Files
libreoffice/starmath/qa/cppunit/test_starmath.cxx

419 lines
13 KiB
C++
Raw Normal View History

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_starmath.hxx"
#include "sal/config.h"
#include <cppuhelper/bootstrap.hxx>
#include <comphelper/processfactory.hxx>
2010-11-29 15:59:10 +00:00
#include <com/sun/star/frame/XFrame.hpp>
#include <com/sun/star/frame/XDesktop.hpp>
#include <vcl/svapp.hxx>
#include <smdll.hxx>
#include <document.hxx>
2010-11-29 15:59:10 +00:00
#include <view.hxx>
2010-12-07 11:12:13 +00:00
#include <sfx2/sfxmodelfactory.hxx>
#include <sfx2/bindings.hxx>
#include <sfx2/request.hxx>
2010-11-29 15:59:10 +00:00
#include <sfx2/dispatch.hxx>
#include <svl/stritem.hxx>
#include <editeng/editeng.hxx>
#include <editeng/editview.hxx>
2010-12-07 11:12:13 +00:00
#include <svx/zoomitem.hxx>
#include "preextstl.h"
#include <cppunit/TestSuite.h>
#include <cppunit/TestFixture.h>
#include <cppunit/TestCase.h>
#include <cppunit/plugin/TestPlugIn.h>
#include <cppunit/extensions/HelperMacros.h>
#include "postextstl.h"
SO2_DECL_REF(SmDocShell)
SO2_IMPL_REF(SmDocShell)
using namespace ::com::sun::star;
namespace {
class Test : public CppUnit::TestFixture {
public:
Test();
~Test();
// init
virtual void setUp();
virtual void tearDown();
// tests
2010-12-01 20:48:30 +00:00
void tmEditUndoRedo();
void tmEditAllClipboard();
void tmEditMarker();
void tmEditFailure();
2010-11-29 21:24:16 +00:00
2010-12-01 20:48:30 +00:00
void tViewZoom();
2010-11-29 21:24:16 +00:00
CPPUNIT_TEST_SUITE(Test);
CPPUNIT_TEST(tmEditUndoRedo);
CPPUNIT_TEST(tmEditAllClipboard);
CPPUNIT_TEST(tmEditMarker);
CPPUNIT_TEST(tmEditFailure);
CPPUNIT_TEST(tViewZoom);
CPPUNIT_TEST_SUITE_END();
private:
2010-11-29 15:59:10 +00:00
uno::Reference<uno::XComponentContext> m_xContext;
uno::Reference<lang::XMultiComponentFactory> m_xFactory;
2010-12-01 20:48:30 +00:00
SfxBindings m_aBindings;
SfxDispatcher *m_pDispatcher;
SmCmdBoxWindow *m_pSmCmdBoxWindow;
SmEditWindow *m_pEditWindow;
SmDocShellRef m_xDocShRef;
SmViewShell *m_pViewShell;
};
Test::Test()
{
2010-11-29 15:59:10 +00:00
m_xContext = cppu::defaultBootstrap_InitialComponentContext();
m_xFactory = m_xContext->getServiceManager();
2010-11-29 15:59:10 +00:00
uno::Reference<lang::XMultiServiceFactory> xSM(m_xFactory, uno::UNO_QUERY_THROW);
//Without this we're crashing because callees are using
//getProcessServiceFactory. In general those should be removed in favour
//of retaining references to the root ServiceFactory as its passed around
comphelper::setProcessServiceFactory(xSM);
InitVCL(xSM);
SmDLL::Init();
}
2010-12-01 20:48:30 +00:00
void Test::setUp()
{
2010-12-07 11:12:13 +00:00
m_xDocShRef = new SmDocShell(
SFXMODEL_EMBEDDED_OBJECT |
SFXMODEL_DISABLE_EMBEDDED_SCRIPTS |
SFXMODEL_DISABLE_DOCUMENT_RECOVERY);
2010-12-01 20:48:30 +00:00
m_xDocShRef->DoInitNew(0);
SfxViewFrame *pViewFrame = SfxViewFrame::LoadHiddenDocument(*m_xDocShRef, 0);
CPPUNIT_ASSERT_MESSAGE("Should have a SfxViewFrame", pViewFrame);
m_pDispatcher = new SfxDispatcher(pViewFrame);
m_aBindings.SetDispatcher(m_pDispatcher);
m_pSmCmdBoxWindow = new SmCmdBoxWindow(&m_aBindings, NULL, NULL);
m_pEditWindow = new SmEditWindow(*m_pSmCmdBoxWindow);
m_pViewShell = m_pEditWindow->GetView();
CPPUNIT_ASSERT_MESSAGE("Should have a SmViewShell", m_pViewShell);
}
void Test::tearDown()
{
2010-12-01 20:48:30 +00:00
delete m_pEditWindow;
delete m_pSmCmdBoxWindow;
delete m_pDispatcher;
m_xDocShRef.Clear();
}
Test::~Test()
{
2010-11-29 15:59:10 +00:00
uno::Reference< lang::XComponent >(m_xContext, uno::UNO_QUERY_THROW)->dispose();
}
2010-12-01 20:48:30 +00:00
void Test::tmEditMarker()
2010-11-29 15:59:10 +00:00
{
{
rtl::OUString sMarkedText(RTL_CONSTASCII_USTRINGPARAM("<?> under <?> under <?>"));
2010-12-01 20:48:30 +00:00
m_pEditWindow->SetText(sMarkedText);
m_pEditWindow->Flush();
rtl::OUString sFinalText = m_pEditWindow->GetText();
2010-11-29 15:59:10 +00:00
CPPUNIT_ASSERT_MESSAGE("Should be equal text", sFinalText == sMarkedText);
}
{
rtl::OUString sTargetText(RTL_CONSTASCII_USTRINGPARAM("a under b under c"));
2010-12-01 20:48:30 +00:00
m_pEditWindow->SelNextMark();
m_pEditWindow->Cut();
m_pEditWindow->InsertText(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("a")));
2010-11-29 15:59:10 +00:00
2010-12-01 20:48:30 +00:00
m_pEditWindow->SelNextMark();
m_pEditWindow->SelNextMark();
m_pEditWindow->Cut();
m_pEditWindow->InsertText(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("c")));
2010-11-29 15:59:10 +00:00
2010-12-01 20:48:30 +00:00
m_pEditWindow->SelPrevMark();
m_pEditWindow->Cut();
m_pEditWindow->InsertText(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("b")));
2010-11-29 15:59:10 +00:00
2010-12-01 20:48:30 +00:00
m_pEditWindow->Flush();
rtl::OUString sFinalText = m_pEditWindow->GetText();
2010-11-29 15:59:10 +00:00
CPPUNIT_ASSERT_MESSAGE("Should be a under b under c", sFinalText == sTargetText);
}
{
2010-12-01 20:48:30 +00:00
m_pEditWindow->SetText(rtl::OUString());
m_pEditWindow->Flush();
}
}
2010-12-01 20:48:30 +00:00
void Test::tmEditAllClipboard()
{
rtl::OUString sOriginalText(RTL_CONSTASCII_USTRINGPARAM("a over b"));
{
2010-12-01 20:48:30 +00:00
m_pEditWindow->SetText(sOriginalText);
m_pEditWindow->Flush();
rtl::OUString sFinalText = m_pEditWindow->GetText();
CPPUNIT_ASSERT_MESSAGE("Should be equal text", sFinalText == sOriginalText);
}
{
2010-12-01 20:48:30 +00:00
m_pEditWindow->SelectAll();
m_pEditWindow->Cut();
m_pEditWindow->Flush();
rtl::OUString sFinalText = m_pEditWindow->GetText();
CPPUNIT_ASSERT_MESSAGE("Should be empty", !sFinalText.getLength());
}
{
2010-12-01 20:48:30 +00:00
m_pEditWindow->Paste();
m_pEditWindow->Flush();
rtl::OUString sFinalText = m_pEditWindow->GetText();
CPPUNIT_ASSERT_MESSAGE("Should be equal text", sFinalText == sOriginalText);
}
{
2010-12-01 20:48:30 +00:00
m_pEditWindow->SelectAll();
m_pEditWindow->Copy();
}
{
rtl::OUString sExpectedText(RTL_CONSTASCII_USTRINGPARAM("a over ba over b"));
2010-12-01 20:48:30 +00:00
m_pEditWindow->Paste();
m_pEditWindow->Paste();
m_pEditWindow->Flush();
rtl::OUString sFinalText = m_pEditWindow->GetText();
CPPUNIT_ASSERT_MESSAGE("Should be equal text", sFinalText == sExpectedText);
}
{
2010-12-01 20:48:30 +00:00
m_pEditWindow->SetText(rtl::OUString());
m_pEditWindow->Flush();
}
}
2010-12-01 20:48:30 +00:00
void Test::tmEditFailure()
{
2010-12-01 20:48:30 +00:00
m_xDocShRef->SetText(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("color a b over {a/}")));
2010-12-01 20:48:30 +00:00
const SmErrorDesc *pErrorDesc = m_xDocShRef->GetParser().NextError();
CPPUNIT_ASSERT_MESSAGE("Should be a PE_UNEXPECTED_CHAR",
pErrorDesc && pErrorDesc->Type == PE_UNEXPECTED_CHAR);
2010-12-01 20:48:30 +00:00
pErrorDesc = m_xDocShRef->GetParser().PrevError();
CPPUNIT_ASSERT_MESSAGE("Should be a PE_RGROUP_EXPECTED",
pErrorDesc && pErrorDesc->Type == PE_RGROUP_EXPECTED);
2010-12-01 20:48:30 +00:00
pErrorDesc = m_xDocShRef->GetParser().PrevError();
CPPUNIT_ASSERT_MESSAGE("Should be a PE_COLOR_EXPECTED",
pErrorDesc && pErrorDesc->Type == PE_COLOR_EXPECTED);
2010-12-01 20:48:30 +00:00
const SmErrorDesc *pLastErrorDesc = m_xDocShRef->GetParser().PrevError();
CPPUNIT_ASSERT_MESSAGE("Should be three syntax errors",
pLastErrorDesc && pLastErrorDesc == pErrorDesc);
}
2010-12-01 20:48:30 +00:00
void Test::tmEditUndoRedo()
{
2010-12-01 20:48:30 +00:00
EditEngine &rEditEngine = m_xDocShRef->GetEditEngine();
rtl::OUString sStringOne(RTL_CONSTASCII_USTRINGPARAM("a under b"));
{
rEditEngine.SetText(0, sStringOne);
2010-12-01 20:48:30 +00:00
m_xDocShRef->UpdateText();
rtl::OUString sFinalText = m_xDocShRef->GetText();
CPPUNIT_ASSERT_MESSAGE("Strings must match", sStringOne == sFinalText);
}
rtl::OUString sStringTwo(RTL_CONSTASCII_USTRINGPARAM("a over b"));
{
rEditEngine.SetText(0, sStringTwo);
2010-12-01 20:48:30 +00:00
m_xDocShRef->UpdateText();
rtl::OUString sFinalText = m_xDocShRef->GetText();
CPPUNIT_ASSERT_MESSAGE("Strings must match", sStringTwo == sFinalText);
}
2010-12-01 20:48:30 +00:00
SfxRequest aUndo(SID_UNDO, SFX_CALLMODE_SYNCHRON, m_xDocShRef->GetPool());
{
2010-12-01 20:48:30 +00:00
m_xDocShRef->Execute(aUndo);
rtl::OUString sFoo = rEditEngine.GetText();
2010-12-01 20:48:30 +00:00
m_xDocShRef->UpdateText();
rtl::OUString sFinalText = m_xDocShRef->GetText();
CPPUNIT_ASSERT_MESSAGE("Strings much match", sStringOne == sFinalText);
}
{
2010-12-01 20:48:30 +00:00
m_xDocShRef->Execute(aUndo);
rtl::OUString sFoo = rEditEngine.GetText();
2010-12-01 20:48:30 +00:00
m_xDocShRef->UpdateText();
rtl::OUString sFinalText = m_xDocShRef->GetText();
CPPUNIT_ASSERT_MESSAGE("Must now be empty", !sFinalText.getLength());
}
2010-12-01 20:48:30 +00:00
SfxRequest aRedo(SID_REDO, SFX_CALLMODE_SYNCHRON, m_xDocShRef->GetPool());
{
2010-12-01 20:48:30 +00:00
m_xDocShRef->Execute(aRedo);
rtl::OUString sFoo = rEditEngine.GetText();
2010-12-01 20:48:30 +00:00
m_xDocShRef->UpdateText();
rtl::OUString sFinalText = m_xDocShRef->GetText();
CPPUNIT_ASSERT_MESSAGE("Strings much match", sStringOne == sFinalText);
}
2010-11-29 21:03:42 +00:00
{
rEditEngine.SetText(0, rtl::OUString());
2010-12-01 20:48:30 +00:00
m_xDocShRef->UpdateText();
2010-11-29 21:03:42 +00:00
rEditEngine.ClearModifyFlag();
2010-12-01 20:48:30 +00:00
rtl::OUString sFinalText = m_xDocShRef->GetText();
2010-11-29 21:03:42 +00:00
CPPUNIT_ASSERT_MESSAGE("Must be empty", !sFinalText.getLength());
}
2010-11-10 16:17:58 +00:00
}
2010-12-01 20:48:30 +00:00
void Test::tViewZoom()
2010-11-29 21:24:16 +00:00
{
sal_uInt16 nOrigZoom, nNextZoom, nFinalZoom;
2010-12-06 21:26:08 +00:00
EditEngine &rEditEngine = m_xDocShRef->GetEditEngine();
rtl::OUString sStringOne(RTL_CONSTASCII_USTRINGPARAM("a under b"));
{
rEditEngine.SetText(0, sStringOne);
m_xDocShRef->UpdateText();
rtl::OUString sFinalText = m_xDocShRef->GetText();
CPPUNIT_ASSERT_MESSAGE("Strings must match", sStringOne == sFinalText);
}
2010-12-01 20:48:30 +00:00
SmGraphicWindow &rGraphicWindow = m_pViewShell->GetGraphicWindow();
2010-12-06 21:26:08 +00:00
rGraphicWindow.SetSizePixel(Size(1024, 800));
2010-11-29 21:24:16 +00:00
nOrigZoom = rGraphicWindow.GetZoom();
{
2010-12-01 20:48:30 +00:00
SfxRequest aZoomIn(SID_ZOOMIN, SFX_CALLMODE_SYNCHRON, m_pViewShell->GetPool());
m_pViewShell->Execute(aZoomIn);
2010-11-29 21:24:16 +00:00
nNextZoom = rGraphicWindow.GetZoom();
CPPUNIT_ASSERT_MESSAGE("Should be bigger", nNextZoom > nOrigZoom);
}
{
2010-12-01 20:48:30 +00:00
SfxRequest aZoomOut(SID_ZOOMOUT, SFX_CALLMODE_SYNCHRON, m_pViewShell->GetPool());
m_pViewShell->Execute(aZoomOut);
2010-11-29 21:24:16 +00:00
nFinalZoom = rGraphicWindow.GetZoom();
CPPUNIT_ASSERT_MESSAGE("Should be equal", nFinalZoom == nOrigZoom);
}
2010-12-06 21:26:08 +00:00
2010-12-07 11:12:13 +00:00
sal_uInt16 nOptimalZoom=0;
{
SfxRequest aZoom(SID_FITINWINDOW, SFX_CALLMODE_SYNCHRON, m_pViewShell->GetPool());
m_pViewShell->Execute(aZoom);
nOptimalZoom = rGraphicWindow.GetZoom();
CPPUNIT_ASSERT_MESSAGE("Should be about 800%", nOptimalZoom > nOrigZoom);
}
{
SfxItemSet aSet(m_xDocShRef->GetPool(), SID_ATTR_ZOOM, SID_ATTR_ZOOM);
aSet.Put(SvxZoomItem(SVX_ZOOM_OPTIMAL, 0));
SfxRequest aZoom(SID_ATTR_ZOOM, SFX_CALLMODE_SYNCHRON, aSet);
m_pViewShell->Execute(aZoom);
nFinalZoom = rGraphicWindow.GetZoom();
CPPUNIT_ASSERT_MESSAGE("Should be optimal zoom", nFinalZoom == nOptimalZoom);
}
#if 0
//TO-DO: switch from embedded to normal to get these meaningfull
2010-12-06 21:26:08 +00:00
{
2010-12-07 11:12:13 +00:00
SfxRequest aZoomOut(SID_ZOOMOUT, SFX_CALLMODE_SYNCHRON, m_pViewShell->GetPool());
2010-12-06 21:26:08 +00:00
m_pViewShell->Execute(aZoomOut);
nFinalZoom = rGraphicWindow.GetZoom();
2010-12-07 11:12:13 +00:00
CPPUNIT_ASSERT_MESSAGE("Should not be optimal zoom", nFinalZoom != nOptimalZoom);
SfxItemSet aSet(m_xDocShRef->GetPool(), SID_ATTR_ZOOM, SID_ATTR_ZOOM);
aSet.Put(SvxZoomItem(SVX_ZOOM_PAGEWIDTH, 0));
SfxRequest aZoom(SID_ATTR_ZOOM, SFX_CALLMODE_SYNCHRON, aSet);
m_pViewShell->Execute(aZoom);
nFinalZoom = rGraphicWindow.GetZoom();
CPPUNIT_ASSERT_MESSAGE("Should be same as optimal zoom", nFinalZoom == nOptimalZoom);
2010-12-06 21:26:08 +00:00
}
2010-12-07 11:12:13 +00:00
{
SfxRequest aZoomOut(SID_ZOOMOUT, SFX_CALLMODE_SYNCHRON, m_pViewShell->GetPool());
m_pViewShell->Execute(aZoomOut);
nFinalZoom = rGraphicWindow.GetZoom();
CPPUNIT_ASSERT_MESSAGE("Should not be optimal zoom", nFinalZoom != nOptimalZoom);
SfxItemSet aSet(m_xDocShRef->GetPool(), SID_ATTR_ZOOM, SID_ATTR_ZOOM);
aSet.Put(SvxZoomItem(SVX_ZOOM_WHOLEPAGE, 0));
SfxRequest aZoom(SID_ATTR_ZOOM, SFX_CALLMODE_SYNCHRON, aSet);
m_pViewShell->Execute(aZoom);
nFinalZoom = rGraphicWindow.GetZoom();
CPPUNIT_ASSERT_MESSAGE("Should be same as optimal zoom", nFinalZoom == nOptimalZoom);
}
#endif
{
SfxRequest aZoomOut(SID_ZOOMOUT, SFX_CALLMODE_SYNCHRON, m_pViewShell->GetPool());
m_pViewShell->Execute(aZoomOut);
nFinalZoom = rGraphicWindow.GetZoom();
CPPUNIT_ASSERT_MESSAGE("Should not be optimal zoom", nFinalZoom != nOptimalZoom);
SfxItemSet aSet(m_xDocShRef->GetPool(), SID_ATTR_ZOOM, SID_ATTR_ZOOM);
aSet.Put(SvxZoomItem(SVX_ZOOM_PERCENT, 50));
SfxRequest aZoom(SID_ATTR_ZOOM, SFX_CALLMODE_SYNCHRON, aSet);
m_pViewShell->Execute(aZoom);
nFinalZoom = rGraphicWindow.GetZoom();
CPPUNIT_ASSERT_MESSAGE("Should be 50%", nFinalZoom == 50);
}
2010-12-07 11:17:24 +00:00
{
SfxItemSet aSet(m_xDocShRef->GetPool(), SID_ATTR_ZOOM, SID_ATTR_ZOOM);
aSet.Put(SvxZoomItem(SVX_ZOOM_PERCENT, 5));
SfxRequest aZoom(SID_ATTR_ZOOM, SFX_CALLMODE_SYNCHRON, aSet);
m_pViewShell->Execute(aZoom);
nFinalZoom = rGraphicWindow.GetZoom();
CPPUNIT_ASSERT_MESSAGE("Should be Clipped to 25%", nFinalZoom == 25);
}
{
SfxItemSet aSet(m_xDocShRef->GetPool(), SID_ATTR_ZOOM, SID_ATTR_ZOOM);
aSet.Put(SvxZoomItem(SVX_ZOOM_PERCENT, 1000));
SfxRequest aZoom(SID_ATTR_ZOOM, SFX_CALLMODE_SYNCHRON, aSet);
m_pViewShell->Execute(aZoom);
nFinalZoom = rGraphicWindow.GetZoom();
CPPUNIT_ASSERT_MESSAGE("Should be Clipped to 800%", nFinalZoom == 800);
}
2010-11-29 21:24:16 +00:00
}
CPPUNIT_TEST_SUITE_REGISTRATION(Test);
}
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */