diff options
-rw-r--r-- | include/svx/gallery1.hxx | 4 | ||||
-rw-r--r-- | svx/CppunitTest_svx_gallery_test.mk | 5 | ||||
-rw-r--r-- | svx/qa/unit/gallery/test_gallery.cxx | 133 |
3 files changed, 139 insertions, 3 deletions
diff --git a/include/svx/gallery1.hxx b/include/svx/gallery1.hxx index dc2631beb70e..aa3e986f9e78 100644 --- a/include/svx/gallery1.hxx +++ b/include/svx/gallery1.hxx @@ -112,10 +112,10 @@ public: static Gallery* GetGalleryInstance(); - SAL_DLLPRIVATE size_t GetThemeCount() const { return aThemeList.size(); } + size_t GetThemeCount() const { return aThemeList.size(); } SAL_DLLPRIVATE const GalleryThemeEntry* GetThemeInfo( size_t nPos ) { return nPos < aThemeList.size() ? aThemeList[ nPos ].get() : nullptr; } - SAL_DLLPRIVATE const GalleryThemeEntry* GetThemeInfo( const OUString& rThemeName ) { return ImplGetThemeEntry( rThemeName ); } + const GalleryThemeEntry* GetThemeInfo( const OUString& rThemeName ) { return ImplGetThemeEntry( rThemeName ); } bool HasTheme( const OUString& rThemeName ); SAL_DLLPRIVATE OUString GetThemeName( sal_uInt32 nThemeId ) const; diff --git a/svx/CppunitTest_svx_gallery_test.mk b/svx/CppunitTest_svx_gallery_test.mk index e13b75694627..d4e50c51c127 100644 --- a/svx/CppunitTest_svx_gallery_test.mk +++ b/svx/CppunitTest_svx_gallery_test.mk @@ -26,8 +26,13 @@ $(eval $(call gb_CppunitTest_use_libraries,svx_gallery_test, \ utl \ svxcore \ comphelper \ + tl \ + svl \ + sfx \ )) +$(eval $(call gb_CppunitTest_use_externals,svx_gallery_test,boost_headers)) + $(eval $(call gb_CppunitTest_use_vcl,svx_gallery_test)) $(eval $(call gb_CppunitTest_use_sdk_api,svx_gallery_test)) diff --git a/svx/qa/unit/gallery/test_gallery.cxx b/svx/qa/unit/gallery/test_gallery.cxx index c7ced2d58ee1..4c95e461a52b 100644 --- a/svx/qa/unit/gallery/test_gallery.cxx +++ b/svx/qa/unit/gallery/test_gallery.cxx @@ -7,10 +7,15 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include <svx/gallery1.hxx> +#include <tools/urlobj.hxx> +#include <sfx2/app.hxx> #include <unotools/tempfile.hxx> #include <comphelper/DirectoryHelper.hxx> +#include <svx/gallery1.hxx> +#include <svx/galtheme.hxx> +#include <galobj.hxx> + #include <cppunit/TestAssert.h> #include <cppunit/TestFixture.h> #include <cppunit/extensions/HelperMacros.h> @@ -23,6 +28,9 @@ public: void TestDeleteTheme(); void TestSetThemeName(); void TestThemeURLCase(); + void TestThemeCount(); + void TestGalleryThemeEntry(); + void TestInsertGalleryObject(); CPPUNIT_TEST_SUITE(GalleryObjTest); @@ -30,6 +38,9 @@ public: CPPUNIT_TEST(TestDeleteTheme); CPPUNIT_TEST(TestSetThemeName); CPPUNIT_TEST(TestThemeURLCase); + CPPUNIT_TEST(TestThemeCount); + CPPUNIT_TEST(TestGalleryThemeEntry); + CPPUNIT_TEST(TestInsertGalleryObject); CPPUNIT_TEST_SUITE_END(); }; @@ -170,6 +181,126 @@ void GalleryObjTest::TestThemeURLCase() #endif } +void GalleryObjTest::TestThemeCount() +{ + std::unique_ptr<utl::TempFile> pTempDir; + pTempDir.reset(new utl::TempFile(nullptr, true)); + CPPUNIT_ASSERT_MESSAGE("Could not create valid temporary directory", pTempDir->IsValid()); + pTempDir->EnableKillingFile(); + const OUString aGalleryURL = pTempDir->GetURL(); + + // Check if directory exists + CPPUNIT_ASSERT_MESSAGE("Could not create temporary directory", + comphelper::DirectoryHelper::dirExists(aGalleryURL)); + + std::unique_ptr<Gallery> pGallery(new Gallery(aGalleryURL)); + CPPUNIT_ASSERT_MESSAGE("Could not create gallery instance", (pGallery != nullptr)); + + // Loop through and test theme count in each pass. + sal_uInt32 nLimit = 10; + for (sal_uInt32 i = 1; i <= nLimit; i++) + { + OUString myThemeName = "addytesttheme" + OUString::number(i); + // Create theme + CPPUNIT_ASSERT_MESSAGE("Could not create theme", pGallery->CreateTheme(myThemeName)); + CPPUNIT_ASSERT_MESSAGE("Could not find theme", pGallery->HasTheme(myThemeName)); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Inconsistent theme count", + static_cast<sal_uInt32>(pGallery->GetThemeCount()), i); + } + CPPUNIT_ASSERT_EQUAL_MESSAGE("Inconsistent theme count", + static_cast<sal_uInt32>(pGallery->GetThemeCount()), nLimit); + for (sal_uInt32 i = nLimit; i > 0; i--) + { + OUString myThemeName = "addytesttheme" + OUString::number(i); + // Delete Theme + CPPUNIT_ASSERT_MESSAGE("Could not remove theme", pGallery->RemoveTheme(myThemeName)); + CPPUNIT_ASSERT_MESSAGE("Could not remove theme, theme found even after trying to remove", + !pGallery->HasTheme(myThemeName)); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Inconsistent theme count", + static_cast<sal_uInt32>(pGallery->GetThemeCount()), i - 1); + } +} + +void GalleryObjTest::TestGalleryThemeEntry() +{ + // Create theme + std::unique_ptr<utl::TempFile> pTempDir; + pTempDir.reset(new utl::TempFile(nullptr, true)); + CPPUNIT_ASSERT_MESSAGE("Could not create valid temporary directory", pTempDir->IsValid()); + pTempDir->EnableKillingFile(); + const OUString aGalleryURL = pTempDir->GetURL(); + + // Check if directory exists + CPPUNIT_ASSERT_MESSAGE("Could not create temporary directory", + comphelper::DirectoryHelper::dirExists(aGalleryURL)); + + std::unique_ptr<Gallery> pGallery(new Gallery(aGalleryURL)); + CPPUNIT_ASSERT_MESSAGE("Could not create gallery instance", (pGallery != nullptr)); + const OUString myThemeName = "addytesttheme"; + CPPUNIT_ASSERT_MESSAGE("Could not create theme", pGallery->CreateTheme(myThemeName)); + CPPUNIT_ASSERT_MESSAGE("Could not find theme", pGallery->HasTheme(myThemeName)); + + // Get Theme Entry Object + const GalleryThemeEntry* mpThemeEntry = pGallery->GetThemeInfo(myThemeName); + + // Check Theme Name + CPPUNIT_ASSERT_EQUAL_MESSAGE("Theme name doesn't match", mpThemeEntry->GetThemeName(), + myThemeName); + + // Check URLs + INetURLObject aURL(aGalleryURL); + aURL.Append(myThemeName); + INetURLObject aThemeURL(aURL), aSdvURL(aURL), aSdgURL(aURL), aStrURL(aURL); + aThemeURL.setExtension("thm"); + aSdvURL.setExtension("sdv"); + aSdgURL.setExtension("sdg"); + aStrURL.setExtension("str"); + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "Theme URL doesn't match", + mpThemeEntry->GetThmURL().GetMainURL(INetURLObject::DecodeMechanism::Unambiguous), + aThemeURL.GetMainURL(INetURLObject::DecodeMechanism::Unambiguous)); + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "Sdv URL doesn't match", + mpThemeEntry->GetSdvURL().GetMainURL(INetURLObject::DecodeMechanism::Unambiguous), + aSdvURL.GetMainURL(INetURLObject::DecodeMechanism::Unambiguous)); + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "Sdg URL doesn't match", + mpThemeEntry->GetSdgURL().GetMainURL(INetURLObject::DecodeMechanism::Unambiguous), + aSdgURL.GetMainURL(INetURLObject::DecodeMechanism::Unambiguous)); + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "Str URL doesn't match", + mpThemeEntry->GetStrURL().GetMainURL(INetURLObject::DecodeMechanism::Unambiguous), + aStrURL.GetMainURL(INetURLObject::DecodeMechanism::Unambiguous)); +} + +void GalleryObjTest::TestInsertGalleryObject() +{ + // Create theme + std::unique_ptr<utl::TempFile> pTempDir; + pTempDir.reset(new utl::TempFile(nullptr, true)); + CPPUNIT_ASSERT_MESSAGE("Could not create valid temporary directory", pTempDir->IsValid()); + pTempDir->EnableKillingFile(); + const OUString aGalleryURL = pTempDir->GetURL(); + + // Check if directory exists + CPPUNIT_ASSERT_MESSAGE("Could not create temporary directory", + comphelper::DirectoryHelper::dirExists(aGalleryURL)); + + std::unique_ptr<Gallery> pGallery(new Gallery(aGalleryURL)); + CPPUNIT_ASSERT_MESSAGE("Could not create gallery instance", (pGallery != nullptr)); + const OUString myThemeName = "addytesttheme"; + CPPUNIT_ASSERT_MESSAGE("Could not create theme", pGallery->CreateTheme(myThemeName)); + CPPUNIT_ASSERT_MESSAGE("Could not find theme", pGallery->HasTheme(myThemeName)); + + // Insert Objects Into Theme + SfxListener aListener; + SfxApplication::GetOrCreate(); + GalleryTheme* pGalleryTheme = pGallery->AcquireTheme(myThemeName, aListener); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt32>(0), pGalleryTheme->GetObjectCount()); + + pGallery->ReleaseTheme(pGalleryTheme, aListener); +} + CPPUNIT_TEST_SUITE_REGISTRATION(GalleryObjTest); CPPUNIT_PLUGIN_IMPLEMENT(); |