LCOV - code coverage report
Current view: top level - sw/qa/extras/htmlimport - htmlimport.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 35 35 100.0 %
Date: 2015-06-13 12:38:46 Functions: 27 31 87.1 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.11