How to make a unit test for Draw to test file format?

Regina Henschel rb.henschel at t-online.de
Sun Aug 26 13:33:29 UTC 2018


Hi Tomaž,

Tomaž Vajngerl schrieb am 23-Aug-18 um 17:26:
> Hi Regina,
>
> On Thu, Aug 23, 2018 at 3:26 PM Regina Henschel <rb.henschel at t-online.de> wrote:
[..]
>
>> I have tried a start like
>> void SdMiscTest::testTdf101242_ODF2ODF()
>> {
>>      ::sd::DrawDocShellRef xDocShRef =
>> Load(m_directories.getURLFromSrc("/sd/qa/unit/data/tdf101242_without_settings.odg"),
>> ODG);
>
> I would do it like it is done in test SdExportTest::testTdf113822 in
> export-tests.cxx and SdExportTest::testEmbeddedText().
>
>     utl::TempFile tempFile;
>     sd::DrawDocShellRef xShell =
> loadURL(m_directories.getURLFromSrc("/sd/qa/unit/data/tdf101242_without_settings.odg"),
> ODG);
>     xShell = saveAndReload(xShell.get(), ODG, &tempFile);
>     xmlDocPtr pXmlDoc = parseExport(tempFile, "styles.xml");
>     assert with xpath ...
>     xDocShRef->DoClose();
>
>> I see a temp file in C:\cygwin64\tmp\. But it has mimetype
>> application/vnd.oasis.opendocument.presentation and the attributes in
>> the <draw:layer> elements are wrong.
>
> That's weird - I hope it works with my example.

It turns out, that loadURL is not enough. Using 'Load' works now, I 
guess because it generates a Frame, which is needed for layers.

I have changed SdModelTestBase to use "private:factory/sdraw*" for odg 
documents and that gives now the correct mimetype.

The resaved file is now the same as I get from a running LO with UI.

>
>> My idea was to use something like
>> xmlDocPtr pXmlDoc = parseExport(aTempFile, "styles.xml");
>> OString
>> sPathStart("/office:document-styles/office:master-styles/draw:layer-set/draw:layer");
>>      assertXPath(pXmlDoc, sPathStart +
>> "[@draw:name='backgroundobjects']", "draw:protected", "true" );
>> I get something in pXmlDoc. How can I see, what I have got? I cannot get
>> nodes from it, e.g
>> getXPathNode(pXmlDoc,OString("/office:document-styles")) or
>> getXPathNode(pXmlDoc,"/office:document-styles") is already empty.
>
> I solve this by constructing the path step by step, until it is what I want.
> For example:
>
> first try:
> assertPath("/office:document-styles/");
>
> second try I would add : master-styles:
> assertPath("/office:document-styles/office:master-styles/");
>
> third try I would add layer-set:
> assertPath("/office:document-styles/office:master-styles/draw:layer-set/");

I have found the reason of my problem. assertXPath evaluates the 
attribute in the second parameter by calling method xmlGetProp. But that 
cannot handle attributes with prefix. So my solution is now to put the 
test into the predicate, e.g.
assertXPath(pXmlDoc, sPathStart + "[@draw:name='backgroundobjects' and 
@draw:protected='true']");

It works basically now.

Kind regards
Regina


More information about the LibreOffice mailing list