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

Regina Henschel rb.henschel at t-online.de
Fri Aug 24 11:06:57 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:
>> 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();

"loadURL" would be called from "Load".

I have looked closer at "loadURL". It does not result in a Draw 
document, but always uses "private:factory/simpress*" and 
DocumentType::Impress. A Draw document can be opened as Impress 
document. But that is not usable for me, because the layer feature is 
one of the differences between Draw and Impress documents.

It seems, I need to extend it to get a Draw document.

BTW, SdModelTestBase has a lot of references to Calc. Copy&Paste left 
over or intentional?

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

I have used CPPUNITTRACE=TRUE now, opened the interesting files and set 
breakpoints before actually starting.

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

You are right, "save" works, beside the wrong factory.

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

No, "save" has "private:factory/simpress*" too.
>
>> 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/");

Already that fails. The "office:" prefix is the problem. It seems, that 
for class SdMiscTest, where I put my test, the part "registerNamespaces" 
is missing.

I am the first one who works on a "Draw" unittest?

Kind regards
Regina


More information about the LibreOffice mailing list