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

Tomaž Vajngerl quikee at gmail.com
Thu Aug 23 15:26:30 UTC 2018


Hi Regina,

On Thu, Aug 23, 2018 at 3:26 PM Regina Henschel <rb.henschel at t-online.de> wrote:
>
> Hi all,
>
> I'm still working on https://gerrit.libreoffice.org/#/c/59269/. The
> suggested range-based for-loops work well. Now I try to make a unit test
> as suggested by Tomaž.
>
> I have a test file "tdf101242_without_settings.odg", which has the
> attributes in the <draw:layer> elements in styles.xml and has no
> visible/printable/locked items in settings.xml. I want to load the file,
> then save it, then verify that the attributes are still there in
> styles.xml. After that works, make a test to verify, that the old kind
> items in settings.xml are written correctly.

Sounds promising.

> Is there any example, where I can see how to do that?

Probably not.. usually just look at other tests and do what they do.
The problem is that most of them are for impress and not draw. I have
struggled with some tests in the past too.

> 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();

> Is there a human readable way to see, what I get there?

Not that I know of. You need to hunt down the temporary file and look
at it. You can look at the path of the tempFile -
tempFile.GetURLPath();

> Then I have continued (mimicking what I have seen in other places) with:
> uno::Reference<lang::XComponent > xComponent(xDocShRef->GetModel(),
> uno::UNO_QUERY);
>      uno::Reference<frame::XStorable> xStorable(xComponent, uno::UNO_QUERY);
>      utl::MediaDescriptor aMediaDescriptor;
>      aMediaDescriptor["FilterName"] <<= OUString("draw8");
>      utl::TempFile aTempFile;
>      aTempFile.EnableKillingFile();
>      xStorable->storeToURL(aTempFile.GetURL(),
> aMediaDescriptor.getAsConstPropertyValueList());

This may not be needed - look at my example.

> 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.

> 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/");
....

> Obviously I need help.
>
> Kind regards
> Regina

Best Regards, Tomaž Vajngerl


More information about the LibreOffice mailing list