include/svx/gallery1.hxx             |    2 
 svx/CppunitTest_svx_gallery_test.mk  |   49 +++++++++
 svx/Module_svx.mk                    |    1 
 svx/qa/unit/gallery/test_gallery.cxx |  175 +++++++++++++++++++++++++++++++++++
 4 files changed, 226 insertions(+), 1 deletion(-)

New commits:
commit 3e8a93f5077e7ec5fbc47acdcdeaafaa15c5a7a9
Author:     Aditya <adityasahu1...@gmail.com>
AuthorDate: Wed Apr 22 14:33:49 2020 +0530
Commit:     Tomaž Vajngerl <qui...@gmail.com>
CommitDate: Thu Apr 30 19:03:51 2020 +0200

    svx:unit tests for gallery
    
    Tests for creation of renaming, deletion of gallery theme
    
    Change-Id: I2bfb602342f5d6b4ed45ff2f2fb9df7601e0e6b5
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/92679
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <qui...@gmail.com>

diff --git a/include/svx/gallery1.hxx b/include/svx/gallery1.hxx
index ca639cddf4ea..dc2631beb70e 100644
--- a/include/svx/gallery1.hxx
+++ b/include/svx/gallery1.hxx
@@ -121,7 +121,7 @@ public:
     SAL_DLLPRIVATE OUString     GetThemeName( sal_uInt32 nThemeId ) const;
 
     bool                        CreateTheme( const OUString& rThemeName );
