LCOV - code coverage report
Current view: top level - sw/qa/extras/htmlimport - htmlimport.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 35 35 100.0 %
Date: 2014-11-03 Functions: 21 25 84.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * This file is part of the LibreOffice project.
       3             :  *
       4             :  * This Source Code Form is subject to the terms of the Mozilla Public
       5             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       6             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       7             :  */
       8             : 
       9             : #include <swmodeltestbase.hxx>
      10             : 
      11             : #include <com/sun/star/graphic/XGraphic.hpp>
      12             : #include <com/sun/star/graphic/GraphicType.hpp>
      13             : #include <vcl/GraphicNativeTransform.hxx>
      14             : #include <sfx2/linkmgr.hxx>
      15             : 
      16             : #include <docsh.hxx>
      17             : #include <editsh.hxx>
      18             : #include <ndgrf.hxx>
      19             : 
      20           4 : class HtmlImportTest : public SwModelTestBase
      21             : {
      22             :     public:
      23           4 :         HtmlImportTest() : SwModelTestBase("sw/qa/extras/htmlimport/data/", "HTML (StarWriter)") {}
      24             : };
      25             : 
      26             : #define DECLARE_HTMLIMPORT_TEST(TestName, filename) DECLARE_SW_IMPORT_TEST(TestName, filename, HtmlImportTest)
      27             : 
      28          18 : DECLARE_HTMLIMPORT_TEST(testPictureImport, "picture.html")
      29             : {
      30           2 :     SwXTextDocument* pTxtDoc = dynamic_cast<SwXTextDocument *>(mxComponent.get());
      31           2 :     CPPUNIT_ASSERT(pTxtDoc);
      32             :     // The document contains two pictures stored as a link.
      33           2 :     sfx2::LinkManager& rLinkManager = pTxtDoc->GetDocShell()->GetDoc()->GetEditShell()->GetLinkManager();
      34           2 :     CPPUNIT_ASSERT_EQUAL(size_t(2), rLinkManager.GetLinks().size());
      35           2 :     rLinkManager.Remove(0,2);
      36           2 :     CPPUNIT_ASSERT_EQUAL(size_t(0), rLinkManager.GetLinks().size());
      37             : 
      38             :     // TODO: Get the data into clipboard in html format and paste
      39             : 
      40             :     // But when pasting we don't want images to be linked.
      41           2 :     CPPUNIT_ASSERT_EQUAL(size_t(0), rLinkManager.GetLinks().size());
      42           2 : }
      43             : 
      44          18 : DECLARE_HTMLIMPORT_TEST(testInlinedImage, "inlined_image.html")
      45             : {
      46           2 :     SwXTextDocument* pTxtDoc = dynamic_cast<SwXTextDocument *>(mxComponent.get());
      47           2 :     CPPUNIT_ASSERT(pTxtDoc);
      48             :     // The document contains only one embeded picture inlined in img's src attribute.
      49             : 
      50           2 :     SwDoc* pDoc = pTxtDoc->GetDocShell()->GetDoc();
      51           2 :     SwEditShell* pEditShell = pDoc->GetEditShell();
      52           2 :     CPPUNIT_ASSERT(pEditShell);
      53             : 
      54             :     // This was 1 before 3914a711060341345f15b83656457f90095f32d6
      55           2 :     const sfx2::LinkManager& rLinkManager = pEditShell->GetLinkManager();
      56           2 :     CPPUNIT_ASSERT_EQUAL(size_t(0), rLinkManager.GetLinks().size());
      57             : 
      58           2 :     uno::Reference<drawing::XShape> xShape = getShape(1);
      59           4 :     uno::Reference<container::XNamed> const xNamed(xShape, uno::UNO_QUERY_THROW);
      60           2 :     CPPUNIT_ASSERT_EQUAL(OUString("Image1"), xNamed->getName());
      61             : 
      62             :     uno::Reference<graphic::XGraphic> xGraphic =
      63           4 :         getProperty< uno::Reference<graphic::XGraphic> >(xShape, "Graphic");
      64           2 :     CPPUNIT_ASSERT(xGraphic.is());
      65           2 :     CPPUNIT_ASSERT(xGraphic->getType() != graphic::GraphicType::EMPTY);
      66             : 
      67           4 :     OUString sGraphicURL = getProperty< OUString >(xShape, "GraphicURL");
      68             :     // Before it was "data:image/png;base64,<data>"
      69           2 :     CPPUNIT_ASSERT(sGraphicURL.startsWith("vnd.sun.star.GraphicObject:"));
      70             : 
      71          14 :     for (int n = 0; ; n++)
      72             :     {
      73          14 :         SwNode* pNode = pDoc->GetNodes()[ n ];
      74          14 :         if (SwGrfNode *pGrfNode = pNode->GetGrfNode())
      75             :         {
      76             :             // FIXME? For some reason without the fix in 72703173066a2db5c977d422ace
      77             :             // I was getting GRAPHIC_NONE from SwEditShell::GetGraphicType() when
      78             :             // running LibreOffice but cannot reproduce that in a unit test here. :-(
      79             :             // So, this does not really test anything.
      80           2 :             CPPUNIT_ASSERT(pGrfNode->GetGrfObj().GetType() != GRAPHIC_NONE);
      81           2 :             break;
      82             :         }
      83          14 :     }
      84           2 : }
      85             : 
      86           8 : CPPUNIT_PLUGIN_IMPLEMENT();
      87             : 
      88             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10