include/svx/galtheme.hxx | 2 svx/CppunitTest_svx_gallery_test.mk | 2 svx/qa/unit/gallery/data/galtest1.png |binary svx/qa/unit/gallery/data/galtest2.png |binary svx/qa/unit/gallery/data/galtest3.jpg |binary svx/qa/unit/gallery/test_gallery.cxx | 177 +++++++++++++++++++++++++++++++++- 6 files changed, 178 insertions(+), 3 deletions(-)
New commits: commit 75eeb423196c1e94a0189b7eccff37aed5765853 Author: Aditya <adityasahu1...@gmail.com> AuthorDate: Thu May 21 21:51:23 2020 +0530 Commit: Tomaž Vajngerl <qui...@gmail.com> CommitDate: Mon Jun 1 22:30:47 2020 +0200 svx:unit tests for adding, acquiring, counting objects into gallery theme Change-Id: I256c6658a4257bc5bf8793153021efccef47bad2 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/94646 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <qui...@gmail.com> diff --git a/include/svx/galtheme.hxx b/include/svx/galtheme.hxx index 44f85f19c6eb..c7c248d22344 100644 --- a/include/svx/galtheme.hxx +++ b/include/svx/galtheme.hxx @@ -126,7 +126,7 @@ public: bool InsertObject(const SgaObject& rObj, sal_uInt32 nPos = SAL_MAX_UINT32); void RemoveObject(sal_uInt32 nPos); - SAL_DLLPRIVATE bool ChangeObjectPos(sal_uInt32 nOldPos, sal_uInt32 nNewPos); + bool ChangeObjectPos(sal_uInt32 nOldPos, sal_uInt32 nNewPos); const OUString& GetName() const; diff --git a/svx/CppunitTest_svx_gallery_test.mk b/svx/CppunitTest_svx_gallery_test.mk index d4e50c51c127..1415dce921a5 100644 --- a/svx/CppunitTest_svx_gallery_test.mk +++ b/svx/CppunitTest_svx_gallery_test.mk @@ -29,6 +29,8 @@ $(eval $(call gb_CppunitTest_use_libraries,svx_gallery_test, \ tl \ svl \ sfx \ + unotest \ + test \ )) $(eval $(call gb_CppunitTest_use_externals,svx_gallery_test,boost_headers)) diff --git a/svx/qa/unit/gallery/data/galtest1.png b/svx/qa/unit/gallery/data/galtest1.png new file mode 100755 index 000000000000..37be81f9d203 Binary files /dev/null and b/svx/qa/unit/gallery/data/galtest1.png differ diff --git a/svx/qa/unit/gallery/data/galtest2.png b/svx/qa/unit/gallery/data/galtest2.png new file mode 100755 index 000000000000..bf1aac397a39 Binary files /dev/null and b/svx/qa/unit/gallery/data/galtest2.png differ diff --git a/svx/qa/unit/gallery/data/galtest3.jpg b/svx/qa/unit/gallery/data/galtest3.jpg new file mode 100755 index 000000000000..59f67e9aaf98 Binary files /dev/null and b/svx/qa/unit/gallery/data/galtest3.jpg differ diff --git a/svx/qa/unit/gallery/test_gallery.cxx b/svx/qa/unit/gallery/test_gallery.cxx index 4c95e461a52b..c423f900cd64 100644 --- a/svx/qa/unit/gallery/test_gallery.cxx +++ b/svx/qa/unit/gallery/test_gallery.cxx @@ -6,6 +6,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#include <test/bootstrapfixture.hxx> #include <tools/urlobj.hxx> #include <sfx2/app.hxx> @@ -21,7 +22,7 @@ #include <cppunit/extensions/HelperMacros.h> #include <cppunit/plugin/TestPlugIn.h> -class GalleryObjTest : public CppUnit::TestFixture +class GalleryObjTest : public test::BootstrapFixture { public: void TestCreateTheme(); @@ -31,6 +32,9 @@ public: void TestThemeCount(); void TestGalleryThemeEntry(); void TestInsertGalleryObject(); + void TestRemoveGalleryObject(); + void TestChangePositionGalleryObject(); + void TestGetThemeNameFromGalleryTheme(); CPPUNIT_TEST_SUITE(GalleryObjTest); @@ -41,6 +45,9 @@ public: CPPUNIT_TEST(TestThemeCount); CPPUNIT_TEST(TestGalleryThemeEntry); CPPUNIT_TEST(TestInsertGalleryObject); + CPPUNIT_TEST(TestRemoveGalleryObject); + CPPUNIT_TEST(TestChangePositionGalleryObject); + CPPUNIT_TEST(TestGetThemeNameFromGalleryTheme); CPPUNIT_TEST_SUITE_END(); }; @@ -292,11 +299,177 @@ void GalleryObjTest::TestInsertGalleryObject() CPPUNIT_ASSERT_MESSAGE("Could not create theme", pGallery->CreateTheme(myThemeName)); CPPUNIT_ASSERT_MESSAGE("Could not find theme", pGallery->HasTheme(myThemeName)); + // Create Sfx Instance + SfxListener aListener; + SfxApplication::GetOrCreate(); + // Insert Objects Into Theme + GalleryTheme* pGalleryTheme = pGallery->AcquireTheme(myThemeName, aListener); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Object count inconsistent", sal_uInt32(0), + pGalleryTheme->GetObjectCount()); + + std::vector<OUString> imageList{ "galtest1.png", "galtest2.png", "galtest3.jpg" }; + + for (sal_uInt32 i = 0; i < static_cast<sal_uInt32>(imageList.size()); i++) + { + OUString imageNameFromList(imageList[i]); + OUString aURL(m_directories.getURLFromSrc("/svx/qa/unit/gallery/data/") + + imageNameFromList); + CPPUNIT_ASSERT_MESSAGE("Could not insert object into theme", + pGalleryTheme->InsertURL(INetURLObject(aURL))); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Inconsistent object Count", pGalleryTheme->GetObjectCount(), + i + 1); + std::unique_ptr<SgaObject> pObj = pGalleryTheme->AcquireObject(i); + CPPUNIT_ASSERT_MESSAGE("Acquired Object Invalid", pObj->IsValid()); + } + pGallery->ReleaseTheme(pGalleryTheme, aListener); +} + +void GalleryObjTest::TestRemoveGalleryObject() +{ + // 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)); + + // Create Sfx Instance SfxListener aListener; SfxApplication::GetOrCreate(); + + // Insert Objects Into Theme GalleryTheme* pGalleryTheme = pGallery->AcquireTheme(myThemeName, aListener); - CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt32>(0), pGalleryTheme->GetObjectCount()); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Object count inconsistent", sal_uInt32(0), + pGalleryTheme->GetObjectCount()); + + std::vector<OUString> imageList{ "galtest1.png", "galtest2.png", "galtest3.jpg" }; + + for (sal_uInt32 i = 0; i < static_cast<sal_uInt32>(imageList.size()); i++) + { + OUString imageNameFromList(imageList[i]); + OUString aURL(m_directories.getURLFromSrc("/svx/qa/unit/gallery/data/") + + imageNameFromList); + CPPUNIT_ASSERT_MESSAGE("Could not insert object into theme", + pGalleryTheme->InsertURL(INetURLObject(aURL))); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Inconsistent object Count", pGalleryTheme->GetObjectCount(), + i + 1); + std::unique_ptr<SgaObject> pObj = pGalleryTheme->AcquireObject(i); + CPPUNIT_ASSERT_MESSAGE("Acquired Object Invalid", pObj->IsValid()); + } + + for (sal_uInt32 i = static_cast<sal_uInt32>(imageList.size()); i > 0; i--) + { + std::unique_ptr<SgaObject> pObj = pGalleryTheme->AcquireObject(i - 1); + CPPUNIT_ASSERT_MESSAGE("Acquired Object Invalid", pObj->IsValid()); + pGalleryTheme->RemoveObject(i - 1); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Inconsistent object Count", pGalleryTheme->GetObjectCount(), + i - 1); + } + + pGallery->ReleaseTheme(pGalleryTheme, aListener); +} + +void GalleryObjTest::TestChangePositionGalleryObject() +{ + // 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)); + + // Create Sfx Instance + SfxListener aListener; + SfxApplication::GetOrCreate(); + + // Insert Objects Into Theme + GalleryTheme* pGalleryTheme = pGallery->AcquireTheme(myThemeName, aListener); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Object count inconsistent", sal_uInt32(0), + pGalleryTheme->GetObjectCount()); + + OUString imageList[] = { "galtest1.png", "galtest2.png", "galtest3.jpg" }; + + for (sal_uInt32 i = 0; i < (sizeof(imageList) / sizeof(imageList[0])); i++) + { + OUString imageNameFromList(imageList[i]); + OUString aURL(m_directories.getURLFromSrc("/svx/qa/unit/gallery/data/") + + imageNameFromList); + CPPUNIT_ASSERT_MESSAGE("Could not insert object into theme", + pGalleryTheme->InsertURL(INetURLObject(aURL))); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Inconsistent object Count", pGalleryTheme->GetObjectCount(), + i + 1); + std::unique_ptr<SgaObject> pObj = pGalleryTheme->AcquireObject(i); + CPPUNIT_ASSERT_MESSAGE("Acquired Object Invalid", pObj->IsValid()); + } + + CPPUNIT_ASSERT(pGalleryTheme->ChangeObjectPos(1, 3)); + std::unique_ptr<SgaObject> pObj = pGalleryTheme->AcquireObject(0); + INetURLObject aURL = pObj->GetURL(); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Failure to change object position", imageList[0], + aURL.GetLastName()); + + pObj = pGalleryTheme->AcquireObject(1); + aURL = pObj->GetURL(); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Failure to change object position", imageList[2], + aURL.GetLastName()); + + pObj = pGalleryTheme->AcquireObject(2); + aURL = pObj->GetURL(); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Failure to change object position", imageList[1], + aURL.GetLastName()); + + pGallery->ReleaseTheme(pGalleryTheme, aListener); +} + +void GalleryObjTest::TestGetThemeNameFromGalleryTheme() +{ + // 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)); + + // Create Sfx Instance + SfxListener aListener; + SfxApplication::GetOrCreate(); + + GalleryTheme* pGalleryTheme = pGallery->AcquireTheme(myThemeName, aListener); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Object count inconsistent", sal_uInt32(0), + pGalleryTheme->GetObjectCount()); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("Theme name not matching", myThemeName, pGalleryTheme->GetName()); pGallery->ReleaseTheme(pGalleryTheme, aListener); } _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits