LCOV - code coverage report
Current view: top level - starmath/qa/cppunit - test_starmath.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 158 158 100.0 %
Date: 2014-11-03 Functions: 15 16 93.8 %
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 <sal/config.h>
      11             : #include <test/bootstrapfixture.hxx>
      12             : 
      13             : #include <vcl/svapp.hxx>
      14             : #include <smdll.hxx>
      15             : #include <document.hxx>
      16             : #include <view.hxx>
      17             : 
      18             : #include <sfx2/sfxmodelfactory.hxx>
      19             : #include <sfx2/bindings.hxx>
      20             : #include <sfx2/request.hxx>
      21             : #include <sfx2/dispatch.hxx>
      22             : 
      23             : #include <svl/stritem.hxx>
      24             : 
      25             : #include <editeng/editeng.hxx>
      26             : #include <editeng/editview.hxx>
      27             : 
      28             : #include <sfx2/zoomitem.hxx>
      29             : 
      30             : typedef tools::SvRef<SmDocShell> SmDocShellRef;
      31             : 
      32             : using namespace ::com::sun::star;
      33             : 
      34             : namespace {
      35             : 
      36          24 : class Test : public test::BootstrapFixture
      37             : {
      38             : public:
      39             :     // init
      40             :     virtual void setUp() SAL_OVERRIDE;
      41             :     virtual void tearDown() SAL_OVERRIDE;
      42             : 
      43             :     // tests
      44             :     void editUndoRedo();
      45             :     void editMarker();
      46             :     void editFailure();
      47             : 
      48             :     void viewZoom();
      49             : 
      50           4 :     CPPUNIT_TEST_SUITE(Test);
      51           2 :     CPPUNIT_TEST(editUndoRedo);
      52           2 :     CPPUNIT_TEST(editMarker);
      53           2 :     CPPUNIT_TEST(editFailure);
      54           2 :     CPPUNIT_TEST(viewZoom);
      55           4 :     CPPUNIT_TEST_SUITE_END();
      56             : 
      57             : private:
      58             :     uno::Reference<uno::XComponentContext> m_xContext;
      59             :     uno::Reference<lang::XMultiComponentFactory> m_xFactory;
      60             : 
      61             :     SfxBindings m_aBindings;
      62             :     SfxDispatcher *m_pDispatcher;
      63             :     SmCmdBoxWindow *m_pSmCmdBoxWindow;
      64             :     SmEditWindow *m_pEditWindow;
      65             :     SmDocShellRef m_xDocShRef;
      66             :     SmViewShell *m_pViewShell;
      67             : };
      68             : 
      69           8 : void Test::setUp()
      70             : {
      71           8 :     BootstrapFixture::setUp();
      72             : 
      73           8 :     SmGlobals::ensure();
      74             : 
      75          24 :     m_xDocShRef = new SmDocShell(
      76             :         SFXMODEL_STANDARD |
      77             :         SFXMODEL_DISABLE_EMBEDDED_SCRIPTS |
      78          16 :         SFXMODEL_DISABLE_DOCUMENT_RECOVERY);
      79           8 :     m_xDocShRef->DoInitNew(0);
      80             : 
      81           8 :     SfxViewFrame *pViewFrame = SfxViewFrame::LoadHiddenDocument(*m_xDocShRef, 0);
      82             : 
      83           8 :     CPPUNIT_ASSERT_MESSAGE("Should have a SfxViewFrame", pViewFrame);
      84             : 
      85           8 :     m_pDispatcher = new SfxDispatcher(pViewFrame);
      86           8 :     m_aBindings.SetDispatcher(m_pDispatcher);
      87           8 :     m_aBindings.EnterRegistrations();
      88           8 :     m_pSmCmdBoxWindow = new SmCmdBoxWindow(&m_aBindings, NULL, NULL);
      89           8 :     m_aBindings.LeaveRegistrations();
      90           8 :     m_pEditWindow = new SmEditWindow(*m_pSmCmdBoxWindow);
      91           8 :     m_pViewShell = m_pEditWindow->GetView();
      92           8 :     CPPUNIT_ASSERT_MESSAGE("Should have a SmViewShell", m_pViewShell);
      93           8 : }
      94             : 
      95           8 : void Test::tearDown()
      96             : {
      97           8 :     delete m_pEditWindow;
      98           8 :     delete m_pSmCmdBoxWindow;
      99           8 :     delete m_pDispatcher;
     100           8 :     m_xDocShRef->DoClose();
     101           8 :     m_xDocShRef.Clear();
     102             : 
     103           8 :     BootstrapFixture::tearDown();
     104           8 : }
     105             : 
     106           2 : void Test::editMarker()
     107             : {
     108             :     {
     109           2 :         OUString sMarkedText("<?> under <?> under <?>");
     110           2 :         m_pEditWindow->SetText(sMarkedText);
     111           2 :         m_pEditWindow->Flush();
     112           4 :         OUString sFinalText = m_pEditWindow->GetText();
     113           4 :         CPPUNIT_ASSERT_MESSAGE("Should be equal text", sFinalText == sMarkedText);
     114             :     }
     115             : 
     116             :     {
     117           2 :         OUString sTargetText("a under b under c");
     118             : 
     119           2 :         m_pEditWindow->SelNextMark();
     120           2 :         m_pEditWindow->Delete();
     121           2 :         m_pEditWindow->InsertText("a");
     122             : 
     123           2 :         m_pEditWindow->SelNextMark();
     124           2 :         m_pEditWindow->SelNextMark();
     125           2 :         m_pEditWindow->Delete();
     126           2 :         m_pEditWindow->InsertText("c");
     127             : 
     128           2 :         m_pEditWindow->SelPrevMark();
     129           2 :         m_pEditWindow->Delete();
     130           2 :         m_pEditWindow->InsertText("b");
     131             : 
     132           2 :         m_pEditWindow->Flush();
     133           4 :         OUString sFinalText = m_pEditWindow->GetText();
     134           4 :         CPPUNIT_ASSERT_MESSAGE("Should be a under b under c", sFinalText == sTargetText);
     135             :     }
     136             : 
     137             :     {
     138           2 :         m_pEditWindow->SetText(OUString());
     139           2 :         m_pEditWindow->Flush();
     140             :     }
     141           2 : }
     142             : 
     143           2 : void Test::editFailure()
     144             : {
     145           2 :     m_xDocShRef->SetText("color a b over {a/}");
     146             : 
     147           2 :     const SmErrorDesc *pErrorDesc = m_xDocShRef->GetParser().NextError();
     148             : 
     149           4 :     CPPUNIT_ASSERT_MESSAGE("Should be a PE_COLOR_EXPECTED",
     150           2 :         pErrorDesc && pErrorDesc->Type == PE_COLOR_EXPECTED);
     151             : 
     152           2 :     pErrorDesc = m_xDocShRef->GetParser().PrevError();
     153             : 
     154           4 :     CPPUNIT_ASSERT_MESSAGE("Should be a PE_UNEXPECTED_CHAR",
     155           2 :         pErrorDesc && pErrorDesc->Type == PE_UNEXPECTED_CHAR);
     156             : 
     157           2 :     pErrorDesc = m_xDocShRef->GetParser().PrevError();
     158             : 
     159           4 :     CPPUNIT_ASSERT_MESSAGE("Should be a PE_RGROUP_EXPECTED",
     160           2 :         pErrorDesc && pErrorDesc->Type == PE_RGROUP_EXPECTED);
     161             : 
     162           2 :     const SmErrorDesc *pLastErrorDesc = m_xDocShRef->GetParser().PrevError();
     163             : 
     164           4 :     CPPUNIT_ASSERT_MESSAGE("Should be three syntax errors",
     165           2 :         pLastErrorDesc && pLastErrorDesc == pErrorDesc);
     166           2 : }
     167             : 
     168           2 : void Test::editUndoRedo()
     169             : {
     170           2 :     EditEngine &rEditEngine = m_xDocShRef->GetEditEngine();
     171             : 
     172           2 :     OUString sStringOne("a under b");
     173             :     {
     174           2 :         rEditEngine.SetText(0, sStringOne);
     175           2 :         m_xDocShRef->UpdateText();
     176           2 :         OUString sFinalText = m_xDocShRef->GetText();
     177           2 :         CPPUNIT_ASSERT_MESSAGE("Strings must match", sStringOne == sFinalText);
     178             :     }
     179             : 
     180           4 :     OUString sStringTwo("a over b");
     181             :     {
     182           2 :         rEditEngine.SetText(0, sStringTwo);
     183           2 :         m_xDocShRef->UpdateText();
     184           2 :         OUString sFinalText = m_xDocShRef->GetText();
     185           2 :         CPPUNIT_ASSERT_MESSAGE("Strings must match", sStringTwo == sFinalText);
     186             :     }
     187             : 
     188           4 :     SfxRequest aUndo(SID_UNDO, SfxCallMode::SYNCHRON, m_xDocShRef->GetPool());
     189             : 
     190             :     {
     191           2 :         m_xDocShRef->Execute(aUndo);
     192           2 :         m_xDocShRef->UpdateText();
     193           2 :         OUString sFinalText = m_xDocShRef->GetText();
     194           2 :         CPPUNIT_ASSERT_MESSAGE("Strings much match", sStringOne == sFinalText);
     195             :     }
     196             : 
     197             :     {
     198           2 :         m_xDocShRef->Execute(aUndo);
     199           2 :         m_xDocShRef->UpdateText();
     200           2 :         OUString sFinalText = m_xDocShRef->GetText();
     201           2 :         CPPUNIT_ASSERT_MESSAGE("Must now be empty", !sFinalText.getLength());
     202             :     }
     203             : 
     204           4 :     SfxRequest aRedo(SID_REDO, SfxCallMode::SYNCHRON, m_xDocShRef->GetPool());
     205             :     {
     206           2 :         m_xDocShRef->Execute(aRedo);
     207           2 :         m_xDocShRef->UpdateText();
     208           2 :         OUString sFinalText = m_xDocShRef->GetText();
     209           2 :         CPPUNIT_ASSERT_MESSAGE("Strings much match", sStringOne == sFinalText);
     210             :     }
     211             : 
     212             :     {
     213           2 :         rEditEngine.SetText(0, OUString());
     214           2 :         m_xDocShRef->UpdateText();
     215           2 :         rEditEngine.ClearModifyFlag();
     216           2 :         OUString sFinalText = m_xDocShRef->GetText();
     217           2 :         CPPUNIT_ASSERT_MESSAGE("Must be empty", !sFinalText.getLength());
     218           2 :     }
     219             : 
     220           2 : }
     221             : 
     222           2 : void Test::viewZoom()
     223             : {
     224             :     sal_uInt16 nOrigZoom, nNextZoom, nFinalZoom;
     225             : 
     226           2 :     EditEngine &rEditEngine = m_xDocShRef->GetEditEngine();
     227             : 
     228           2 :     OUString sStringOne("a under b");
     229             :     {
     230           2 :         rEditEngine.SetText(0, sStringOne);
     231           2 :         m_xDocShRef->UpdateText();
     232           2 :         OUString sFinalText = m_xDocShRef->GetText();
     233           2 :         CPPUNIT_ASSERT_MESSAGE("Strings must match", sStringOne == sFinalText);
     234             :     }
     235             : 
     236           2 :     SmGraphicWindow &rGraphicWindow = m_pViewShell->GetGraphicWindow();
     237           2 :     rGraphicWindow.SetSizePixel(Size(1024, 800));
     238           2 :     nOrigZoom = rGraphicWindow.GetZoom();
     239             : 
     240             :     {
     241           2 :         SfxRequest aZoomIn(SID_ZOOMIN, SfxCallMode::SYNCHRON, m_pViewShell->GetPool());
     242           2 :         m_pViewShell->Execute(aZoomIn);
     243           2 :         nNextZoom = rGraphicWindow.GetZoom();
     244           2 :         CPPUNIT_ASSERT_MESSAGE("Should be bigger", nNextZoom > nOrigZoom);
     245             :     }
     246             : 
     247             :     {
     248           2 :         SfxRequest aZoomOut(SID_ZOOMOUT, SfxCallMode::SYNCHRON, m_pViewShell->GetPool());
     249           2 :         m_pViewShell->Execute(aZoomOut);
     250           2 :         nFinalZoom = rGraphicWindow.GetZoom();
     251           2 :         CPPUNIT_ASSERT_MESSAGE("Should be equal", nFinalZoom == nOrigZoom);
     252             :     }
     253             : 
     254           2 :     sal_uInt16 nOptimalZoom=0;
     255             : 
     256             :     {
     257           2 :         SfxRequest aZoom(SID_ZOOM_OPTIMAL, SfxCallMode::SYNCHRON, m_pViewShell->GetPool());
     258           2 :         m_pViewShell->Execute(aZoom);
     259           2 :         nOptimalZoom = rGraphicWindow.GetZoom();
     260           2 :         CPPUNIT_ASSERT_MESSAGE("Should be about 800%", nOptimalZoom > nOrigZoom);
     261             :     }
     262             : 
     263             :     {
     264           2 :         SfxItemSet aSet(m_xDocShRef->GetPool(), SID_ATTR_ZOOM, SID_ATTR_ZOOM);
     265           2 :         aSet.Put(SvxZoomItem(SVX_ZOOM_OPTIMAL, 0));
     266           4 :         SfxRequest aZoom(SID_ATTR_ZOOM, SfxCallMode::SYNCHRON, aSet);
     267           2 :         m_pViewShell->Execute(aZoom);
     268           2 :         nFinalZoom = rGraphicWindow.GetZoom();
     269           4 :         CPPUNIT_ASSERT_MESSAGE("Should be optimal zoom", nFinalZoom == nOptimalZoom);
     270             :     }
     271             : 
     272             : //To-Do: investigate GetPrinter logic of SVX_ZOOM_PAGEWIDTH/SVX_ZOOM_WHOLEPAGE to ensure
     273             : //consistent value regardless of
     274             : #if 0
     275             :     {
     276             :         SfxRequest aZoomOut(SID_ZOOMOUT, SfxCallMode::SYNCHRON, m_pViewShell->GetPool());
     277             :         m_pViewShell->Execute(aZoomOut);
     278             :         nFinalZoom = rGraphicWindow.GetZoom();
     279             :         CPPUNIT_ASSERT_MESSAGE("Should not be optimal zoom", nFinalZoom != nOptimalZoom);
     280             : 
     281             :         SfxItemSet aSet(m_xDocShRef->GetPool(), SID_ATTR_ZOOM, SID_ATTR_ZOOM);
     282             :         aSet.Put(SvxZoomItem(SVX_ZOOM_PAGEWIDTH, 0));
     283             :         SfxRequest aZoom(SID_ATTR_ZOOM, SfxCallMode::SYNCHRON, aSet);
     284             :         m_pViewShell->Execute(aZoom);
     285             :         nFinalZoom = rGraphicWindow.GetZoom();
     286             :         CPPUNIT_ASSERT_MESSAGE("Should be same as optimal zoom", nFinalZoom == nOptimalZoom);
     287             :     }
     288             : 
     289             :     {
     290             :         SfxRequest aZoomOut(SID_ZOOMOUT, SfxCallMode::SYNCHRON, m_pViewShell->GetPool());
     291             :         m_pViewShell->Execute(aZoomOut);
     292             :         nFinalZoom = rGraphicWindow.GetZoom();
     293             :         CPPUNIT_ASSERT_MESSAGE("Should not be optimal zoom", nFinalZoom != nOptimalZoom);
     294             : 
     295             :         SfxItemSet aSet(m_xDocShRef->GetPool(), SID_ATTR_ZOOM, SID_ATTR_ZOOM);
     296             :         aSet.Put(SvxZoomItem(SVX_ZOOM_WHOLEPAGE, 0));
     297             :         SfxRequest aZoom(SID_ATTR_ZOOM, SfxCallMode::SYNCHRON, aSet);
     298             :         m_pViewShell->Execute(aZoom);
     299             :         nFinalZoom = rGraphicWindow.GetZoom();
     300             :         CPPUNIT_ASSERT_MESSAGE("Should be same as optimal zoom", nFinalZoom == nOptimalZoom);
     301             :     }
     302             : #endif
     303             : 
     304             :     {
     305           2 :         SfxRequest aZoomOut(SID_ZOOMOUT, SfxCallMode::SYNCHRON, m_pViewShell->GetPool());
     306           2 :         m_pViewShell->Execute(aZoomOut);
     307           2 :         nFinalZoom = rGraphicWindow.GetZoom();
     308           2 :         CPPUNIT_ASSERT_MESSAGE("Should not be optimal zoom", nFinalZoom != nOptimalZoom);
     309             : 
     310           4 :         SfxItemSet aSet(m_xDocShRef->GetPool(), SID_ATTR_ZOOM, SID_ATTR_ZOOM);
     311           2 :         aSet.Put(SvxZoomItem(SVX_ZOOM_PERCENT, 50));
     312           4 :         SfxRequest aZoom(SID_ATTR_ZOOM, SfxCallMode::SYNCHRON, aSet);
     313           2 :         m_pViewShell->Execute(aZoom);
     314           2 :         nFinalZoom = rGraphicWindow.GetZoom();
     315           4 :         CPPUNIT_ASSERT_MESSAGE("Should be 50%", nFinalZoom == 50);
     316             :     }
     317             : 
     318             :     {
     319           2 :         SfxItemSet aSet(m_xDocShRef->GetPool(), SID_ATTR_ZOOM, SID_ATTR_ZOOM);
     320           2 :         aSet.Put(SvxZoomItem(SVX_ZOOM_PERCENT, 5));
     321           4 :         SfxRequest aZoom(SID_ATTR_ZOOM, SfxCallMode::SYNCHRON, aSet);
     322           2 :         m_pViewShell->Execute(aZoom);
     323           2 :         nFinalZoom = rGraphicWindow.GetZoom();
     324           4 :         CPPUNIT_ASSERT_MESSAGE("Should be Clipped to 25%", nFinalZoom == 25);
     325             :     }
     326             : 
     327             :     {
     328           2 :         SfxItemSet aSet(m_xDocShRef->GetPool(), SID_ATTR_ZOOM, SID_ATTR_ZOOM);
     329           2 :         aSet.Put(SvxZoomItem(SVX_ZOOM_PERCENT, 1000));
     330           4 :         SfxRequest aZoom(SID_ATTR_ZOOM, SfxCallMode::SYNCHRON, aSet);
     331           2 :         m_pViewShell->Execute(aZoom);
     332           2 :         nFinalZoom = rGraphicWindow.GetZoom();
     333           4 :         CPPUNIT_ASSERT_MESSAGE("Should be Clipped to 800%", nFinalZoom == 800);
     334           2 :     }
     335             : 
     336           2 : }
     337             : 
     338           2 : CPPUNIT_TEST_SUITE_REGISTRATION(Test);
     339             : 
     340             : }
     341             : 
     342           8 : CPPUNIT_PLUGIN_IMPLEMENT();
     343             : 
     344             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10