Commits

Anonymous committed 380ab45

swbookmarkfixes01: PageDescManager unit tests

  • Participants
  • Parent commits f8e33bd

Comments (0)

Files changed (6)

sw/inc/IDocumentLayoutAccess.hxx

     virtual SwFrmFmt* CopyLayoutFmt( const SwFrmFmt& rSrc, const SwFmtAnchor& rNewAnchor,
                                      bool bSetTxtFlyAtt, bool bMakeFrms ) = 0;
 
-protected:
-
     virtual ~IDocumentLayoutAccess() {};
  };
 

sw/inc/IDocumentUndoRedo.hxx

     virtual SwUndoNoModifiedPosition getUndoNoModifiedPosition() const = 0;
 
     virtual void SetModified() = 0;
-protected:
+
  	virtual ~IDocumentUndoRedo() {};
 };
  

sw/inc/pagedesc.hxx

 #include "swdllapi.h"
 #include <swtypes.hxx>	//fuer SwTwips
 #include <frmfmt.hxx>
-//#ifndef _NUMRULE_HXX
-//#include <numrule.hxx>
-//#endif
 #include <editeng/numitem.hxx>
+#include <editeng/frmdir.hxx>
 
 class SfxPoolItem;
 class SwTxtFmtColl;
 
 	SW_DLLPRIVATE void ResetAllAttr( sal_Bool bLeft );
 
-	SW_DLLPRIVATE SwPageDesc(const String&, SwFrmFmt*, SwDoc *pDc );
+	SW_DLLPRIVATE SwPageDesc(const String& rName, SwDoc* const pDoc, SvxFrameDirectionItem aFrameDirection);
+	SW_DLLPRIVATE SwPageDesc(const String&, SwFrmFmt*, SwDoc* const, SvxFrameDirection aFrameDir);
 
 public:
     // copy the complete PageDesc -- even with different docs and "deep"

sw/qa/core/PageDescManager/PageDescManagerTest.cxx

 #include <cppunit/extensions/HelperMacros.h>
 #include <cppunit/plugin/TestPlugIn.h>
 
+#include <boost/scoped_ptr.hpp>
+#include <boost/shared_ptr.hpp>
 
 #include <tools/rtti.hxx>
 #include <rsc/rscsfx.hxx>
 #include <svl/style.hxx>
+#include <editeng/frmdir.hxx>
 
 
 #define _CALBCK_HXX
 {
     public:
         // Meh, these need to go ...
-        SwFrmFmt* GetDfltFrmFmt() { return NULL; };
         void BroadcastStyleOperation(String, SfxStyleFamily, USHORT) {};
 };
 
 {
     public:
         SwPageDesc() {};
-        SwPageDesc(const String&, SwFrmFmt*, SwDoc*) {};
-        SwPageDesc(const SwPageDesc&) {};
-        String GetName() const { return String(); };
-        void SetName(const String&) {};
+        SwPageDesc(const String& rName, SwDoc*, SvxFrameDirection aFrameDir) : m_sName(rName) {};
+        SwPageDesc(const String& rName, SwFrmFmt*, SwDoc*) : m_sName(rName) {};
+        SwPageDesc(const SwPageDesc& rOther) : m_sName(rOther.m_sName), m_nFmtId(rOther.m_nFmtId) {};
+        String GetName() const { return m_sName; };
+        void SetName(const String& rName) { m_sName = rName; };
         SwFrmFmt& GetLeft() { return *((SwFrmFmt*)NULL); };
         SwFrmFmt& GetMaster() { return *((SwFrmFmt*)NULL); };
         SwPageDesc* GetFollow() { return NULL; };
         void SetFollow(SwPageDesc*) {};
         const SwPageDesc* GetFollow() const { return NULL; };
-        void Dispose();
+        void Dispose() {};
         bool HasInvalidPageFormat() const { return true; };
-        void ResetTotDefaultPageFormat();
-        USHORT GetPoolFmtId() const { return 0; };
-        void SetPoolFmtId( USHORT ) {};
-        void SetPoolHelpId( USHORT ) {};
-        void SetPoolHlpFileId( BYTE ) {};
+        void ResetTotDefaultPageFormat() {};
+        USHORT GetPoolFmtId() const { return m_nFmtId; };
+        void SetPoolFmtId(USHORT nFmtId) { m_nFmtId = nFmtId; };
+        void SetPoolHelpId(USHORT nHid) { m_nHid = nHid; };
+        USHORT GetPoolHelpId() const { return m_nHid; };
+        void SetPoolHlpFileId(BYTE nHfid) { m_nHfid = nHfid; };
+        BYTE GetPoolHlpFileId() const { return m_nHfid; };
+    private:
+        String m_sName;
+        USHORT m_nFmtId;
+        USHORT m_nHid;
+        BYTE  m_nHfid;
 };
 class SwPageDescExt : public SwPageDesc {};
 
 
 #include <source/core/doc/PageDescManager.cxx>
 
