File indexing completed on 2024-12-22 04:17:08

0001 /*
0002 Test bind_kst
0003 */
0004 
0005 // Can't resetInterpreter because it nukes the script, of course...
0006 //try { Kst.resetInterpreter(); } catch(e) { alert("Error: " + e.name); }
0007 
0008 var errors = 0;
0009 function assertNoReturn(x) {
0010         try {
0011                 eval(x);
0012         } catch (e) {
0013                 alert("Error: " + e.name + "\nLast test was: " + x);
0014                 ++errors;
0015         }
0016 }
0017 
0018 
0019 function assert(x) {
0020         try {
0021                 var xrc = eval(x);
0022                 if (!xrc) {
0023                         alert("Failed: " + x);
0024                         ++errors;
0025                 }
0026         } catch (e) {
0027                 alert("Error: " + e.name + "\nLast test was: " + x);
0028                 ++errors;
0029         }
0030 }
0031 
0032 assertNoReturn("Kst.purge()");
0033 
0034 assert("Kst.vectors.length == 0");
0035 assert("Kst.scalars.length >= 0"); // the built-ins
0036 assert("Kst.strings.length == 0");
0037 assert("Kst.windows.length <= 1");
0038 assert("Kst.dataSources.length == 0");
0039 
0040 var v = new Vector;
0041 v.tagName = "My Vector";
0042 assert("Kst.vectors.length == 1");
0043 assert("var j = Kst.vectors[0]; j.tagName = 'My Vector'");
0044 assert("Kst.vectors[0].tagName = 'My Vector'");
0045 
0046 var sc = Kst.scalars.length;
0047 var s = new Scalar;
0048 s.tagName = "My Scalar";
0049 assert("Kst.scalars.length == " + (sc + 1));
0050 assert("var j = Kst.scalars[0]; j.tagName = 'My Scalar'");
0051 assert("Kst.scalars[" + sc + "].tagName = 'My Scalar'");
0052 
0053 
0054 
0055 if (errors > 0) {
0056         alert("" + errors + " failed testcases.");
0057 } else {
0058         alert("All tests passed.");
0059 }