1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 #include <test/bootstrapfixture.hxx>
11 #include <tools/urlobj.hxx>
12 #include <sfx2/app.hxx>
13 #include <unotools/tempfile.hxx>
14 #include <comphelper/DirectoryHelper.hxx>
16 #include <svx/gallery1.hxx>
17 #include <svx/galtheme.hxx>
18 #include <svx/gallerybinarystoragelocations.hxx>
19 #include <svx/gallerystoragelocations.hxx>
22 #include <cppunit/TestAssert.h>
23 #include <cppunit/extensions/HelperMacros.h>
24 #include <cppunit/plugin/TestPlugIn.h>
26 class GalleryObjTest
: public test::BootstrapFixture
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();
40 CPPUNIT_TEST_SUITE(GalleryObjTest
);
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
);
53 CPPUNIT_TEST_SUITE_END();
56 // Create and Dereference a theme, check that file exists
57 void GalleryObjTest::TestCreateTheme()
60 std::unique_ptr
<utl::TempFileNamed
> pTempDir
;
61 pTempDir
.reset(new utl::TempFileNamed(nullptr, true));
62 CPPUNIT_ASSERT_MESSAGE("Could not create valid temporary directory", pTempDir
->IsValid());
63 pTempDir
->EnableKillingFile();
64 const OUString aGalleryURL
= pTempDir
->GetURL();
66 // Check if directory exists
67 CPPUNIT_ASSERT_MESSAGE("Could not create temporary directory",
68 comphelper::DirectoryHelper::dirExists(aGalleryURL
));
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
));
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"));
85 // Create and Delete Theme, check the file doesn't exist
86 void GalleryObjTest::TestDeleteTheme()
89 std::unique_ptr
<utl::TempFileNamed
> pTempDir
;
90 pTempDir
.reset(new utl::TempFileNamed(nullptr, true));
91 CPPUNIT_ASSERT_MESSAGE("Could not create valid temporary directory", pTempDir
->IsValid());
92 pTempDir
->EnableKillingFile();
93 const OUString aGalleryURL
= pTempDir
->GetURL();
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
));
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
));
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"));
121 // Create theme, set name, assert the name is expected
122 void GalleryObjTest::TestSetThemeName()
125 std::unique_ptr
<utl::TempFileNamed
> pTempDir
;
126 pTempDir
.reset(new utl::TempFileNamed(nullptr, true));
127 CPPUNIT_ASSERT_MESSAGE("Could not create valid temporary directory", pTempDir
->IsValid());
128 pTempDir
->EnableKillingFile();
129 const OUString aGalleryURL
= pTempDir
->GetURL();
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
));
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
));
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"));
153 void GalleryObjTest::TestThemeURLCase()
156 std::unique_ptr
<utl::TempFileNamed
> pTempDir
;
157 pTempDir
.reset(new utl::TempFileNamed(nullptr, true));
158 CPPUNIT_ASSERT_MESSAGE("Could not create valid temporary directory", pTempDir
->IsValid());
159 pTempDir
->EnableKillingFile();
160 const OUString aGalleryURL
= pTempDir
->GetURL();
162 // Check if directory exists
163 CPPUNIT_ASSERT_MESSAGE("Could not create temporary directory",
164 comphelper::DirectoryHelper::dirExists(aGalleryURL
));
166 std::unique_ptr
<Gallery
> pGallery(new Gallery(aGalleryURL
));
167 CPPUNIT_ASSERT_MESSAGE("Could not create gallery instance", (pGallery
!= nullptr));
169 // Mixed Case Theme Name
170 const OUString myThemeName
= "AddyTestTheme";
172 CPPUNIT_ASSERT_MESSAGE("Could not create theme", pGallery
->CreateTheme(myThemeName
));
173 CPPUNIT_ASSERT_MESSAGE("Could not find theme", pGallery
->HasTheme(myThemeName
));
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"));
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"));
192 void GalleryObjTest::TestThemeCount()
194 std::unique_ptr
<utl::TempFileNamed
> pTempDir
;
195 pTempDir
.reset(new utl::TempFileNamed(nullptr, true));
196 CPPUNIT_ASSERT_MESSAGE("Could not create valid temporary directory", pTempDir
->IsValid());
197 pTempDir
->EnableKillingFile();
198 const OUString aGalleryURL
= pTempDir
->GetURL();
200 // Check if directory exists
201 CPPUNIT_ASSERT_MESSAGE("Could not create temporary directory",
202 comphelper::DirectoryHelper::dirExists(aGalleryURL
));
204 std::unique_ptr
<Gallery
> pGallery(new Gallery(aGalleryURL
));
205 CPPUNIT_ASSERT_MESSAGE("Could not create gallery instance", (pGallery
!= nullptr));
207 // Loop through and test theme count in each pass.
208 sal_uInt32 nLimit
= 10;
209 for (sal_uInt32 i
= 1; i
<= nLimit
; i
++)
211 OUString myThemeName
= "addytesttheme" + OUString::number(i
);
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
);
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
--)
222 OUString myThemeName
= "addytesttheme" + OUString::number(i
);
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);
232 void GalleryObjTest::TestGalleryThemeEntry()
235 std::unique_ptr
<utl::TempFileNamed
> pTempDir
;
236 pTempDir
.reset(new utl::TempFileNamed(nullptr, true));
237 CPPUNIT_ASSERT_MESSAGE("Could not create valid temporary directory", pTempDir
->IsValid());
238 pTempDir
->EnableKillingFile();
239 const OUString aGalleryURL
= pTempDir
->GetURL();
241 // Check if directory exists
242 CPPUNIT_ASSERT_MESSAGE("Could not create temporary directory",
243 comphelper::DirectoryHelper::dirExists(aGalleryURL
));
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
));
251 // Get Theme Entry Object
252 const GalleryThemeEntry
* mpThemeEntry
= pGallery
->GetThemeInfo(myThemeName
);
255 CPPUNIT_ASSERT_EQUAL_MESSAGE("Theme name doesn't match", mpThemeEntry
->GetThemeName(),
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
));
286 void GalleryObjTest::TestInsertGalleryObject()
289 std::unique_ptr
<utl::TempFileNamed
> pTempDir
;
290 pTempDir
.reset(new utl::TempFileNamed(nullptr, true));
291 CPPUNIT_ASSERT_MESSAGE("Could not create valid temporary directory", pTempDir
->IsValid());
292 pTempDir
->EnableKillingFile();
293 const OUString aGalleryURL
= pTempDir
->GetURL();
295 // Check if directory exists
296 CPPUNIT_ASSERT_MESSAGE("Could not create temporary directory",
297 comphelper::DirectoryHelper::dirExists(aGalleryURL
));
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
));
305 // Create Sfx Instance
306 SfxListener aListener
;
307 SfxApplication::GetOrCreate();
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());
314 std::vector
<OUString
> imageList
{ "galtest1.png", "galtest2.png", "galtest3.jpg" };
316 for (sal_uInt32 i
= 0; i
< static_cast<sal_uInt32
>(imageList
.size()); i
++)
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(),
325 std::unique_ptr
<SgaObject
> pObj
= pGalleryTheme
->AcquireObject(i
);
326 CPPUNIT_ASSERT_MESSAGE("Acquired Object Invalid", pObj
->IsValid());
328 pGallery
->ReleaseTheme(pGalleryTheme
, aListener
);
331 void GalleryObjTest::TestRemoveGalleryObject()
334 std::unique_ptr
<utl::TempFileNamed
> pTempDir
;
335 pTempDir
.reset(new utl::TempFileNamed(nullptr, true));
336 CPPUNIT_ASSERT_MESSAGE("Could not create valid temporary directory", pTempDir
->IsValid());
337 pTempDir
->EnableKillingFile();
338 const OUString aGalleryURL
= pTempDir
->GetURL();
340 // Check if directory exists
341 CPPUNIT_ASSERT_MESSAGE("Could not create temporary directory",
342 comphelper::DirectoryHelper::dirExists(aGalleryURL
));
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
));
350 // Create Sfx Instance
351 SfxListener aListener
;
352 SfxApplication::GetOrCreate();
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());
359 std::vector
<OUString
> imageList
{ "galtest1.png", "galtest2.png", "galtest3.jpg" };
361 for (sal_uInt32 i
= 0; i
< static_cast<sal_uInt32
>(imageList
.size()); i
++)
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(),
370 std::unique_ptr
<SgaObject
> pObj
= pGalleryTheme
->AcquireObject(i
);
371 CPPUNIT_ASSERT_MESSAGE("Acquired Object Invalid", pObj
->IsValid());
374 for (sal_uInt32 i
= static_cast<sal_uInt32
>(imageList
.size()); i
> 0; i
--)
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(),
383 pGallery
->ReleaseTheme(pGalleryTheme
, aListener
);
386 void GalleryObjTest::TestChangePositionGalleryObject()
389 std::unique_ptr
<utl::TempFileNamed
> pTempDir
;
390 pTempDir
.reset(new utl::TempFileNamed(nullptr, true));
391 CPPUNIT_ASSERT_MESSAGE("Could not create valid temporary directory", pTempDir
->IsValid());
392 pTempDir
->EnableKillingFile();
393 const OUString aGalleryURL
= pTempDir
->GetURL();
395 // Check if directory exists
396 CPPUNIT_ASSERT_MESSAGE("Could not create temporary directory",
397 comphelper::DirectoryHelper::dirExists(aGalleryURL
));
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
));
405 // Create Sfx Instance
406 SfxListener aListener
;
407 SfxApplication::GetOrCreate();
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());
414 OUString imageList
[] = { "galtest1.png", "galtest2.png", "galtest3.jpg" };
416 for (sal_uInt32 i
= 0; i
< (sizeof(imageList
) / sizeof(imageList
[0])); i
++)
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(),
425 std::unique_ptr
<SgaObject
> pObj
= pGalleryTheme
->AcquireObject(i
);
426 CPPUNIT_ASSERT_MESSAGE("Acquired Object Invalid", pObj
->IsValid());
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],
435 pObj
= pGalleryTheme
->AcquireObject(1);
436 aURL
= pObj
->GetURL();
437 CPPUNIT_ASSERT_EQUAL_MESSAGE("Failure to change object position", imageList
[2],
440 pObj
= pGalleryTheme
->AcquireObject(2);
441 aURL
= pObj
->GetURL();
442 CPPUNIT_ASSERT_EQUAL_MESSAGE("Failure to change object position", imageList
[1],
445 pGallery
->ReleaseTheme(pGalleryTheme
, aListener
);
448 void GalleryObjTest::TestGetThemeNameFromGalleryTheme()
451 std::unique_ptr
<utl::TempFileNamed
> pTempDir
;
452 pTempDir
.reset(new utl::TempFileNamed(nullptr, true));
453 CPPUNIT_ASSERT_MESSAGE("Could not create valid temporary directory", pTempDir
->IsValid());
454 pTempDir
->EnableKillingFile();
455 const OUString aGalleryURL
= pTempDir
->GetURL();
457 // Check if directory exists
458 CPPUNIT_ASSERT_MESSAGE("Could not create temporary directory",
459 comphelper::DirectoryHelper::dirExists(aGalleryURL
));
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
));
467 // Create Sfx Instance
468 SfxListener aListener
;
469 SfxApplication::GetOrCreate();
471 GalleryTheme
* pGalleryTheme
= pGallery
->AcquireTheme(myThemeName
, aListener
);
472 CPPUNIT_ASSERT_EQUAL_MESSAGE("Object count inconsistent", sal_uInt32(0),
473 pGalleryTheme
->GetObjectCount());
475 CPPUNIT_ASSERT_EQUAL_MESSAGE("Theme name not matching", myThemeName
, pGalleryTheme
->GetName());
477 pGallery
->ReleaseTheme(pGalleryTheme
, aListener
);
480 CPPUNIT_TEST_SUITE_REGISTRATION(GalleryObjTest
);
482 CPPUNIT_PLUGIN_IMPLEMENT();