[Libreoffice-commits] core.git: include/svx svx/CppunitTest_svx_gallery_test.mk svx/qa

Aditya (via logerrit) logerrit at kemper.freedesktop.org
Mon May 25 11:03:24 UTC 2020


 include/svx/gallery1.hxx             |    4 -
 svx/CppunitTest_svx_gallery_test.mk  |    5 +
 svx/qa/unit/gallery/test_gallery.cxx |  133 ++++++++++++++++++++++++++++++++++-
 3 files changed, 139 insertions(+), 3 deletions(-)

New commits:
commit 94181db5c3ed607042dd1b0ea029f54ac8238cf1
Author:     Aditya <adityasahu1511 at gmail.com>
AuthorDate: Thu May 14 23:54:59 2020 +0530
Commit:     Tomaž Vajngerl <quikee at gmail.com>
CommitDate: Mon May 25 13:02:48 2020 +0200

    svx:unit tests for theme count, gallery theme entry functions in gallery
    
    Change-Id: I7ff7f6f5607348e8ff135614d7de1957741a11fc
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/93305
    Tested-by: Tomaž Vajngerl <quikee at gmail.com>
    Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>

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();


More information about the Libreoffice-commits mailing list