Improving transformiix test harness. Adding better error reporting, range selection, support for loading text-only reference files, ignore namespace attributes, cleanup code. Code by Pike, sicking and me. r=Pike. Not part of the build.

This commit is contained in:
peterv%netscape.com 2001-09-21 12:23:25 +00:00
Родитель 86961a499f
Коммит 1c3aa047fe
4 изменённых файлов: 156 добавлений и 53 удалений

Просмотреть файл

@ -30,40 +30,81 @@ function DiffDOM(node1,node2)
}
// namespace attributes in the second node are ignored
const nsreg = /^xmlns[|:\w]/;
// This function does the work of DiffDOM by recursively calling
// itself to explore the tree
function DiffNodeAndChildren(node1, node2)
{
if (!node1 && !node2) return true;
if (!node1 || !node2) return false;
if (node1.type!=node2.type){
return false;
}
var attributes = node1.attributes;
if ( attributes && attributes.length ) {
if (!node2.attributes || node2.attributes.length!=attributes.length)
return false;
var item, name, value;
for ( var index = 0; index < attributes.length; index++ ) {
if (!node1 && !node2)
return true;
if (!node1 || !node2)
return ErrorUp("One of the nodes is null", node1, node2);
if (node1.type!=node2.type)
return ErrorUp("Different node types", node1, node2);
var attributes = node2.attributes;
if (attributes && attributes.length) {
var item, name, ns, value, otherValue;
for (var index = 0; index < attributes.length; index++) {
item = attributes.item(index);
name = item.nodeName;
ns = item.namespaceURI;
if (ns=="") {
name = item.nodeName;
otherValue = node2.getAttribute(name);
}
else {
name = item.localName;
otherValue = node2.getAttributeNS(ns, name);
}
value = item.nodeValue;
if (node2.getAttribute(name)!=value){
if (!nsreg.test(name) && otherValue!=value) {
return ErrorUp("Different values for attribute", node1, node2);
}
}
}
else if (node1.attributes && node1.attributes.length) {
return ErrorUp("Different number of attributes", node1, node2);
}
if (node1.nodeName!=node2.nodeName)
return ErrorUp("Different node names", node1, node2);
if (node1.nodeValue!=node2.nodeValue)
return ErrorUp("Different node values", node1, node2);
if (node1.namespaceURI!=node2.namespaceURI)
return ErrorUp("Different namespace", node1, node2);
if (node1.hasChildNodes() != node2.hasChildNodes())
return ErrorUp("Different children", node1, node2);
if (node1.childNodes) {
if (node1.childNodes.length != node2.childNodes.length)
return ErrorUp("Different number of children", node1, node2);
for (var child = 0; child < node1.childNodes.length; child++) {
if (!DiffNodeAndChildren(node1.childNodes[child],
node2.childNodes[child])) {
return false;
}
}
}
if (node1.nodeName!=node2.nodeName) return false;
if (node1.nodeValue!=node2.nodeValue) return false;
if (node1.hasChildNodes() != node2.hasChildNodes()) return false;
if ( node1.childNodes ) {
if (node1.childNodes.length != node2.childNodes.length) return false;
for ( var child = 0; child < node1.childNodes.length; child++ )
if (!DiffNodeAndChildren(node1.childNodes[child], node2.childNodes[child])) {
return false;
}
}
return true;
}
function ErrorUp(errMsg, node1, node2)
{
dump("Error: "+errMsg+"\n");
if (node1) {
dump("Node 1: "+node1+", ");
if (node1.nodeType == Node.TEXT_NODE)
dump("nodeValue: "+node1.nodeValue+"\n");
else
dump("nodeName: "+node1.nodeName+"\n");
}
if (node2) {
dump("Node 2: "+node2+", ");
if (node2.nodeType == Node.TEXT_NODE)
dump("nodeValue: "+node2.nodeValue+"\n");
else
dump("nodeName: "+node2.nodeName+"\n");
}
return false;
}

Просмотреть файл

@ -58,11 +58,18 @@
</menupopup>
</menulist>
</groupbox>
<groupbox orient="horizontal"><caption label="select" />
<button label="Select from " oncommand="selectRange()"/>
<textbox style="width: 10em;" id="start-field" persist="value" />
<text value=" to " />
<textbox style="width: 10em;" id="end-field" persist="value" />
</groupbox>
<spacer flex="1" /></hbox>
<hbox><groupbox orient="horizontal"><caption label="stats" />
<text value="tests run: "/><text id="tests_run" value="0" />
<text value=" tests passed: "/><text id="tests_passed" value="0"/>
<text value=" tests failed: "/><text id="tests_failed" value="0"/>
<text value=" tests selected: "/><text id="tests_selected" value="0"/>
</groupbox>
<spacer flex="1" /></hbox>
@ -70,7 +77,7 @@
<outlinercol id="name" label="Name" flex="1"/>
<outlinercol id="purp" label="Purpose" flex="2"/>
<outlinercol id="comm" label="Comment" flex="1"/>
<outlinerbody flex="1" onselect="dump('selection changed!\n')"/>
<outlinerbody flex="1" onselect="sel_change()"/>
</outliner>
</window>

Просмотреть файл

@ -20,7 +20,7 @@
* Axel Hecht <axel@pike.org> (Original Author)
*/
var name_array,index_array,__docSet;
var name_array,index_array;
function do_transforms(new_name_array,new_number_array,verbose){
if (new_name_array) {
@ -31,8 +31,7 @@ function do_transforms(new_name_array,new_number_array,verbose){
dump("==============================\n");
}
if (name_array.length){
current=name_array.shift();
__docSet=new txDocSet(current,index_array.shift());
new txDocSet(name_array.shift(),index_array.shift());
}
}
@ -43,17 +42,17 @@ function txDocSet(name,index,verbose){
if (verbose) this.mVerbose=verbose;
this.mSource = document.implementation.createDocument("","",null);
this.mStyle = document.implementation.createDocument("","",null);
this.mReference = document.implementation.createDocument("","",null);
this.mResult = document.implementation.createDocument("","",null);
this.mSource.addEventListener("load",this.docLoaded,false);
this.mStyle.addEventListener("load",this.styleLoaded,false);
this.mReference.addEventListener("load",this.refLoaded,false);
this.mSource.addEventListener("load",this.loaded(1),false);
this.mStyle.addEventListener("load",this.loaded(2),false);
this.mSource.load(this.mBase+"conf/"+name+".xml");
this.mStyle.load(this.mBase+"conf/"+name+".xsl");
this.mIsError = name.match(/\/err\//);
if (this.mIsError){
this.mLoaded = 2;
this.stuffLoaded(4);
} else {
this.mReference = document.implementation.createDocument("","",null);
this.mReference.addEventListener("load",this.loaded(4),false);
this.mReference.load(this.mBase+"conf-gold/"+name+".out");
}
}
@ -70,17 +69,27 @@ txDocSet.prototype = {
mLoaded : 0,
mIndex : 0,
styleLoaded : function(e){
__docSet.stuffLoaded(1);
loaded : function(i) {
var self = this;
return function(e) { return self.stuffLoaded(i); };
},
docLoaded : function(e){
__docSet.stuffLoaded(4);
},
refLoaded : function(e){
__docSet.stuffLoaded(2);
},
stuffLoaded : function(mask){
__docSet.mLoaded+=mask;
stuffLoaded : function(mask) {
if (mask==4 && this.mReference) {
var docElement=this.mReference.documentElement;
if (docElement && docElement.nodeName=="parsererror") {
try {
var text=loadFile(docElement.baseURI);
this.mReference.removeChild(docElement);
var wrapper=this.mReference.createElement("transformiix:result");
var textNode=this.mReference.createTextNode(text);
wrapper.appendChild(textNode);
this.mReference.appendChild(wrapper);
}
catch (e) {
}
}
}
this.mLoaded+=mask;
if (this.mLoaded==7){
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
var txProc = new XSLTProcessor(),isGood=false;
@ -91,6 +100,7 @@ txDocSet.prototype = {
DumpDOM(this.mResult);
handle_result(this.mIndex,true);
} else {
this.mReference.normalize();
try{
isGood = DiffDOM(this.mResult.documentElement,this.mReference.documentElement);
} catch (e) {isGood = false;};
@ -113,3 +123,24 @@ txDocSet.prototype = {
}
}
};
const IOSERVICE_CTRID = "@mozilla.org/network/io-service;1";
const nsIIOService = Components.interfaces.nsIIOService;
const SIS_CTRID = "@mozilla.org/scriptableinputstream;1"
const nsIScriptableInputStream = Components.interfaces.nsIScriptableInputStream;
function loadFile(url)
{
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
var serv = Components.classes[IOSERVICE_CTRID].getService(nsIIOService);
if (!serv)
throw Components.results.ERR_FAILURE;
var chan = serv.newChannel(url, null);
var instream =
Components.classes[SIS_CTRID].createInstance(nsIScriptableInputStream);
instream.init(chan.open());
return instream.read(instream.available());
}

Просмотреть файл

@ -23,8 +23,8 @@
var pop_last=0, pop_chunk=25;
var isinited=false;
var xalan_base, xalan_xml, xalan_elems, xalan_length, content_row, target;
var matchRE, matchNameTag, matchFieldTag;
var tests_run, tests_passed, tests_failed;
var matchRE, matchNameTag, matchFieldTag, startFieldTag, endFieldTag;
var tests_run, tests_passed, tests_failed, tests_selected;
var view = ({
// nsIOutlinerView
rowCount : 0,
@ -83,6 +83,7 @@ var view = ({
this.selection.toggleSelect(index);
},
swallow : function(initial) {
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
var startt = new Date();
this.rowCount = initial.length;
this.success = new Array(this.rowCount);
@ -102,7 +103,6 @@ var view = ({
}
cur = cur.nextSibling;
}
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
this.outliner.rowCountChanged(0,this.rowCount);
//dump((new Date()-startt)/1000+" secs in swallow for "+k+" items\n");
},
@ -119,8 +119,8 @@ var view = ({
getNames : function(first,last){
last = Math.min(this.rowCount,last);
first = Math.max(0,first);
list = new Array(last-first+1);
for (k=first;k<=last;k++)
var list = new Array(last-first+1);
for (var k=first;k<=last;k++)
list[k-first] = this.names[k];
return list;
}
@ -138,9 +138,12 @@ function loaderstuff(eve) {
view.sad = atomservice.getAtom("fail");
matchNameTag = document.getElementById("search-name");
matchFieldTag = document.getElementById("search-field");
startFieldTag = document.getElementById("start-field");
endFieldTag = document.getElementById("end-field");
tests_run = document.getElementById("tests_run");
tests_passed = document.getElementById("tests_passed");
tests_failed = document.getElementById("tests_failed");
tests_selected = document.getElementById("tests_selected");
xalan_base = document.getElementById("xalan_base");
setView(document.getElementById('out'), view)
xalan_xml = document.implementation.createDocument("","",null);
@ -173,7 +176,7 @@ function dump_checked(){
for (k=0;k<sels.getRangeCount();k++){
sels.getRangeAt(k,a,b);
todo = todo.concat(view.getNames(a.value,b.value));
for (l=a.value;l<=b.value;l++) nums.push(l);
for (var l=a.value;l<=b.value;l++) nums.push(l);
}
do_transforms(todo,nums);
}
@ -217,7 +220,7 @@ function select(){
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
var searchField = matchFieldTag.getAttribute("value");
var matchRE = new RegExp(matchNameTag.value);
for (k=0;k<view.rowCount;k++){
for (var k=0;k<view.rowCount;k++){
switch (searchField) {
case "1":
if (view.names[k] && view.names[k].match(matchRE))
@ -236,10 +239,26 @@ function select(){
}
}
function selectRange(){
var start = startFieldTag.value-1;
var end = endFieldTag.value-1;
if (start > end) {
// hihihi
var tempStart = start;
start = end;
end = startTemp;
}
start = Math.max(0, start);
end = Math.min(end, view.rowCount-1);
view.selection.rangedSelect(start,end,true);
}
function check(yes){
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
if (yes) view.selection.selectAll();
else view.selection.clearSelection();
if (yes)
view.selection.selectAll();
else
view.selection.clearSelection();
}
function invert_check(){
@ -276,3 +295,8 @@ function reset_stats(){
tests_passed.setAttribute("value", "0");
tests_failed.setAttribute("value", "0");
}
function sel_change() {
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
tests_selected.setAttribute("value", view.selection.count);
}