summaryrefslogtreecommitdiff
path: root/svx
diff options
context:
space:
mode:
authorAditya <adityasahu1511@gmail.com>2020-05-14 23:54:59 +0530
committerTomaž Vajngerl <quikee@gmail.com>2020-05-25 13:02:48 +0200
commit94181db5c3ed607042dd1b0ea029f54ac8238cf1 (patch)
tree94b99613d76d1a1c76e02c151e196d4efab3155c /svx
parent88bd1509bf12e668a3a4107af42e8918171a7690 (diff)
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@gmail.com> Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'svx')
-rw-r--r--svx/CppunitTest_svx_gallery_test.mk5
-rw-r--r--svx/qa/unit/gallery/test_gallery.cxx133
2 files changed, 137 insertions, 1 deletions
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();