-void SwPageDesc::ResetTotDefaultPageFormat()
-{
-    OSL_TRACE("<SwPageDesc::ResetTotDefaultPageFormat(..)> - called.");
-}
-
-void SwPageDesc::Dispose()
-{
-    OSL_TRACE("<SwPageDesc::Dispose(..)> - called.");
-}
-
 void SwFrm::CheckPageDescs(SwPageFrm*, unsigned char)
 {
     OSL_TRACE("<SwFrm::CheckPageDescs(..)> - called.");
 #include <mock/LayoutAccessMockBase.hxx>
 #include <mock/UndoRedoMockBase.hxx>
 
-namespace
+using namespace ::boost;
+using namespace ::sw::pagedesc;
+using namespace ::sw::mock;
+
+namespace sw { namespace test
 {
 
-    class Test: public CppUnit::TestFixture
+    class PageDescManagerTest: public CppUnit::TestFixture
     {
         public:
-            void test()
-            {
-                CPPUNIT_ASSERT_EQUAL(true, true == true);
-                CPPUNIT_ASSERT_EQUAL(false, true == false);
-            }
+            void Create();
+            void MakePageDesc();
+            void MakePageDesc_Copy();
+            void GetPageDescCnt();
+            void GetPageDescByName();
+            void GetPageDescByPoolFmtId();
+            void GetDefaultPageDesc();
 
-            CPPUNIT_TEST_SUITE(Test);
-            CPPUNIT_TEST(test);
+            CPPUNIT_TEST_SUITE(PageDescManagerTest);
+            CPPUNIT_TEST(Create);
+            CPPUNIT_TEST(MakePageDesc);
+            CPPUNIT_TEST(MakePageDesc_Copy);
+            CPPUNIT_TEST(GetPageDescCnt);
+            CPPUNIT_TEST(GetPageDescByName);
+            CPPUNIT_TEST(GetPageDescByPoolFmtId);
+            CPPUNIT_TEST(GetDefaultPageDesc);
             CPPUNIT_TEST_SUITE_END();
+        private:
+            void Setup();
+            void AddPageDesc(const String& rName);
+            scoped_ptr<IDocumentPageDescAccess> m_pPageDescAccess;
+            scoped_ptr<SwDoc> m_pDoc;
+            scoped_ptr<IDocumentLayoutAccess> m_pLayoutAccess;
+            scoped_ptr<IDocumentUndoRedo> m_pUndoRedo;
     };
 
-CPPUNIT_TEST_SUITE_REGISTRATION(Test);
+    CPPUNIT_TEST_SUITE_REGISTRATION(PageDescManagerTest);
 
+}}
+
+using namespace ::sw::test;
+
+void PageDescManagerTest::Setup()
+{
+    m_pDoc.reset(new SwDoc());
+    m_pLayoutAccess.reset(new LayoutAccessMockBase());
+    m_pUndoRedo.reset(new UndoRedoMockBase());
+    m_pPageDescAccess.reset(PageDescManager::Create(m_pDoc.get(), m_pLayoutAccess.get(), m_pUndoRedo.get()));
+    CPPUNIT_ASSERT(m_pPageDescAccess.get()!=NULL);
+}
+
+void PageDescManagerTest::Create()
+{
+    Setup();
+}
+
+void PageDescManagerTest::MakePageDesc()
+{
+    Setup();
+    const String sName = String::CreateFromAscii("someinterestingname");
+    IDocumentPageDescAccess::difference_type nPrecount = m_pPageDescAccess->GetPageDescCnt();
+    const SwPageDesc* const pPageDesc(m_pPageDescAccess->MakePageDesc(sName));
+    CPPUNIT_ASSERT(pPageDesc!=NULL);
+    CPPUNIT_ASSERT(m_pPageDescAccess->GetPageDescCnt() == nPrecount+1);
+    CPPUNIT_ASSERT(sName == pPageDesc->GetName());
+}
+
+void PageDescManagerTest::MakePageDesc_Copy()
+{
+    Setup();
+    const String sName = String::CreateFromAscii("someinterestingname");
+    const String sName2 = String::CreateFromAscii("someinterestingname2");
+    SwPageDesc* const pPageDescTemplate(m_pPageDescAccess->MakePageDesc(sName));
+    pPageDescTemplate->SetPoolFmtId(0xdead);
+    pPageDescTemplate->SetPoolHelpId(0xdead);
+    pPageDescTemplate->SetPoolHlpFileId(0xde);
+    IDocumentPageDescAccess::difference_type nPrecount = m_pPageDescAccess->GetPageDescCnt();
+    const SwPageDesc* const pPageDesc(m_pPageDescAccess->MakePageDesc(sName2, pPageDescTemplate));
+    CPPUNIT_ASSERT(pPageDesc!=NULL);
+    CPPUNIT_ASSERT(m_pPageDescAccess->GetPageDescCnt() == nPrecount+1);
+    CPPUNIT_ASSERT(pPageDesc->GetName() == sName2);
+    CPPUNIT_ASSERT(pPageDesc->GetPoolFmtId() == USHRT_MAX);
+    CPPUNIT_ASSERT(pPageDesc->GetPoolHelpId() == USHRT_MAX);
+    CPPUNIT_ASSERT(pPageDesc->GetPoolHlpFileId() == UCHAR_MAX);
+    CPPUNIT_ASSERT(m_pPageDescAccess->GetPageDescByPoolFmtId(0xdead)==pPageDescTemplate);
+}
+
+void PageDescManagerTest::GetPageDescCnt()
+{
+    Setup();
+    IDocumentPageDescAccess::difference_type nCount = m_pPageDescAccess->GetPageDescCnt();
+    m_pPageDescAccess->MakePageDesc(String::CreateFromAscii("FOO1"));
+    CPPUNIT_ASSERT(++nCount == m_pPageDescAccess->GetPageDescCnt());
+    m_pPageDescAccess->MakePageDesc(String::CreateFromAscii("FOO2"));
+    CPPUNIT_ASSERT(++nCount == m_pPageDescAccess->GetPageDescCnt());
+    m_pPageDescAccess->MakePageDesc(String::CreateFromAscii("FOO3"));
+    CPPUNIT_ASSERT(++nCount == m_pPageDescAccess->GetPageDescCnt());
+    m_pPageDescAccess->MakePageDesc(String::CreateFromAscii("FOO4"));
+    CPPUNIT_ASSERT(++nCount == m_pPageDescAccess->GetPageDescCnt());
+    m_pPageDescAccess->DelPageDesc(String::CreateFromAscii("FOO4"));
+    CPPUNIT_ASSERT(--nCount == m_pPageDescAccess->GetPageDescCnt());
+    m_pPageDescAccess->DelPageDesc(String::CreateFromAscii("FOO3"));
+    CPPUNIT_ASSERT(--nCount == m_pPageDescAccess->GetPageDescCnt());
+    m_pPageDescAccess->DelPageDesc(String::CreateFromAscii("FOO2"));
+    CPPUNIT_ASSERT(--nCount == m_pPageDescAccess->GetPageDescCnt());
+}
+
+void PageDescManagerTest::GetPageDescByName()
+{
+    Setup();
+    const String sName = String::CreateFromAscii("someinterestingname");
+    const String sOtherName = String::CreateFromAscii("someotherinterestingname");
+    m_pPageDescAccess->MakePageDesc(sName);
+    CPPUNIT_ASSERT(m_pPageDescAccess->GetPageDescByName(sName)!=NULL);
+    CPPUNIT_ASSERT(m_pPageDescAccess->GetPageDescByName(sOtherName)==NULL);
+}
+
+void PageDescManagerTest::GetPageDescByPoolFmtId()
+{
+    Setup();
+    const USHORT nId = 0xdead;
+    const USHORT nOtherId = 0xbeef;
+    CPPUNIT_ASSERT(m_pPageDescAccess->GetPageDescByPoolFmtId(nId)==NULL);
+    SwPageDesc* pPageDesc(m_pPageDescAccess->MakePageDesc(String()));
+    pPageDesc->SetPoolFmtId(nId);
+    CPPUNIT_ASSERT(m_pPageDescAccess->GetPageDescByPoolFmtId(nId)==pPageDesc);
+    CPPUNIT_ASSERT(m_pPageDescAccess->GetPageDescByPoolFmtId(nOtherId)==NULL);
+}
+
+void PageDescManagerTest::GetDefaultPageDesc()
+{
+    Setup();
+    SwPageDesc* pPageDesc(m_pPageDescAccess->MakePageDesc(String()));
+    m_pPageDescAccess->MakePageDesc(String());
+    m_pPageDescAccess->MakePageDesc(String());
+    m_pPageDescAccess->MakePageDesc(String());
+    CPPUNIT_ASSERT(m_pPageDescAccess->GetDefaultPageDesc()==pPageDesc);
 }
 
 CPPUNIT_PLUGIN_IMPLEMENT();

sw/source/core/doc/PageDescManager.cxx

 #include <SwUndoPageDesc.hxx>
 #include <algorithm>
 #include <doc.hxx>
-#include <editeng/frmdiritem.hxx>
 #include <fmtcntnt.hxx>
-//#include <fmtfsize.hxx>
 #include <fmthdft.hxx>
 #include <pagedesc.hxx>
 #include <pagefrm.hxx>	//Fuer DelPageDesc
     }
     else
     {
-        pNew = shared_ptr<SwPageDesc>(new SwPageDesc(rName, m_pDoc->GetDfltFrmFmt(), m_pDoc));
-        //Default-Seitenformat einstellen.
-        pNew->ResetTotDefaultPageFormat();
-
-        SvxFrameDirection aFrameDirection = bRegardLanguage ?
-            GetDefaultFrameDirection(GetAppLanguage())
+        SvxFrameDirection aFrameDirection = bRegardLanguage
+            ?  GetDefaultFrameDirection(GetAppLanguage())
             : FRMDIR_HORI_LEFT_TOP;
-
-        pNew->GetMaster().SetFmtAttr(SvxFrameDirectionItem(aFrameDirection, RES_FRAMEDIR));
-        pNew->GetLeft().SetFmtAttr(SvxFrameDirectionItem(aFrameDirection, RES_FRAMEDIR));
+        pNew = shared_ptr<SwPageDesc>(new SwPageDesc(rName, m_pDoc, aFrameDirection));
     }
 
     m_vPageDescs.push_back(pNew);

