Add xmled test to tests.js.

And fix the tests so that they pass.
This commit is contained in:
Jos van den Oever
2015-06-07 20:25:02 +02:00
parent f8505979ef
commit cc52a758c8
4 changed files with 44 additions and 21 deletions
+1
View File
@@ -8,6 +8,7 @@ FILE( GLOB_RECURSE TESTS_TESTFILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/*/*.xml
${CMAKE_CURRENT_SOURCE_DIR}/*/*.zip
${CMAKE_CURRENT_SOURCE_DIR}/*/*.odt
${CMAKE_CURRENT_SOURCE_DIR}/*/*.xsd
${CMAKE_CURRENT_SOURCE_DIR}/*/*.fodt
)
+18 -15
View File
@@ -320,21 +320,24 @@ core.UnitTestRunner = function UnitTestRunner(resourcePrefix, logger) {
+ "' should be '" + /**@type{!Text}*/(b).data + "'");
return false;
}
runtime.assert(atype === Node.ELEMENT_NODE,
"Only textnodes and elements supported.");
if (a.namespaceURI !== b.namespaceURI) {
testFailed("namespace '" + a.namespaceURI + "' should be '"
+ b.namespaceURI + "'");
return false;
}
if (a.localName !== b.localName) {
testFailed("localName '" + a.localName + "' should be '"
+ b.localName + "'");
return false;
}
if (!areAttributesEqual(/**@type{!Element}*/(a),
/**@type{!Element}*/(b), false)) {
return false;
if (atype === Node.ELEMENT_NODE) {
if (a.namespaceURI !== b.namespaceURI) {
testFailed("namespace '" + a.namespaceURI + "' should be '"
+ b.namespaceURI + "'");
return false;
}
if (a.localName !== b.localName) {
testFailed("localName '" + a.localName + "' should be '"
+ b.localName + "'");
return false;
}
if (!areAttributesEqual(/**@type{!Element}*/(a),
/**@type{!Element}*/(b), false)) {
return false;
}
} else {
runtime.assert(atype === Node.DOCUMENT_FRAGMENT_NODE,
"Only textnodes, elements and document-fragments are supported.");
}
an = a.firstChild;
bn = b.firstChild;
+3 -1
View File
@@ -22,7 +22,7 @@
* @source: https://github.com/kogmbh/WebODF/
*/
/*global runtime, Runtime, core, gui, xmldom, RuntimeTests, odf, ops, webodf_css: true*/
/*global runtime, Runtime, core, gui, xmldom, xmled, RuntimeTests, odf, ops, webodf_css: true*/
runtime.loadClass("core.UnitTester");
runtime.loadClass("core.Base64Tests");
@@ -61,6 +61,7 @@ runtime.loadClass("ops.TransformationTests");
runtime.loadClass("ops.TransformerTests");
runtime.loadClass("xmldom.LSSerializerTests");
runtime.loadClass("xmldom.XPathTests");
runtime.loadClass("xmled.ValidationModelTests");
// The StepsCache verification feature verifies the cache after every modification to ensure it does
@@ -108,6 +109,7 @@ if (runtime.getDOMImplementation() && runtime.parseXML("<a/>").createRange) {
tests.push(ops.OdtDocumentTests);
tests.push(ops.OdtStepsTranslatorTests);
tests.push(ops.TransformerTests);
tests.push(xmled.ValidationModelTests);
}
// add tests depending on browser runtime
if (runtime.type() === "BrowserRuntime") {
+22 -5
View File
@@ -161,16 +161,22 @@ xmled.ValidationModelTests = function ValidationModelTests(runner) {
/**
* @param {!string} xsdfile
* @param {!string} xmlfile
* @return {!function(!function():undefined):undefined} callback
* @return {!core.AsyncTestData}
*/
function testValidation(xsdfile, xmlfile) {
var f = function (callback) {
var model = new xmled.ValidationModel(xsdfile, function (err) {
t.err = err;
r.shouldBeNull(t, "t.err");
if (err) {
return callback();
}
runtime.loadXML(xmlfile, function (err, dom) {
t.err = err;
r.shouldBeNull(t, "t.err");
if (err) {
return callback();
}
var e = firstElementChild(dom || null);
t.documentElement = e;
r.shouldBeNonNull(t, "t.documentElement");
@@ -184,14 +190,22 @@ xmled.ValidationModelTests = function ValidationModelTests(runner) {
});
};
f.functionName = "validation-" + xsdfile + "-" + xmlfile;
return f;
return {f: f, name: xsdfile, expectFail: false};
}
/**
* @param {!string} xsd
* @param {!Array.<!string>} replacementIds
* @return {!core.AsyncTestData}
*/
function testRoot(xsd, replacementIds) {
var f = function (callback) {
var model = new xmled.ValidationModel(xsd, function (e) {
t.err = e;
r.shouldBeNull(t, "t.err");
if (e) {
return callback();
}
t.reps = model.getPossibleReplacements(document.documentElement);
loadReplacements(function () {
checkReplacements(t.reps, replacementIds);
@@ -200,7 +214,7 @@ xmled.ValidationModelTests = function ValidationModelTests(runner) {
});
};
f.functionName = "init-" + xsd;
return f;
return {f: f, name: xsd, expectFail: false};
}
/**
@@ -269,13 +283,16 @@ xmled.ValidationModelTests = function ValidationModelTests(runner) {
* @param {!Array.<!number>} start
* @param {!Array.<!number>} end
* @param {!Array.<!number>} replacementIds
* @return {!function(!function():undefined):undefined} callback
* @return {!core.AsyncTestData}
*/
function testReplace(xsd, initId, start, end, replacementIds) {
var f = function (callback) {
var model = new xmled.ValidationModel(xsd, function (e) {
t.err = e;
r.shouldBeNull(t, "t.err");
if (e) {
return callback();
}
loadReplacements(function () {
var initial = replacements[initId],
range,
@@ -295,7 +312,7 @@ xmled.ValidationModelTests = function ValidationModelTests(runner) {
});
};
f.functionName = "replace-" + xsd + "-" + initId;
return f;
return {f: f, name: xsd, expectFail: false};
}
this.setUp = function () {