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

Generated by: LCOV version 1.10