sw/source/core/layout/pagedesc.cxx

 #include <rootfrm.hxx>
 #include <swtable.hxx>
 
-/*************************************************************************
-|*
-|*	SwPageDesc::SwPageDesc()
-|*
-|*	Ersterstellung		MA 25. Jan. 93
-|*	Letzte Aenderung	MA 16. Feb. 94
-|*
-|*************************************************************************/
+SwPageDesc::SwPageDesc(const String& rName, SwDoc* const pDc, SvxFrameDirection aFrameDirection) :
+	SwModify( 0 ),
+	aDescName( rName ),
+    aMaster( pDc->GetAttrPool(), rName, pDc->GetDfltFrmFmt() ),
+    aLeft( pDc->GetAttrPool(), rName, pDc->GetDfltFrmFmt() ),
+    aDepend( this, 0 ),
+    pFollow( this ),
+    nRegHeight( 0 ),
+	nRegAscent( 0 ),
+    eUse( (UseOnPage)(nsUseOnPage::PD_ALL | nsUseOnPage::PD_HEADERSHARE | nsUseOnPage::PD_FOOTERSHARE) ),
+    bLandscape( FALSE ),
+    aFtnInfo()
+{
+        ResetTotDefaultPageFormat();
+        GetMaster().SetFmtAttr(SvxFrameDirectionItem(aFrameDirection, RES_FRAMEDIR));
+        GetLeft().SetFmtAttr(SvxFrameDirectionItem(aFrameDirection, RES_FRAMEDIR));
+}
 
-
-
-SwPageDesc::SwPageDesc( const String& rName, SwFrmFmt *pFmt, SwDoc *pDc ) :
+SwPageDesc::SwPageDesc( const String& rName, SwFrmFmt* pFmt, SwDoc* const pDc ) :
 	SwModify( 0 ),
 	aDescName( rName ),
     aMaster( pDc->GetAttrPool(), rName, pFmt ),