-    SAL_DLLPRIVATE void         RenameTheme( const OUString& rOldName, const 
OUString& rNewName );
+    void                        RenameTheme( const OUString& rOldName, const 
OUString& rNewName );
     bool                        RemoveTheme( const OUString& rThemeName );
 
     GalleryTheme*               AcquireTheme( const OUString& rThemeName, 
SfxListener& rListener );
diff --git a/svx/CppunitTest_svx_gallery_test.mk 
b/svx/CppunitTest_svx_gallery_test.mk
new file mode 100644
index 000000000000..e13b75694627
--- /dev/null
+++ b/svx/CppunitTest_svx_gallery_test.mk
@@ -0,0 +1,49 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#*************************************************************************
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# 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/.
+#
+#*************************************************************************
+
+$(eval $(call gb_CppunitTest_CppunitScreenShot,svx_gallery_test))
+
+$(eval $(call gb_CppunitTest_add_exception_objects,svx_gallery_test, \
+    svx/qa/unit/gallery/test_gallery \
+))
+
+$(eval $(call gb_CppunitTest_set_include,svx_gallery_test,\
+    -I$(SRCDIR)/svx/source/inc \
+    -I$(SRCDIR)/svx/inc \
+    $$(INCLUDE) \
+))
+
+$(eval $(call gb_CppunitTest_use_libraries,svx_gallery_test, \
+       sal \
+       utl \
+       svxcore \
+       comphelper \
+))
+
+$(eval $(call gb_CppunitTest_use_vcl,svx_gallery_test))
+
+$(eval $(call gb_CppunitTest_use_sdk_api,svx_gallery_test))
+
+$(eval $(call gb_CppunitTest_use_configuration,svx_gallery_test))
+
+$(eval $(call gb_CppunitTest_use_rdb,svx_gallery_test,services))
+
+$(eval $(call gb_CppunitTest_use_ure,svx_gallery_test))
+
+
+
+
+
+
+
+
+
+# vim: set noet sw=4 ts=4:
diff --git a/svx/Module_svx.mk b/svx/Module_svx.mk
index 1d83bdc29d68..2040a906891f 100644
--- a/svx/Module_svx.mk
+++ b/svx/Module_svx.mk
@@ -32,6 +32,7 @@ $(eval $(call gb_Module_add_l10n_targets,svx,\
 
 $(eval $(call gb_Module_add_check_targets,svx,\
        CppunitTest_svx_unit \
+       CppunitTest_svx_gallery_test \
 ))
 
 # screenshots
diff --git a/svx/qa/unit/gallery/test_gallery.cxx 
b/svx/qa/unit/gallery/test_gallery.cxx
new file mode 100644
index 000000000000..c7ced2d58ee1
--- /dev/null
+++ b/svx/qa/unit/gallery/test_gallery.cxx
@@ -0,0 +1,175 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+* This file is part of the LibreOffice project.
+*
+* This Source Code Form is subject to the terms of the Mozilla Public
+* 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 <svx/gallery1.hxx>
+#include <unotools/tempfile.hxx>
+#include <comphelper/DirectoryHelper.hxx>
+
+#include <cppunit/TestAssert.h>
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/plugin/TestPlugIn.h>
+
+class GalleryObjTest : public CppUnit::TestFixture
+{
+public:
+    void TestCreateTheme();
+    void TestDeleteTheme();
+    void TestSetThemeName();
+    void TestThemeURLCase();
+
+    CPPUNIT_TEST_SUITE(GalleryObjTest);
+
+    CPPUNIT_TEST(TestCreateTheme);
+    CPPUNIT_TEST(TestDeleteTheme);
+    CPPUNIT_TEST(TestSetThemeName);
+    CPPUNIT_TEST(TestThemeURLCase);
+
+    CPPUNIT_TEST_SUITE_END();
+};
+
+// Create and Dereference a theme, check that file exists
+void GalleryObjTest::TestCreateTheme()
+{
+    // 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));
+
+    // check if files exist
+    CPPUNIT_ASSERT_MESSAGE(
+        "Could not find .thm file inside it",
+        comphelper::DirectoryHelper::fileExists(aGalleryURL + "/" + 
myThemeName + ".thm"));
+    CPPUNIT_ASSERT_MESSAGE(
+        "Could not find .sdv file inside it",
+        comphelper::DirectoryHelper::fileExists(aGalleryURL + "/" + 
myThemeName + ".sdv"));
+}
+
+//  Create and Delete Theme, check the file doesn't exist
+void GalleryObjTest::TestDeleteTheme()
+{
+    // 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();
+
+    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));
+
+    // 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));
+
+    // Check that files do not exist
+    CPPUNIT_ASSERT_MESSAGE(
+        "Found .thm file inside it after deletion",
+        !comphelper::DirectoryHelper::fileExists(aGalleryURL + "/" + 
myThemeName + ".thm"));
+    CPPUNIT_ASSERT_MESSAGE(
+        "Found .sdv file inside it after deletion",
+        !comphelper::DirectoryHelper::fileExists(aGalleryURL + "/" + 
myThemeName + ".sdv"));
+    CPPUNIT_ASSERT_MESSAGE(
+        "Found .sdg file inside it after deletion",
+        !comphelper::DirectoryHelper::fileExists(aGalleryURL + "/" + 
myThemeName + ".sdg"));
+    CPPUNIT_ASSERT_MESSAGE(
+        "Found .str file inside it after deletion",
+        !comphelper::DirectoryHelper::fileExists(aGalleryURL + "/" + 
myThemeName + ".str"));
+}
+
+// Create theme, set name, assert the name is expected
+void GalleryObjTest::TestSetThemeName()
+{
+    // 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();
+
+    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));
+
+    // Rename theme
+    const OUString myNewThemeName = "addytestthemenew";
+    pGallery->RenameTheme(myThemeName, myNewThemeName);
+    CPPUNIT_ASSERT_MESSAGE("Could not rename theme because old theme name 
still exists",
+                           !pGallery->HasTheme(myThemeName));
+    CPPUNIT_ASSERT_MESSAGE("Could not find new renamed theme", 
pGallery->HasTheme(myNewThemeName));
+
+    // Check that files are not renamed
+    CPPUNIT_ASSERT_MESSAGE(
+        "Could not find .thm file inside it",
+        comphelper::DirectoryHelper::fileExists(aGalleryURL + "/" + 
myThemeName + ".thm"));
+    CPPUNIT_ASSERT_MESSAGE(
+        "Could not find .sdv file inside it",
+        comphelper::DirectoryHelper::fileExists(aGalleryURL + "/" + 
myThemeName + ".sdv"));
+}
+
+void GalleryObjTest::TestThemeURLCase()
+{
+    // 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));
+
+    // Mixed Case Theme Name
+    const OUString myThemeName = "AddyTestTheme";
+
+    CPPUNIT_ASSERT_MESSAGE("Could not create theme", 
pGallery->CreateTheme(myThemeName));
+    CPPUNIT_ASSERT_MESSAGE("Could not find theme", 
pGallery->HasTheme(myThemeName));
+
+#if defined(LINUX)
+    CPPUNIT_ASSERT_MESSAGE("[LINUX] Could not find .thm in lowercase",
+                           comphelper::DirectoryHelper::fileExists(
+                               aGalleryURL + "/" + 
myThemeName.toAsciiLowerCase() + ".thm"));
+    CPPUNIT_ASSERT_MESSAGE("[LINUX] Could not find .sdv in lowercase",
+                           comphelper::DirectoryHelper::fileExists(
+                               aGalleryURL + "/" + 
myThemeName.toAsciiLowerCase() + ".sdv"));
+#else
+    CPPUNIT_ASSERT_MESSAGE(
+        "[WINDOWS] Could not find .thm in mixed case",
+        comphelper::DirectoryHelper::fileExists(aGalleryURL + "/" + 
myThemeName + ".thm"));
+    CPPUNIT_ASSERT_MESSAGE(
+        "[WINDOWS] Could not find .sdv in mixed case",
+        comphelper::DirectoryHelper::fileExists(aGalleryURL + "/" + 
myThemeName + ".sdv"));
+#endif
+}
+
+CPPUNIT_TEST_SUITE_REGISTRATION(GalleryObjTest);
+
+CPPUNIT_PLUGIN_IMPLEMENT();
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to