summaryrefslogtreecommitdiff
path: root/svx/qa/unit/gallery/test_gallery.cxx
blob: 072361232dc741376dff1c5a8a9fb62c36031e51 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
/* -*- 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 <test/bootstrapfixture.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 <svx/gallerybinarystoragelocations.hxx>
#include <svx/gallerystoragelocations.hxx>
#include <galobj.hxx>

#include <cppunit/TestAssert.h>
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/plugin/TestPlugIn.h>

class GalleryObjTest : public test::BootstrapFixture
{
public:
    void TestCreateTheme();
    void TestDeleteTheme();
    void TestSetThemeName();
    void TestThemeURLCase();
    void TestThemeCount();
    void TestGalleryThemeEntry();
    void TestInsertGalleryObject();
    void TestRemoveGalleryObject();
    void TestChangePositionGalleryObject();
    void TestGetThemeNameFromGalleryTheme();

    CPPUNIT_TEST_SUITE(GalleryObjTest);

    CPPUNIT_TEST(TestCreateTheme);
    CPPUNIT_TEST(TestDeleteTheme);
    CPPUNIT_TEST(TestSetThemeName);
    CPPUNIT_TEST(TestThemeURLCase);
    CPPUNIT_TEST(TestThemeCount);
    CPPUNIT_TEST(TestGalleryThemeEntry);
    CPPUNIT_TEST(TestInsertGalleryObject);
    CPPUNIT_TEST(TestRemoveGalleryObject);
    CPPUNIT_TEST(TestChangePositionGalleryObject);
    CPPUNIT_TEST(TestGetThemeNameFromGalleryTheme);

    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));
    static const OUStringLiteral myThemeName = u"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));
    static const OUStringLiteral myThemeName = u"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));
    static const OUStringLiteral myThemeName = u"addytesttheme";
    CPPUNIT_ASSERT_MESSAGE("Could not create theme", pGallery->CreateTheme(myThemeName));
    CPPUNIT_ASSERT_MESSAGE("Could not find theme", pGallery->HasTheme(myThemeName));

    // Rename theme
    static const OUStringLiteral myNewThemeName = u"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
}

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
    GalleryBinaryStorageLocations& aGalleryBinaryStorageLocations
        = dynamic_cast<GalleryBinaryStorageLocations&>(mpThemeEntry->getGalleryStorageLocations());
    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",
                                 aGalleryBinaryStorageLocations.GetThmURL().GetMainURL(
                                     INetURLObject::DecodeMechanism::Unambiguous),
                                 aThemeURL.GetMainURL(INetURLObject::DecodeMechanism::Unambiguous));
    CPPUNIT_ASSERT_EQUAL_MESSAGE("Sdv URL doesn't match",
                                 aGalleryBinaryStorageLocations.GetSdvURL().GetMainURL(
                                     INetURLObject::DecodeMechanism::Unambiguous),
                                 aSdvURL.GetMainURL(INetURLObject::DecodeMechanism::Unambiguous));
    CPPUNIT_ASSERT_EQUAL_MESSAGE("Sdg URL doesn't match",
                                 aGalleryBinaryStorageLocations.GetSdgURL().GetMainURL(
                                     INetURLObject::DecodeMechanism::Unambiguous),
                                 aSdgURL.GetMainURL(INetURLObject::DecodeMechanism::Unambiguous));
    CPPUNIT_ASSERT_EQUAL_MESSAGE("Str URL doesn't match",
                                 aGalleryBinaryStorageLocations.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));
    static const OUStringLiteral myThemeName = u"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());

    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(u"/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));
    static const OUStringLiteral myThemeName = u"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());

    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(u"/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));
    static const OUStringLiteral myThemeName = u"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(u"/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);
}

CPPUNIT_TEST_SUITE_REGISTRATION(GalleryObjTest);

CPPUNIT_PLUGIN_IMPLEMENT();