File indexing completed on 2024-12-22 04:12:02

0001 /*
0002  * SPDX-FileCopyrightText: 2017 Boudewijn Rempt <boud@valdyas.org>
0003  *
0004  * SPDX-License-Identifier: LGPL-2.0-or-later
0005  */
0006 
0007 #include "TestTag.h"
0008 #include <simpletest.h>
0009 #include <QBuffer>
0010 
0011 #include <KisTag.h>
0012 #include <KoResource.h>
0013 
0014 #include <KLocalizedString>
0015 
0016 #ifndef FILES_DATA_DIR
0017 #error "FILES_DATA_DIR not set. A directory with the data used for testing installing resources"
0018 #endif
0019 
0020 void TestTag::testLoadTag()
0021 {
0022     KisTag tagLoader;
0023     QFile f(QString(FILES_DATA_DIR) + "paintoppresets/test.tag");
0024 
0025     QVERIFY(f.exists());
0026 
0027     f.open(QFile::ReadOnly);
0028     QVERIFY(f.isOpen());
0029 
0030     bool r = tagLoader.load(f);
0031 
0032     f.close();
0033 
0034     QVERIFY(r);
0035     QVERIFY(tagLoader.name() == "* Favorites");
0036     QVERIFY(tagLoader.comment() == "Your favorite brush presets");
0037     QVERIFY(tagLoader.url() == "* Favorites");
0038 
0039     m_languages = KLocalizedString::languages();
0040     KLocalizedString::setLanguages(QStringList() << "nl");
0041     QLocale::setDefault(QLocale("nl"));
0042 
0043     QVERIFY(tagLoader.name() == "* Favorieten");
0044     QVERIFY(tagLoader.comment() == "Uw favorite voorinstellingen van penselen");
0045     QVERIFY(tagLoader.url() == "* Favorites");
0046 
0047     KLocalizedString::setLanguages(m_languages);
0048     QLocale::setDefault(QLocale("C"));
0049 }
0050 
0051 void TestTag::testSaveTag()
0052 {
0053     KisTag tag1;
0054     QFile f(QString(FILES_DATA_DIR) + "paintoppresets/test.tag");
0055 
0056     QVERIFY(f.exists());
0057 
0058     f.open(QFile::ReadOnly);
0059     QVERIFY(f.isOpen());
0060 
0061     bool r = tag1.load(f);
0062     QVERIFY(r);
0063 
0064     tag1.setName(QString("Test"));
0065 
0066     QBuffer buf;
0067     buf.open(QBuffer::WriteOnly);
0068 
0069     QVERIFY(tag1.save(buf));
0070 
0071     buf.close();
0072     buf.open(QBuffer::ReadOnly);
0073 
0074     KisTag tag2;
0075     tag2.load(buf);
0076     QVERIFY(tag2.url() == tag1.url());
0077     QVERIFY(tag2.name() == tag1.name());
0078     QVERIFY(tag2.resourceType() == tag1.resourceType());
0079     QVERIFY(tag2.comment() == tag1.comment());
0080     QVERIFY(tag2.defaultResources() == tag1.defaultResources());
0081 
0082 }
0083 
0084 SIMPLE_TEST_MAIN(TestTag)
0085