summaryrefslogtreecommitdiff
path: root/sw/qa
diff options
context:
space:
mode:
authorBjoern Michaelsen <bjoern.michaelsen@canonical.com>2015-03-19 03:23:24 +0100
committerBjoern Michaelsen <bjoern.michaelsen@canonical.com>2015-03-20 02:25:04 +0100
commit87bc662386ffe53b8b4b1fa07deb0bb665fe39c9 (patch)
treeee31bbb675ce81f16b21371e063eebde25d33285 /sw/qa
parent6934ad423afd43d4d5c3788d0c020164309aaffa (diff)
add unittest
Change-Id: Iba119145155ee13067565b1f314c85b0e6a8de85
Diffstat (limited to 'sw/qa')
-rw-r--r--sw/qa/core/uwriter.cxx95
1 files changed, 95 insertions, 0 deletions
diff --git a/sw/qa/core/uwriter.cxx b/sw/qa/core/uwriter.cxx
index e0860c8f8eb6..edfa2417e539 100644
--- a/sw/qa/core/uwriter.cxx
+++ b/sw/qa/core/uwriter.cxx
@@ -60,6 +60,7 @@
#include "scriptinfo.hxx"
#include "IMark.hxx"
#include "ring.hxx"
+#include "calbck.hxx"
typedef tools::SvRef<SwDocShell> SwDocShellRef;
@@ -105,8 +106,10 @@ public:
void testTransliterate();
void testMarkMove();
void testIntrusiveRing();
+ void testClientModify();
CPPUNIT_TEST_SUITE(SwDocTest);
+
CPPUNIT_TEST(testTransliterate);
CPPUNIT_TEST(randomTest);
CPPUNIT_TEST(testPageDescName);
@@ -134,6 +137,7 @@ public:
CPPUNIT_TEST(testGraphicAnchorDeletion);
CPPUNIT_TEST(testMarkMove);
CPPUNIT_TEST(testIntrusiveRing);
+ CPPUNIT_TEST(testClientModify);
CPPUNIT_TEST_SUITE_END();
private:
@@ -1384,6 +1388,97 @@ void SwDocTest::testIntrusiveRing()
CPPUNIT_ASSERT_EQUAL(&foo, foo.GetPrev());
}
+namespace
+{
+ struct TestModify : SwModify
+ {
+ TYPEINFO();
+ };
+ TYPEINIT1( TestModify, SwModify );
+ struct TestClient : SwClient
+ {
+ TYPEINFO();
+ int m_nModifyCount;
+ TestClient() : m_nModifyCount(0) {};
+ virtual void Modify( const SfxPoolItem*, const SfxPoolItem*)
+ {
+ ShowReg();
+ ++m_nModifyCount;
+ }
+
+ void ShowReg()
+ {
+ if(GetRegisteredIn())
+ {
+ std::cout << "TestClient " << this << " registered in " << GetRegisteredIn() << std::endl;
+ }
+ else
+ std::cout << "TestClient " << this << " not registered " << std::endl;
+ }
+ };
+ TYPEINIT1( TestClient, SwClient );
+ struct OtherTestClient : SwClient
+ { TYPEINFO(); };
+ TYPEINIT1( OtherTestClient, SwClient );
+}
+void SwDocTest::testClientModify()
+{
+ TestModify aMod;
+ TestClient aClient1, aClient2;
+ aMod.Add(&aClient1);
+ aMod.Add(&aClient2);
+ CPPUNIT_ASSERT_EQUAL(aClient1.GetRegisteredIn(),static_cast<SwModify*>(&aMod));
+ CPPUNIT_ASSERT_EQUAL(aClient2.GetRegisteredIn(),static_cast<SwModify*>(&aMod));
+ aMod.ModifyBroadcast(nullptr, nullptr);
+ CPPUNIT_ASSERT_EQUAL(aClient1.m_nModifyCount,1);
+ CPPUNIT_ASSERT_EQUAL(aClient2.m_nModifyCount,1);
+ aMod.ModifyBroadcast(nullptr, nullptr);
+ CPPUNIT_ASSERT_EQUAL(aClient1.m_nModifyCount,2);
+ CPPUNIT_ASSERT_EQUAL(aClient2.m_nModifyCount,2);
+ CPPUNIT_ASSERT(!aClient1.IsA(TYPE(OtherTestClient)));
+ {
+ SwIterator<OtherTestClient,SwModify> aIter(aMod);
+ for(OtherTestClient* pClient = aIter.First(); pClient ; pClient = aIter.Next())
+ CPPUNIT_ASSERT(false);
+ }
+ {
+ int nCount = 0;
+ SwIterator<TestClient,SwModify> aIter(aMod);
+ for(TestClient* pClient = aIter.First(); pClient ; pClient = aIter.Next())
+ {
+ CPPUNIT_ASSERT_EQUAL(pClient->m_nModifyCount,2);
+ ++nCount;
+ }
+ CPPUNIT_ASSERT_EQUAL(nCount,2);
+ }
+ CPPUNIT_ASSERT_EQUAL(aClient1.GetRegisteredIn(),static_cast<SwModify*>(&aMod));
+ CPPUNIT_ASSERT_EQUAL(aClient2.GetRegisteredIn(),static_cast<SwModify*>(&aMod));
+ {
+ int nCount = 0;
+ SwIterator<TestClient,SwModify> aIter(aMod);
+ for(TestClient* pClient = aIter.First(); pClient ; pClient = aIter.Next())
+ {
+ aMod.Remove(pClient);
+ ++nCount;
+ }
+ CPPUNIT_ASSERT_EQUAL(nCount,2);
+ }
+ CPPUNIT_ASSERT_EQUAL(aClient1.GetRegisteredIn(), static_cast<SwModify*>(nullptr));
+ CPPUNIT_ASSERT_EQUAL(aClient2.GetRegisteredIn(), static_cast<SwModify*>(nullptr));
+ {
+ int nCount = 0;
+ SwIterator<TestClient,SwModify> aIter(aMod);
+ for(TestClient* pClient = aIter.First(); pClient ; pClient = aIter.Next())
+ {
+ CPPUNIT_ASSERT(false);
+ }
+ CPPUNIT_ASSERT_EQUAL(nCount,0);
+ }
+ aMod.ModifyBroadcast(nullptr, nullptr);
+ CPPUNIT_ASSERT_EQUAL(aClient1.m_nModifyCount,2);
+ CPPUNIT_ASSERT_EQUAL(aClient2.m_nModifyCount,2);
+}
+
void SwDocTest::setUp()
{
BootstrapFixture::setUp();