1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
9 #include <test/bootstrapfixture.hxx>
10 
11 #include <tools/urlobj.hxx>
12 #include <sfx2/app.hxx>
13 #include <unotools/tempfile.hxx>
14 #include <comphelper/DirectoryHelper.hxx>
15 
16 #include <svx/gallery1.hxx>
17 #include <svx/galtheme.hxx>
18 #include <svx/gallerybinarystoragelocations.hxx>
19 #include <svx/gallerystoragelocations.hxx>
20 #include <galobj.hxx>
21 
22 #include <cppunit/TestAssert.h>
23 #include <cppunit/extensions/HelperMacros.h>
24 #include <cppunit/plugin/TestPlugIn.h>
25 
26 class GalleryObjTest : public test::BootstrapFixture
27 {
28 public:
29     void TestCreateTheme();
30     void TestDeleteTheme();
31     void TestSetThemeName();
32     void TestThemeURLCase();
33     void TestThemeCount();
34     void TestGalleryThemeEntry();
35     void TestInsertGalleryObject();
36     void TestRemoveGalleryObject();
37     void TestChangePositionGalleryObject();
38     void TestGetThemeNameFromGalleryTheme();
39 
40     CPPUNIT_TEST_SUITE(GalleryObjTest);
41 
42     CPPUNIT_TEST(TestCreateTheme);
43     CPPUNIT_TEST(TestDeleteTheme);
44     CPPUNIT_TEST(TestSetThemeName);
45     CPPUNIT_TEST(TestThemeURLCase);
46     CPPUNIT_TEST(TestThemeCount);
47     CPPUNIT_TEST(TestGalleryThemeEntry);
48     CPPUNIT_TEST(TestInsertGalleryObject);
49     CPPUNIT_TEST(TestRemoveGalleryObject);
50     CPPUNIT_TEST(TestChangePositionGalleryObject);
51     CPPUNIT_TEST(TestGetThemeNameFromGalleryTheme);
52 
53     CPPUNIT_TEST_SUITE_END();
54 };
55 
56 // Create and Dereference a theme, check that file exists
TestCreateTheme()57 void GalleryObjTest::TestCreateTheme()
58 {
59     // Create theme
60     std::unique_ptr<utl::TempFile> pTempDir;
61     pTempDir.reset(new utl::TempFile(nullptr, true));
62     CPPUNIT_ASSERT_MESSAGE("Could not create valid temporary directory", pTempDir->IsValid());
63     pTempDir->EnableKillingFile();
64     const OUString aGalleryURL = pTempDir->GetURL();
65 
66     // Check if directory exists
67     CPPUNIT_ASSERT_MESSAGE("Could not create temporary directory",
68                            comphelper::DirectoryHelper::dirExists(aGalleryURL));
69 
70     std::unique_ptr<Gallery> pGallery(new Gallery(aGalleryURL));
71     CPPUNIT_ASSERT_MESSAGE("Could not create gallery instance", (pGallery != nullptr));
72     static const OUStringLiteral myThemeName = u"addytesttheme";
73     CPPUNIT_ASSERT_MESSAGE("Could not create theme", pGallery->CreateTheme(myThemeName));
74     CPPUNIT_ASSERT_MESSAGE("Could not find theme", pGallery->HasTheme(myThemeName));
75 
76     // check if files exist
77     CPPUNIT_ASSERT_MESSAGE(
78         "Could not find .thm file inside it",
79         comphelper::DirectoryHelper::fileExists(aGalleryURL + "/" + myThemeName + ".thm"));
80     CPPUNIT_ASSERT_MESSAGE(
81         "Could not find .sdv file inside it",
82         comphelper::DirectoryHelper::fileExists(aGalleryURL + "/" + myThemeName + ".sdv"));
83 }
84 
85 //  Create and Delete Theme, check the file doesn't exist
TestDeleteTheme()86 void GalleryObjTest::TestDeleteTheme()
87 {
88     // Create theme
89     std::unique_ptr<utl::TempFile> pTempDir;
90     pTempDir.reset(new utl::TempFile(nullptr, true));
91     CPPUNIT_ASSERT_MESSAGE("Could not create valid temporary directory", pTempDir->IsValid());
92     pTempDir->EnableKillingFile();
93     const OUString aGalleryURL = pTempDir->GetURL();
94 
95     std::unique_ptr<Gallery> pGallery(new Gallery(aGalleryURL));
96     CPPUNIT_ASSERT_MESSAGE("Could not create gallery instance", (pGallery != nullptr));
97     static const OUStringLiteral myThemeName = u"addytesttheme";
98     CPPUNIT_ASSERT_MESSAGE("Could not create theme", pGallery->CreateTheme(myThemeName));
99     CPPUNIT_ASSERT_MESSAGE("Could not find theme", pGallery->HasTheme(myThemeName));
100 
101     // Delete Theme
102     CPPUNIT_ASSERT_MESSAGE("Could not remove theme", pGallery->RemoveTheme(myThemeName));
103     CPPUNIT_ASSERT_MESSAGE("Could not remove theme, theme found even after trying to remove",
104                            !pGallery->HasTheme(myThemeName));
105 
106     // Check that files do not exist
107     CPPUNIT_ASSERT_MESSAGE(
108         "Found .thm file inside it after deletion",
109         !comphelper::DirectoryHelper::fileExists(aGalleryURL + "/" + myThemeName + ".thm"));
110     CPPUNIT_ASSERT_MESSAGE(
111         "Found .sdv file inside it after deletion",
112         !comphelper::DirectoryHelper::fileExists(aGalleryURL + "/" + myThemeName + ".sdv"));
113     CPPUNIT_ASSERT_MESSAGE(
114         "Found .sdg file inside it after deletion",
115         !comphelper::DirectoryHelper::fileExists(aGalleryURL + "/" + myThemeName + ".sdg"));
116     CPPUNIT_ASSERT_MESSAGE(
117         "Found .str file inside it after deletion",
118         !comphelper::DirectoryHelper::fileExists(aGalleryURL + "/" + myThemeName + ".str"));
119 }
120 
121 // Create theme, set name, assert the name is expected
TestSetThemeName()122 void GalleryObjTest::TestSetThemeName()
123 {
124     // Create theme
125     std::unique_ptr<utl::TempFile> pTempDir;
126     pTempDir.reset(new utl::TempFile(nullptr, true));
127     CPPUNIT_ASSERT_MESSAGE("Could not create valid temporary directory", pTempDir->IsValid());
128     pTempDir->EnableKillingFile();
129     const OUString aGalleryURL = pTempDir->GetURL();
130 
131     std::unique_ptr<Gallery> pGallery(new Gallery(aGalleryURL));
132     CPPUNIT_ASSERT_MESSAGE("Could not create gallery instance", (pGallery != nullptr));
133     static const OUStringLiteral myThemeName = u"addytesttheme";
134     CPPUNIT_ASSERT_MESSAGE("Could not create theme", pGallery->CreateTheme(myThemeName));
135     CPPUNIT_ASSERT_MESSAGE("Could not find theme", pGallery->HasTheme(myThemeName));
136 
137     // Rename theme
138     static const OUStringLiteral myNewThemeName = u"addytestthemenew";
139     pGallery->RenameTheme(myThemeName, myNewThemeName);
140     CPPUNIT_ASSERT_MESSAGE("Could not rename theme because old theme name still exists",
141                            !pGallery->HasTheme(myThemeName));
142     CPPUNIT_ASSERT_MESSAGE("Could not find new renamed theme", pGallery->HasTheme(myNewThemeName));
143 
144     // Check that files are not renamed
145     CPPUNIT_ASSERT_MESSAGE(
146         "Could not find .thm file inside it",
147         comphelper::DirectoryHelper::fileExists(aGalleryURL + "/" + myThemeName + ".thm"));
148     CPPUNIT_ASSERT_MESSAGE(
149         "Could not find .sdv file inside it",
150         comphelper::DirectoryHelper::fileExists(aGalleryURL + "/" + myThemeName + ".sdv"));
151 }
152 
TestThemeURLCase()153 void GalleryObjTest::TestThemeURLCase()
154 {
155     // Create theme
156     std::unique_ptr<utl::TempFile> pTempDir;
157     pTempDir.reset(new utl::TempFile(nullptr, true));
158     CPPUNIT_ASSERT_MESSAGE("Could not create valid temporary directory", pTempDir->IsValid());
159     pTempDir->EnableKillingFile();
160     const OUString aGalleryURL = pTempDir->GetURL();
161 
162     // Check if directory exists
163     CPPUNIT_ASSERT_MESSAGE("Could not create temporary directory",
164                            comphelper::DirectoryHelper::dirExists(aGalleryURL));
165 
166     std::unique_ptr<Gallery> pGallery(new Gallery(aGalleryURL));
167     CPPUNIT_ASSERT_MESSAGE("Could not create gallery instance", (pGallery != nullptr));
168 
169     // Mixed Case Theme Name
170     const OUString myThemeName = "AddyTestTheme";
171 
172     CPPUNIT_ASSERT_MESSAGE("Could not create theme", pGallery->CreateTheme(myThemeName));
173     CPPUNIT_ASSERT_MESSAGE("Could not find theme", pGallery->HasTheme(myThemeName));
174 
175 #if defined(LINUX)
176     CPPUNIT_ASSERT_MESSAGE("[LINUX] Could not find .thm in lowercase",
177                            comphelper::DirectoryHelper::fileExists(
178                                aGalleryURL + "/" + myThemeName.toAsciiLowerCase() + ".thm"));
179     CPPUNIT_ASSERT_MESSAGE("[LINUX] Could not find .sdv in lowercase",
180                            comphelper::DirectoryHelper::fileExists(
181                                aGalleryURL + "/" + myThemeName.toAsciiLowerCase() + ".sdv"));
182 #else
183     CPPUNIT_ASSERT_MESSAGE(
184         "[WINDOWS] Could not find .thm in mixed case",
185         comphelper::DirectoryHelper::fileExists(aGalleryURL + "/" + myThemeName + ".thm"));
186     CPPUNIT_ASSERT_MESSAGE(
187         "[WINDOWS] Could not find .sdv in mixed case",
188         comphelper::DirectoryHelper::fileExists(aGalleryURL + "/" + myThemeName + ".sdv"));
189 #endif
190 }
191 
TestThemeCount()192 void GalleryObjTest::TestThemeCount()
193 {
194     std::unique_ptr<utl::TempFile> pTempDir;
195     pTempDir.reset(new utl::TempFile(nullptr, true));
196     CPPUNIT_ASSERT_MESSAGE("Could not create valid temporary directory", pTempDir->IsValid());
197     pTempDir->EnableKillingFile();
198     const OUString aGalleryURL = pTempDir->GetURL();
199 
200     // Check if directory exists
201     CPPUNIT_ASSERT_MESSAGE("Could not create temporary directory",
202                            comphelper::DirectoryHelper::dirExists(aGalleryURL));
203 
204     std::unique_ptr<Gallery> pGallery(new Gallery(aGalleryURL));
205     CPPUNIT_ASSERT_MESSAGE("Could not create gallery instance", (pGallery != nullptr));
206 
207     // Loop through and test theme count in each pass.
208     sal_uInt32 nLimit = 10;
209     for (sal_uInt32 i = 1; i <= nLimit; i++)
210     {
211         OUString myThemeName = "addytesttheme" + OUString::number(i);
212         // Create theme
213         CPPUNIT_ASSERT_MESSAGE("Could not create theme", pGallery->CreateTheme(myThemeName));
214         CPPUNIT_ASSERT_MESSAGE("Could not find theme", pGallery->HasTheme(myThemeName));
215         CPPUNIT_ASSERT_EQUAL_MESSAGE("Inconsistent theme count",
216                                      static_cast<sal_uInt32>(pGallery->GetThemeCount()), i);
217     }
218     CPPUNIT_ASSERT_EQUAL_MESSAGE("Inconsistent theme count",
219                                  static_cast<sal_uInt32>(pGallery->GetThemeCount()), nLimit);
220     for (sal_uInt32 i = nLimit; i > 0; i--)
221     {
222         OUString myThemeName = "addytesttheme" + OUString::number(i);
223         // Delete Theme
224         CPPUNIT_ASSERT_MESSAGE("Could not remove theme", pGallery->RemoveTheme(myThemeName));
225         CPPUNIT_ASSERT_MESSAGE("Could not remove theme, theme found even after trying to remove",
226                                !pGallery->HasTheme(myThemeName));
227         CPPUNIT_ASSERT_EQUAL_MESSAGE("Inconsistent theme count",
228                                      static_cast<sal_uInt32>(pGallery->GetThemeCount()), i - 1);
229     }
230 }
231 
TestGalleryThemeEntry()232 void GalleryObjTest::TestGalleryThemeEntry()
233 {
234     // Create theme
235     std::unique_ptr<utl::TempFile> pTempDir;
236     pTempDir.reset(new utl::TempFile(nullptr, true));
237     CPPUNIT_ASSERT_MESSAGE("Could not create valid temporary directory", pTempDir->IsValid());
238     pTempDir->EnableKillingFile();
239     const OUString aGalleryURL = pTempDir->GetURL();
240 
241     // Check if directory exists
242     CPPUNIT_ASSERT_MESSAGE("Could not create temporary directory",
243                            comphelper::DirectoryHelper::dirExists(aGalleryURL));
244 
245     std::unique_ptr<Gallery> pGallery(new Gallery(aGalleryURL));
246     CPPUNIT_ASSERT_MESSAGE("Could not create gallery instance", (pGallery != nullptr));
247     const OUString myThemeName = "addytesttheme";
248     CPPUNIT_ASSERT_MESSAGE("Could not create theme", pGallery->CreateTheme(myThemeName));
249     CPPUNIT_ASSERT_MESSAGE("Could not find theme", pGallery->HasTheme(myThemeName));
250 
251     // Get Theme Entry Object
252     const GalleryThemeEntry* mpThemeEntry = pGallery->GetThemeInfo(myThemeName);
253 
254     // Check Theme Name
255     CPPUNIT_ASSERT_EQUAL_MESSAGE("Theme name doesn't match", mpThemeEntry->GetThemeName(),
256                                  myThemeName);
257 
258     // Check URLs
259     GalleryBinaryStorageLocations& aGalleryBinaryStorageLocations
260         = dynamic_cast<GalleryBinaryStorageLocations&>(mpThemeEntry->getGalleryStorageLocations());
261     INetURLObject aURL(aGalleryURL);
262     aURL.Append(myThemeName);
263     INetURLObject aThemeURL(aURL), aSdvURL(aURL), aSdgURL(aURL), aStrURL(aURL);
264     aThemeURL.setExtension(u"thm");
265     aSdvURL.setExtension(u"sdv");
266     aSdgURL.setExtension(u"sdg");
267     aStrURL.setExtension(u"str");
268     CPPUNIT_ASSERT_EQUAL_MESSAGE("Theme URL doesn't match",
269                                  aGalleryBinaryStorageLocations.GetThmURL().GetMainURL(
270                                      INetURLObject::DecodeMechanism::Unambiguous),
271                                  aThemeURL.GetMainURL(INetURLObject::DecodeMechanism::Unambiguous));
272     CPPUNIT_ASSERT_EQUAL_MESSAGE("Sdv URL doesn't match",
273                                  aGalleryBinaryStorageLocations.GetSdvURL().GetMainURL(
274                                      INetURLObject::DecodeMechanism::Unambiguous),
275                                  aSdvURL.GetMainURL(INetURLObject::DecodeMechanism::Unambiguous));
276     CPPUNIT_ASSERT_EQUAL_MESSAGE("Sdg URL doesn't match",
277                                  aGalleryBinaryStorageLocations.GetSdgURL().GetMainURL(
278                                      INetURLObject::DecodeMechanism::Unambiguous),
279                                  aSdgURL.GetMainURL(INetURLObject::DecodeMechanism::Unambiguous));
280     CPPUNIT_ASSERT_EQUAL_MESSAGE("Str URL doesn't match",
281                                  aGalleryBinaryStorageLocations.GetStrURL().GetMainURL(
282                                      INetURLObject::DecodeMechanism::Unambiguous),
283                                  aStrURL.GetMainURL(INetURLObject::DecodeMechanism::Unambiguous));
284 }
285 
TestInsertGalleryObject()286 void GalleryObjTest::TestInsertGalleryObject()
287 {
288     // Create theme
289     std::unique_ptr<utl::TempFile> pTempDir;
290     pTempDir.reset(new utl::TempFile(nullptr, true));
291     CPPUNIT_ASSERT_MESSAGE("Could not create valid temporary directory", pTempDir->IsValid());
292     pTempDir->EnableKillingFile();
293     const OUString aGalleryURL = pTempDir->GetURL();
294 
295     // Check if directory exists
296     CPPUNIT_ASSERT_MESSAGE("Could not create temporary directory",
297                            comphelper::DirectoryHelper::dirExists(aGalleryURL));
298 
299     std::unique_ptr<Gallery> pGallery(new Gallery(aGalleryURL));
300     CPPUNIT_ASSERT_MESSAGE("Could not create gallery instance", (pGallery != nullptr));
301     static const OUStringLiteral myThemeName = u"addytesttheme";
302     CPPUNIT_ASSERT_MESSAGE("Could not create theme", pGallery->CreateTheme(myThemeName));
303     CPPUNIT_ASSERT_MESSAGE("Could not find theme", pGallery->HasTheme(myThemeName));
304 
305     // Create Sfx Instance
306     SfxListener aListener;
307     SfxApplication::GetOrCreate();
308 
309     // Insert Objects Into Theme
310     GalleryTheme* pGalleryTheme = pGallery->AcquireTheme(myThemeName, aListener);
311     CPPUNIT_ASSERT_EQUAL_MESSAGE("Object count inconsistent", sal_uInt32(0),
312                                  pGalleryTheme->GetObjectCount());
313 
314     std::vector<OUString> imageList{ "galtest1.png", "galtest2.png", "galtest3.jpg" };
315 
316     for (sal_uInt32 i = 0; i < static_cast<sal_uInt32>(imageList.size()); i++)
317     {
318         OUString imageNameFromList(imageList[i]);
319         OUString aURL(m_directories.getURLFromSrc(u"/svx/qa/unit/gallery/data/")
320                       + imageNameFromList);
321         CPPUNIT_ASSERT_MESSAGE("Could not insert object into theme",
322                                pGalleryTheme->InsertURL(INetURLObject(aURL)));
323         CPPUNIT_ASSERT_EQUAL_MESSAGE("Inconsistent object Count", pGalleryTheme->GetObjectCount(),
324                                      i + 1);
325         std::unique_ptr<SgaObject> pObj = pGalleryTheme->AcquireObject(i);
326         CPPUNIT_ASSERT_MESSAGE("Acquired Object Invalid", pObj->IsValid());
327     }
328     pGallery->ReleaseTheme(pGalleryTheme, aListener);
329 }
330 
TestRemoveGalleryObject()331 void GalleryObjTest::TestRemoveGalleryObject()
332 {
333     // Create theme
334     std::unique_ptr<utl::TempFile> pTempDir;
335     pTempDir.reset(new utl::TempFile(nullptr, true));
336     CPPUNIT_ASSERT_MESSAGE("Could not create valid temporary directory", pTempDir->IsValid());
337     pTempDir->EnableKillingFile();
338     const OUString aGalleryURL = pTempDir->GetURL();
339 
340     // Check if directory exists
341     CPPUNIT_ASSERT_MESSAGE("Could not create temporary directory",
342                            comphelper::DirectoryHelper::dirExists(aGalleryURL));
343 
344     std::unique_ptr<Gallery> pGallery(new Gallery(aGalleryURL));
345     CPPUNIT_ASSERT_MESSAGE("Could not create gallery instance", (pGallery != nullptr));
346     static const OUStringLiteral myThemeName = u"addytesttheme";
347     CPPUNIT_ASSERT_MESSAGE("Could not create theme", pGallery->CreateTheme(myThemeName));
348     CPPUNIT_ASSERT_MESSAGE("Could not find theme", pGallery->HasTheme(myThemeName));
349 
350     // Create Sfx Instance
351     SfxListener aListener;
352     SfxApplication::GetOrCreate();
353 
354     // Insert Objects Into Theme
355     GalleryTheme* pGalleryTheme = pGallery->AcquireTheme(myThemeName, aListener);
356     CPPUNIT_ASSERT_EQUAL_MESSAGE("Object count inconsistent", sal_uInt32(0),
357                                  pGalleryTheme->GetObjectCount());
358 
359     std::vector<OUString> imageList{ "galtest1.png", "galtest2.png", "galtest3.jpg" };
360 
361     for (sal_uInt32 i = 0; i < static_cast<sal_uInt32>(imageList.size()); i++)
362     {
363         OUString imageNameFromList(imageList[i]);
364         OUString aURL(m_directories.getURLFromSrc(u"/svx/qa/unit/gallery/data/")
365                       + imageNameFromList);
366         CPPUNIT_ASSERT_MESSAGE("Could not insert object into theme",
367                                pGalleryTheme->InsertURL(INetURLObject(aURL)));
368         CPPUNIT_ASSERT_EQUAL_MESSAGE("Inconsistent object Count", pGalleryTheme->GetObjectCount(),
369                                      i + 1);
370         std::unique_ptr<SgaObject> pObj = pGalleryTheme->AcquireObject(i);
371         CPPUNIT_ASSERT_MESSAGE("Acquired Object Invalid", pObj->IsValid());
372     }
373 
374     for (sal_uInt32 i = static_cast<sal_uInt32>(imageList.size()); i > 0; i--)
375     {
376         std::unique_ptr<SgaObject> pObj = pGalleryTheme->AcquireObject(i - 1);
377         CPPUNIT_ASSERT_MESSAGE("Acquired Object Invalid", pObj->IsValid());
378         pGalleryTheme->RemoveObject(i - 1);
379         CPPUNIT_ASSERT_EQUAL_MESSAGE("Inconsistent object Count", pGalleryTheme->GetObjectCount(),
380                                      i - 1);
381     }
382 
383     pGallery->ReleaseTheme(pGalleryTheme, aListener);
384 }
385 
TestChangePositionGalleryObject()386 void GalleryObjTest::TestChangePositionGalleryObject()
387 {
388     // Create theme
389     std::unique_ptr<utl::TempFile> pTempDir;
390     pTempDir.reset(new utl::TempFile(nullptr, true));
391     CPPUNIT_ASSERT_MESSAGE("Could not create valid temporary directory", pTempDir->IsValid());
392     pTempDir->EnableKillingFile();
393     const OUString aGalleryURL = pTempDir->GetURL();
394 
395     // Check if directory exists
396     CPPUNIT_ASSERT_MESSAGE("Could not create temporary directory",
397                            comphelper::DirectoryHelper::dirExists(aGalleryURL));
398 
399     std::unique_ptr<Gallery> pGallery(new Gallery(aGalleryURL));
400     CPPUNIT_ASSERT_MESSAGE("Could not create gallery instance", (pGallery != nullptr));
401     static const OUStringLiteral myThemeName = u"addytesttheme";
402     CPPUNIT_ASSERT_MESSAGE("Could not create theme", pGallery->CreateTheme(myThemeName));
403     CPPUNIT_ASSERT_MESSAGE("Could not find theme", pGallery->HasTheme(myThemeName));
404 
405     // Create Sfx Instance
406     SfxListener aListener;
407     SfxApplication::GetOrCreate();
408 
409     // Insert Objects Into Theme
410     GalleryTheme* pGalleryTheme = pGallery->AcquireTheme(myThemeName, aListener);
411     CPPUNIT_ASSERT_EQUAL_MESSAGE("Object count inconsistent", sal_uInt32(0),
412                                  pGalleryTheme->GetObjectCount());
413 
414     OUString imageList[] = { "galtest1.png", "galtest2.png", "galtest3.jpg" };
415 
416     for (sal_uInt32 i = 0; i < (sizeof(imageList) / sizeof(imageList[0])); i++)
417     {
418         OUString imageNameFromList(imageList[i]);
419         OUString aURL(m_directories.getURLFromSrc(u"/svx/qa/unit/gallery/data/")
420                       + imageNameFromList);
421         CPPUNIT_ASSERT_MESSAGE("Could not insert object into theme",
422                                pGalleryTheme->InsertURL(INetURLObject(aURL)));
423         CPPUNIT_ASSERT_EQUAL_MESSAGE("Inconsistent object Count", pGalleryTheme->GetObjectCount(),
424                                      i + 1);
425         std::unique_ptr<SgaObject> pObj = pGalleryTheme->AcquireObject(i);
426         CPPUNIT_ASSERT_MESSAGE("Acquired Object Invalid", pObj->IsValid());
427     }
428 
429     CPPUNIT_ASSERT(pGalleryTheme->ChangeObjectPos(1, 3));
430     std::unique_ptr<SgaObject> pObj = pGalleryTheme->AcquireObject(0);
431     INetURLObject aURL = pObj->GetURL();
432     CPPUNIT_ASSERT_EQUAL_MESSAGE("Failure to change object position", imageList[0],
433                                  aURL.GetLastName());
434 
435     pObj = pGalleryTheme->AcquireObject(1);
436     aURL = pObj->GetURL();
437     CPPUNIT_ASSERT_EQUAL_MESSAGE("Failure to change object position", imageList[2],
438                                  aURL.GetLastName());
439 
440     pObj = pGalleryTheme->AcquireObject(2);
441     aURL = pObj->GetURL();
442     CPPUNIT_ASSERT_EQUAL_MESSAGE("Failure to change object position", imageList[1],
443                                  aURL.GetLastName());
444 
445     pGallery->ReleaseTheme(pGalleryTheme, aListener);
446 }
447 
TestGetThemeNameFromGalleryTheme()448 void GalleryObjTest::TestGetThemeNameFromGalleryTheme()
449 {
450     // Create theme
451     std::unique_ptr<utl::TempFile> pTempDir;
452     pTempDir.reset(new utl::TempFile(nullptr, true));
453     CPPUNIT_ASSERT_MESSAGE("Could not create valid temporary directory", pTempDir->IsValid());
454     pTempDir->EnableKillingFile();
455     const OUString aGalleryURL = pTempDir->GetURL();
456 
457     // Check if directory exists
458     CPPUNIT_ASSERT_MESSAGE("Could not create temporary directory",
459                            comphelper::DirectoryHelper::dirExists(aGalleryURL));
460 
461     std::unique_ptr<Gallery> pGallery(new Gallery(aGalleryURL));
462     CPPUNIT_ASSERT_MESSAGE("Could not create gallery instance", (pGallery != nullptr));
463     const OUString myThemeName = "addytesttheme";
464     CPPUNIT_ASSERT_MESSAGE("Could not create theme", pGallery->CreateTheme(myThemeName));
465     CPPUNIT_ASSERT_MESSAGE("Could not find theme", pGallery->HasTheme(myThemeName));
466 
467     // Create Sfx Instance
468     SfxListener aListener;
469     SfxApplication::GetOrCreate();
470 
471     GalleryTheme* pGalleryTheme = pGallery->AcquireTheme(myThemeName, aListener);
472     CPPUNIT_ASSERT_EQUAL_MESSAGE("Object count inconsistent", sal_uInt32(0),
473                                  pGalleryTheme->GetObjectCount());
474 
475     CPPUNIT_ASSERT_EQUAL_MESSAGE("Theme name not matching", myThemeName, pGalleryTheme->GetName());
476 
477     pGallery->ReleaseTheme(pGalleryTheme, aListener);
478 }
479 
480 CPPUNIT_TEST_SUITE_REGISTRATION(GalleryObjTest);
481 
482 CPPUNIT_PLUGIN_IMPLEMENT();
483