[ve] Add CMemory.WriteXmlNodeEndCheckEmpty and WriteXmlAttributesEndSavePos; Add xml line to line test.

This commit is contained in:
Sergey Konovalov
2023-09-06 18:14:37 +03:00
parent d88f613740
commit 9f1875def2
5 changed files with 1329 additions and 7 deletions

View File

@ -1,6 +1,6 @@
CD /D %~dp0
call npm install -g grunt-cli
call npm install
call npm ci
call grunt --level=WHITESPACE_ONLY --addon=sdkjs-forms --addon=sdkjs-ooxml
call grunt develop --addon=sdkjs-forms --addon=sdkjs-ooxml

View File

@ -526,6 +526,9 @@
this.context = null;
this.posAttrEnd = 0;
this.attrQuote = 0x22;//"
if (true !== bIsNoInit)
this.Init();
@ -904,6 +907,11 @@
}
};
this.SetXmlAttributeQuote = function(val)
{
this.attrQuote = val;
}
this.WriteXmlString = function(val)
{
var pCur = 0;
@ -1029,6 +1037,19 @@
this.WriteXmlString(name);
this.WriteUtf8Char(0x3e);
};
this.WriteXmlNodeEndCheckEmpty = function(name)
{
if (this.posAttrEnd === this.GetCurPosition()) {
this.Seek(this.posAttrEnd - 1);
this.WriteUtf8Char(0x2f);
this.WriteUtf8Char(0x3e);
} else {
this.WriteUtf8Char(0x3c);
this.WriteUtf8Char(0x2f);
this.WriteXmlString(name);
this.WriteUtf8Char(0x3e);
}
};
this.WriteXmlNodeWithText = function(name, text)
{
this.WriteXmlNodeStart(name);
@ -1043,23 +1064,28 @@
this.WriteUtf8Char(0x2f);
this.WriteUtf8Char(0x3e);
};
this.WriteXmlAttributesEndSavePos = function()
{
this.WriteUtf8Char(0x3e);
this.posAttrEnd = this.GetCurPosition();
};
this.WriteXmlAttributeString = function(name, val)
{
this.WriteUtf8Char(0x20);
this.WriteXmlString(name);
this.WriteUtf8Char(0x3d);
this.WriteUtf8Char(0x22);
this.WriteUtf8Char(this.attrQuote);
this.WriteXmlString(val.toString());
this.WriteUtf8Char(0x22);
this.WriteUtf8Char(this.attrQuote);
};
this.WriteXmlAttributeStringEncode = function(name, val)
{
this.WriteUtf8Char(0x20);
this.WriteXmlString(name);
this.WriteUtf8Char(0x3d);
this.WriteUtf8Char(0x22);
this.WriteUtf8Char(this.attrQuote);
this.WriteXmlStringEncode(val.toString());
this.WriteUtf8Char(0x22);
this.WriteUtf8Char(this.attrQuote);
};
this.WriteXmlAttributeBool = function(name, val)
{

View File

@ -146,6 +146,7 @@
// TODO mb rewrite consider 'CVisioDocument' contains parts(.xml files) only but not XML
CVisioDocument.prototype.toZip = function(zip, context) {
let memory = new AscCommon.CMemory();
memory.SetXmlAttributeQuote(0x27);
memory.context = context;
context.document = this;

File diff suppressed because one or more lines are too long

View File

@ -33,15 +33,19 @@
//for zlib async loading
QUnit.config.autostart = false;
$(function() {
var api = new Asc.asc_docs_api({
const api = new Asc.asc_docs_api({
'id-view': 'editor_sdk'
});
AscCommon.g_oTableId.init()
AscCommon.g_oTableId.init();
let memory = new AscCommon.CMemory();
memory.SetXmlAttributeQuote(0x27);
//todo events
setTimeout(startTests, 3000);
function startTests() {
api.InitEditor();
QUnit.start();
QUnit.module("Test draw serialize")
@ -102,6 +106,22 @@ $(function() {
});
});
QUnit.test("Compare document.xml", function (assert)
{
let document = new AscCommonDraw.CVisioDocument(api);
testXml(assert, document, Asc.documentXml);
});
QUnit.test("Compare document.xml generated", function (assert)
{
let document = new AscCommonDraw.CVisioDocument(api);
testXml(assert, document, Asc.documentXmlGenerated);
});
QUnit.test("Compare masters.xml", function (assert)
{
let masters = new AscCommonDraw.CMasters_Type(api);
testXml(assert, masters, Asc.mastersXml,);
});
QUnit.module("Comparing files");
testFile.skip = function testFileSkip(fileName, base64, ignoreFolders, ignoreFiles, ignoredTags, ignoredAttributes, downloadFile) {
@ -260,6 +280,31 @@ $(function() {
}
}
function testXml(assert, serializeObj, expecteedXml) {
//fromXml
let context = new AscCommon.XmlParserContext();
let zip = new AscCommon.ZLib();
let rels = new AscCommon.openXml.OpenXmlPackage(zip, null);
let reader = new StaxParser(expecteedXml, rels, context);
serializeObj.fromXml(reader);
//toXml
memory.Seek(0);
memory.context = new AscCommon.XmlWriterContext();
memory.context.clearCurrentPartDataMaps();
context.document = serializeObj;
let filePart = new AscCommon.openXml.OpenXmlPackage(zip, memory);
let data = filePart.getXmlBytes(this, serializeObj, memory);
let content = AscCommon.UTF8ArrayToString(data, 0, data.length);
//compare
let expectedContent = expecteedXml.replace(/\t/g,'');
let resultContent = content;
//todo flag in memeory?
resultContent = resultContent.replace(/"/g,'"');
assert.strictEqual(resultContent, expectedContent, "Compare xml");
}
function getCompareResultIgnoredTagsExistance(compareResult, ignoredTags) {
return compareResult.map(function (compareObject) {
let newMissingElements = compareObject.missingElements.filter(function (missingElement) {