You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xap-commits@incubator.apache.org by jm...@apache.org on 2006/08/21 17:52:02 UTC
svn commit: r433308 -
/incubator/xap/trunk/testsrc/xap/mco/_TestDeclarativeArgumentParser.js
Author: jmargaris
Date: Mon Aug 21 10:52:01 2006
New Revision: 433308
URL: http://svn.apache.org/viewvc?rev=433308&view=rev
Log:
Updated tests from Trevor Oldak
Modified:
incubator/xap/trunk/testsrc/xap/mco/_TestDeclarativeArgumentParser.js
Modified: incubator/xap/trunk/testsrc/xap/mco/_TestDeclarativeArgumentParser.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/testsrc/xap/mco/_TestDeclarativeArgumentParser.js?rev=433308&r1=433307&r2=433308&view=diff
==============================================================================
--- incubator/xap/trunk/testsrc/xap/mco/_TestDeclarativeArgumentParser.js (original)
+++ incubator/xap/trunk/testsrc/xap/mco/_TestDeclarativeArgumentParser.js Mon Aug 21 10:52:01 2006
@@ -16,8 +16,7 @@
*/
-Xap.require("xap.session.ClientSession");
-
+
function SimpleMco() {
}
@@ -33,6 +32,11 @@
return i + j;
}
+SimpleMco.prototype.sum3 = function(i,j,k) {
+ return i + j + k;
+}
+
+
SimpleMco.prototype.getString = function(s) {
return s;
}
@@ -40,9 +44,18 @@
function exposeTestFunctionNames(){
- return ["testParser"];
+ return ["testParser", "testContainer"];
}
+Xap.require("xap.session.ClientSession");
+Xap.require("xap.session.DeclarativeArgumentParser");
+Xap.require("xap.xml.DocumentContainer");
+Xap.require("xap.util.Hashtable");
+Xap.require("xap.session.EventHandler");
+Xap.require("xap.session.Container");
+Xap.require("xap.xml.dom.Document");
+
+
function testParser() {
/* var session = new xap.session.ClientSession('', '', document.body); */
@@ -96,7 +109,237 @@
test = eventHandler._handleObjectEvent('mco:simple.getString(this.text)', buttonElement);
assertTrue("THIS Test", test == 'my button text');
+
+ test = eventHandler._handleObjectEvent('mco:simple.sum(10,mco:simple.sum(12,13) )', buttonElement);
+ assertTrue("Sum Test", test == 35);
+
+}
+
+function testContainer() {
+ var session = {
+ getMcoContainer: function() {return this._mcoContainer},
+ getEventHandler: function() {return this._eventHandler},
+ getDeclarativeArgumentParser: function() {return this._declarativeArgumentParser},
+ addContainer: function(name, container) {this._namesToContainers.put(name, container)},
+ getContainer: function(name) {return this._namesToContainers.get(name)},
+ getDocumentContainer: function() {return this._documentContainer},
+ initialize: function() {
+ this._declarativeArgumentParser = new xap.session.DeclarativeArgumentParser(this);
+ this._documentContainer = new xap.xml.DocumentContainer(this);
+ this._namesToContainers = new xap.util.Hashtable(this);
+ this._eventHandler = new xap.session.EventHandler(this);
+ this._mcoContainer = new xap.session.Container(this);
+ this.addContainer('mco', this._mcoContainer);
+ }
+ };
+
+ session.initialize();
+
+ var mcoContainer = session.getMcoContainer();
+ mcoContainer.put('simple', new SimpleMco());
+
+ var simple2 = new SimpleMco();
+ mcoContainer.put('simple2', simple2 );
+
+ /*var buttonElement = document.createElement('button');
+ buttonElement.setAttribute('text', 'button text');*/
+
+ var doc = new xap.xml.dom.Document(null);
+ var buttonElement = doc.createElement('button');
+ buttonElement.setAttribute('text', 'my button text');
+ buttonElement.bonk = function(j){ return j};
+ buttonElement.setAttribute('width', '50%');
+
+
+ var eventHandler = session.getEventHandler();
+
+ assertNotNull('NOT NULL => EVENTHANDLER', eventHandler);
+ assertNotNull("HAS EVENT", eventHandler._handleObjectEvent);
+ var test;
+
+
+ //Initial test by James Margaris.
+ //Tests to make sure the object passed to a function stays exactly the same
+ test = eventHandler._handleObjectEvent('mco:simple.getString( mco:simple2 )', buttonElement);
+ assertTrue("basic: expected simple2 as return value, got back" + test, test == simple2);
+
+ //Various test cases by Trevor Oldak 08/17/2006
+ //Commented out ones returned errors or behaved incorrectly
+ //Tests with inccorect behavior are in their own section at the bottom.
+
+ // Missing/Mal-formed arguments
+ //A two-argument function called with one argument. JavaScript sets the second argument to 'undefined'. This should too
+ test = eventHandler._handleObjectEvent('mco:simple.getString(mco:simple.sum("3"))', buttonElement);
+ assertTrue("emptyarg1: expected 3undefined as return value, got back " + test, test == "3undefined");
+ //Same thing, without calling getString
+ test = eventHandler._handleObjectEvent('mco:simple.sum("3"))', buttonElement);
+ assertTrue("emptyarg2: expected 3undefined as return value, got back " + test, test == "3undefined");
+ //Same thing, with ' instead of "
+ test = eventHandler._handleObjectEvent("mco:simple.getString(mco:simple.sum('3'))", buttonElement);
+ assertTrue('emptyarg3: expected 3undefined as return value, got back ' + test, test == '3undefined');
+ //Empty function call, returns 'NaN' in javascript, should do same here:
+ test = eventHandler._handleObjectEvent("mco:simple.getString(mco:simple.sum())", buttonElement);
+ assertTrue('emptyarg4: expected NaN as return value, got back ' + test, isNaN(test));
+ //Same thing, with empty strings. Should return NaN.
+ test = eventHandler._handleObjectEvent("mco:simple.getString(mco:simple.sum(\"\"))", buttonElement);
+ assertTrue('emptyarg5: expected NaN as return value, got back ' + test, isNaN(test));
+
+
+
+
+ //Various potential bugs related to passing strings to functions
+ //Two strings of integers should be treated as strings, instead of integers
+ test = eventHandler._handleObjectEvent('mco:simple.getString( mco:simple.sum( "3" , "5" ) )', buttonElement);
+ assertTrue("stringarg1: expected 35 as return value, got back " + test, test == "35");
+ //Same thing, sans getString
+ test = eventHandler._handleObjectEvent(' mco:simple.sum( "3" , "5" ) ', buttonElement);
+ assertTrue("stringarg2: expected 35 as return value, got back " + test, test == "35");
+ //Same test, but with boolean strings instead of integers.
+ test = eventHandler._handleObjectEvent("mco:simple.sum3('true','false','true')", buttonElement);
+ assertTrue('stringarg3: expected "truefalsetrue" as return value, got back ' + test, test == 'truefalsetrue');
+ //Same test with single quotes.
+ test = eventHandler._handleObjectEvent("mco:simple.getString( mco:simple.sum( '3' , '5' ) )", buttonElement);
+ assertTrue('stringarg4: expected 35 as return value, got back ' + test, test == '35');
+ //Now, testing to see that integers are treated as such when passed to the MCO
+ test = eventHandler._handleObjectEvent("mco:simple.getString( mco:simple.sum( 3 , 5 ) )", buttonElement);
+ assertTrue('stringarg5: expected 8 as return value, got back ' + test, test == '8');
+ /* This is handled correctly. Tests to make sure that arguments are properly quoted
+ test = eventHandler._handleObjectEvent("mco:simple.getString( mco:simple.sum( 3' , '5 ) )", buttonElement);
+ assertTrue('stringarg6: expected error as return value, got back ' + test, test == '');
+ */
+ /* Same test with escaped double quotes. Correct behavior
+ test = eventHandler._handleObjectEvent(" mco:simple.sum( 3\" , \"5 ) ", buttonElement);
+ assertTrue("stringarg7: expected error as return value, got back " + test, test == "");
+ */
+ //Comma won't split a string into two arguments.
+ test = eventHandler._handleObjectEvent("mco:simple.getString( mco:simple.sum( '3 , 5' ) )", buttonElement);
+ assertTrue('stringarg8: expected "3 , 5undefined" as return value, got back ' + test, test == "3 , 5undefined");
+ //Escaped quotes around an argument should make the argument be treated as a string.
+ test = eventHandler._handleObjectEvent(" mco:simple.sum( \"3\" , \"5\" ) ", buttonElement);
+ assertTrue("stringarg9: expected 35 as return value, got back " + test, test == "35");
+ /* Mismatched quotes should cause an error - Handled correctly
+ test = eventHandler._handleObjectEvent(" mco:simple.sum(\"3 , 5') ", buttonElement);
+ assertTrue("stringarg10: expected error as return value, got back " + test, test == "");
+ */
+ // These next two tests make sure that preceding spaces aren't ignored in strings.
+ test = eventHandler._handleObjectEvent(" mco:simple.sum( \'3 \' , \"5 \") ", buttonElement);
+ assertTrue("stringarg11: expected '3 5 ' as return value, got back " + test, test == "3 5 ");
+ test = eventHandler._handleObjectEvent(" mco:simple.sum( \' 3\' , \" 5\") ", buttonElement);
+ assertTrue("stringarg12: expected ' 3 5' as return value, got back " + test, test == " 3 5");
+ /* Test to ensure that double-quotes nested within eachother don't work. Handled correctly
+ test = eventHandler._handleObjectEvent(" mco:simple.getString(\"mco:simple.getString(\"test\")\") ", buttonElement);
+ assertTrue("stringarg13: expected error as return value, got back " + test, test == "");
+ /* works correctly - should throw an error because quotes are nested with ("('("")')")
+ test = eventHandler._handleObjectEvent(" mco:simple.getString(\"mco:simple.getString(\'mco:simple.getString(\"test\")\')\") ", buttonElement);
+ assertTrue("stringarg14: expected error as return value, got back " + test, test == "");
+ */
+ /* works correctly - shouldn't recognize arguments meant to be passed by value but not expressed as a string.
+ test = eventHandler._handleObjectEvent(" mco:simple.getString(test) ", buttonElement);
+ assertTrue("stringarg14: expected error as return value, got back " + test, test == "");
+ */
+
+
+
+
+ // Tests to make sure that spaces everywhere are OK.
+ test = eventHandler._handleObjectEvent('mco:simple.getString( mco:simple.sum( 3 , 5 ) )', buttonElement);
+ assertTrue("spaces1: expected 8 as return value, got back " + test, test == "8");
+ test = eventHandler._handleObjectEvent(' mco:simple.sum( 3 , 5 ) ', buttonElement);
+ assertTrue("spaces2: expected 8 as return value, got back " + test, test == "8");
+
+
+
+
+ //Test ot see that nesting functions doesn't cause a problem
+ test = eventHandler._handleObjectEvent('mco:simple.getString(mco:simple.getString(mco:simple.getString(mco:simple.getString(mco:simple.getString(mco:simple.getString(mco:simple.getString(mco:simple.getString(mco:simple.getString(mco:simple.getString(mco:simple.getString(mco:simple.getString(mco:simple.getString(mco:simple.getString(mco:simple.getString("bork")))))))))))))))', buttonElement);
+ assertTrue("nesting 1: expected 'bork' as return value, got back " + test, test == "bork");
+ //Same test, with multiple arguments in a function.
+ test = eventHandler._handleObjectEvent("mco:simple.getString( mco:simple.sum( mco:simple.sum( mco:simple.sum( mco:simple.sum( 3 , 5 ) , mco:simple.sum( 3 , 5 ) ) , mco:simple.sum( mco:simple.sum( 3 , 5 ) , mco:simple.sum( 3 , 5 ) ) ) , mco:simple.sum( mco:simple.sum( mco:simple.sum( 3 , 5 ) , mco:simple.sum( 3 , 5 ) ) , mco:simple.sum( mco:simple.sum( 3 , 5 ) , mco:simple.sum( 3 , 5 ) ) ) ) )", buttonElement);
+ assertTrue('nesting 2: expected 64 as return value, got back ' + test, test == '64');
+
+
+
+
+ //Make sure that element properties are accessible.
+ test = eventHandler._handleObjectEvent("mco:simple.getString(this.text)", buttonElement);
+ assertTrue('this1: expected "my button text" as return value, got back ' + test, test == 'my button text');
+ //Make sure that the element is passed exactly as it is.
+ test = eventHandler._handleObjectEvent("mco:simple.getString(this)", buttonElement);
+ assertTrue('this2: expected "my button text" as return value, got back ' + test, test == buttonElement);
+ //Test to see that two elements can be passed at onc
+ test = eventHandler._handleObjectEvent("mco:simple.sum(this,this)", buttonElement);
+ assertTrue('this3: expected "[object Object][object Object]" as return value, got back ' + test, test == '[object Object][object Object]');
+ //Same test with 3.
+ test = eventHandler._handleObjectEvent("mco:simple.sum3(this,this,this)", buttonElement);
+ assertTrue('this4: expected "[object Object][object Object][object Object]" as return value, got back ' + test, test == '[object Object][object Object][object Object]');
+ //Test passing an object, property, and value.
+ test = eventHandler._handleObjectEvent("mco:simple.sum3(this,this.text,3)", buttonElement);
+ assertTrue('this5: expected "[object Object]my button text3" as return value, got back ' + test, test == '[object Object]my button text3');
+ //Test passing multiple element properties.
+ test = eventHandler._handleObjectEvent("mco:simple.sum(this.width,this.text)", buttonElement);
+ assertTrue('this6: expected "50%my button text" as return value, got back ' + test, test == '50%my button text');
+
+
+
+
+ //Make sure that boolean values are correctly passed.
+ test = eventHandler._handleObjectEvent("mco:simple.sum3(true,this.text,3)", buttonElement);
+ assertTrue('true1: expected "truemy button text3" as return value, got back ' + test, test == 'truemy button text3');
+ //This test makes sure that booleans are passed by value instead of as strings. True = 1 and False = 0 in javascript.
+ test = eventHandler._handleObjectEvent("mco:simple.sum3(true,false,true)", buttonElement);
+ assertTrue('true2: expected "2" as return value, got back ' + test, test == '2');
+
+
+
+
+ //Escape characters, when properly escaped, should be correctly passed as strings
+ test = eventHandler._handleObjectEvent('mco:simple.getString("\\")', buttonElement);
+ assertTrue("escape chars: expected \"\\\" as return value, got back " + test, test == "\\");
+ test = eventHandler._handleObjectEvent("mco:simple.getString('\\')", buttonElement);
+ assertTrue("escape chars: expected \"\\\" as return value, got back " + test, test == "\\");
+
+
+
+
+
+ //////////////// FAILED TESTS ////////////
+ /* ERROR: Null not allowed as argument
+ test = eventHandler._handleObjectEvent("mco:simple.getString(null)", buttonElement);
+ assertTrue('null1: expected "null" as return value, got back ' + test, test == null);
+ */
+ /* ERROR: Extra closing parentheses don't cause problems
+ test = eventHandler._handleObjectEvent("mco:simple.getString( mco:simple.sum( 3 , 5 ) ))", buttonElement);
+ assertTrue('Parentheses1: expected error as return value, got back ' + test, test == '');
+ */
+ /* ERROR: Extra parentheses (though unecessary) surrounding arguments shouldn't cause problems. Throws a 'missing colon' error
+ test = eventHandler._handleObjectEvent("mco:simple.getString( mco:simple.sum( (3) , 5 ) )", buttonElement);
+ assertTrue('Parentheses2: expected 8 as return value, got back ' + test, test == '8');
+ */
+ /* ERROR: missing values probably should throw an error, even if the function doesn't need them:
+ test = eventHandler._handleObjectEvent("mco:simple.getString( mco:simple.sum( 3 , 5 , ) )", buttonElement);
+ assertTrue('Extraargs2 error as return value, got back ' + test, test == '');
+ */
+
+
+ // Other Tests of Note:
+ //Test to see if element functions are callable. At the moment, they aren't.
+ /* test = eventHandler._handleObjectEvent("mco:simple.getString(this.bonk(3))", buttonElement);
+ assertTrue('this7: expected "3" as return value, got back ' + test, test == '3');
+ */
+ //Potentially an error: Extra value passed to function. It is ignored.-----------------v
+ /*test = eventHandler._handleObjectEvent("mco:simple.getString( mco:simple.sum( 3 , 5, 6 ) )", buttonElement);
+ assertTrue('Extraargs1: expected error as return value, got back ' + test, test == ''); */
+
+
+
+
+ //Parsing bugs in the javascript would abort the execution of the file and show no errors, so enabling an alert such as this
+ //at the end will indicated to the tester that the whole function ran.
+ //Change the number regularly; It will indicate that your browser isn't using cached tests.
+ //alert('Test Successful 10');
+
+
}