File indexing completed on 2024-12-22 04:10:29

0001 /*
0002  * SPDX-FileCopyrightText: 2018 boud <boud@valdyas.org>
0003  * SPDX-FileCopyrightText: 2019 Agata Cacko <cacko.azh@gmail.com>
0004  *
0005  * SPDX-License-Identifier: GPL-2.0-or-later
0006  */
0007 
0008 #include "TestAslStorage.h"
0009 
0010 
0011 #include <simpletest.h>
0012 #include <QImageReader>
0013 
0014 #include <KoConfig.h>
0015 
0016 #include <KisAslStorage.h>
0017 
0018 #include <testutil.h>
0019 
0020 #ifndef FILES_DATA_DIR
0021 #error "FILES_DATA_DIR not set. A directory with the data used for testing the importing of files in krita"
0022 #endif
0023 
0024 void TestAslStorage::initTestCase()
0025 {
0026     // nothing to do
0027 }
0028 
0029 
0030 void TestAslStorage::testResourceIterator_data()
0031 {
0032     QTest::addColumn<QString>("filename");
0033     QTest::addColumn<int>("patternsCount");
0034     QTest::addColumn<int>("stylesCount");
0035 
0036     QTest::newRow("asl/test_all_style.asl") << TestUtil::fetchDataFileLazy("asl/test_all_style.asl") << 0 << 1;
0037     //QTest::newRow("asl/test_all_with_pattern.asl") << TestUtil::fetchDataFileLazy("asl/test_all_with_pattern.asl") << 1 << 1;
0038     QTest::newRow("asl/multiple_styles.asl") << TestUtil::fetchDataFileLazy("asl/multiple_styles.asl") << 1 << 4;
0039     QTest::newRow("asl/freebie_with_pattern.asl") << TestUtil::fetchDataFileLazy("asl/testset/freebie_with_pattern.asl") << 1 << 1;
0040 
0041 
0042 }
0043 
0044 void TestAslStorage::testResourceIterator()
0045 {
0046     QFETCH(QString, filename);
0047     QFETCH(int, patternsCount);
0048     QFETCH(int, stylesCount);
0049 
0050     KisAslStorage storage(filename);
0051 
0052     QSharedPointer<KisResourceStorage::ResourceIterator> iter(storage.resources(ResourceType::Patterns));
0053 
0054     QVERIFY(iter->hasNext() || patternsCount == 0);
0055     int count = 0;
0056 
0057     while (iter->hasNext()) {
0058         iter->next();
0059         KoResourceSP res(iter->resource());
0060         QVERIFY(res);
0061         count++;
0062     }
0063     QCOMPARE(count, patternsCount);
0064 
0065 
0066     QSharedPointer<KisResourceStorage::ResourceIterator> iter2(storage.resources(ResourceType::LayerStyles));
0067 
0068     QVERIFY(iter2->hasNext());
0069     count = 0;
0070 
0071     while (iter2->hasNext()) {
0072         iter2->next();
0073         KoResourceSP res(iter2->resource());
0074         QVERIFY(res);
0075         count++;
0076     }
0077     QCOMPARE(count, stylesCount);
0078 
0079     QSharedPointer<KisResourceStorage::ResourceIterator> iter3(storage.resources(ResourceType::Brushes));
0080 
0081     count = 0;
0082 
0083     while (iter3->hasNext()) {
0084         iter3->next();
0085         KoResourceSP res(iter3->resource());
0086         QVERIFY(res);
0087         count++;
0088     }
0089     QCOMPARE(count, 0);
0090 
0091 }
0092 
0093 void TestAslStorage::testTagIterator_data()
0094 {
0095     QTest::addColumn<QString>("filename");
0096 
0097     QTest::newRow("asl/test_all_style.asl") << TestUtil::fetchDataFileLazy("asl/test_all_style.asl");
0098     //QTest::newRow("asl/test_all_with_pattern.asl") << TestUtil::fetchDataFileLazy("asl/test_all_with_pattern.asl") << 1 << 1;
0099     QTest::newRow("asl/multiple_styles.asl") << TestUtil::fetchDataFileLazy("asl/multiple_styles.asl");
0100     QTest::newRow("asl/freebie_with_pattern.asl") << TestUtil::fetchDataFileLazy("asl/testset/freebie_with_pattern.asl");
0101 
0102 
0103 }
0104 
0105 void TestAslStorage::testTagIterator()
0106 {
0107     QFETCH(QString, filename);
0108 
0109     KisAslStorage storage(filename);
0110 
0111     QSharedPointer<KisResourceStorage::TagIterator> iter = storage.tags(ResourceType::LayerStyles);
0112     int count = 0;
0113     while (iter->hasNext()) {
0114         iter->next();
0115         count++;
0116     }
0117     QVERIFY(count == 0);
0118 
0119 }
0120 
0121 void TestAslStorage::testResourceItem_data()
0122 {
0123     QTest::addColumn<QString>("filename");
0124     QTest::addColumn<QString>("resource");
0125 
0126     QTest::newRow("asl/test_all_style.asl") << TestUtil::fetchDataFileLazy("asl/test_all_style.asl") << "{0701cdb9-df8a-11e4-adaf-ce8e6f81a66e}";
0127 
0128     //QTest::newRow("asl/test_all_with_pattern.asl") << TestUtil::fetchDataFileLazy("asl/test_all_with_pattern.asl") << 1 << 1;
0129 
0130     QTest::newRow("asl/multiple_styles.asl") << TestUtil::fetchDataFileLazy("asl/multiple_styles.asl") << "8122fc0c-58b9-11d4-b895-a898787104c1.pat";
0131     QTest::newRow("asl/multiple_styles.asl") << TestUtil::fetchDataFileLazy("asl/multiple_styles.asl") << "{81a5a778-bd9f-11d5-b8ba-b73f8571793d}";
0132     QTest::newRow("asl/multiple_styles.asl") << TestUtil::fetchDataFileLazy("asl/multiple_styles.asl") << "{81a5a779-bd9f-11d5-b8ba-b73f8571793d}";
0133     QTest::newRow("asl/multiple_styles.asl") << TestUtil::fetchDataFileLazy("asl/multiple_styles.asl") << "{81a5a77a-bd9f-11d5-b8ba-b73f8571793d}";
0134     QTest::newRow("asl/multiple_styles.asl") << TestUtil::fetchDataFileLazy("asl/multiple_styles.asl") << "{4ae237f2-bda0-11d5-b8ba-b73f8571793d}";
0135 
0136 
0137     QTest::newRow("asl/freebie_with_pattern.asl") << TestUtil::fetchDataFileLazy("asl/testset/freebie_with_pattern.asl")  << "{47c8b792-b27f-11e1-a082-d6e8ee17595d}";
0138     QTest::newRow("asl/freebie_with_pattern.asl") << TestUtil::fetchDataFileLazy("asl/testset/freebie_with_pattern.asl")  << "47c8b78c-b27f-11e1-a082-d6e8ee17595d.pat";
0139 
0140 
0141 }
0142 
0143 void TestAslStorage::testResourceItem()
0144 {
0145 
0146     QFETCH(QString, filename);
0147     QFETCH(QString, resource);
0148     KisAslStorage storage(filename);
0149 
0150     KisResourceStorage::ResourceItem item = storage.resourceItem(resource);
0151     QVERIFY(!item.url.isEmpty());
0152 
0153 }
0154 
0155 void TestAslStorage::testResource_data()
0156 {
0157     QTest::addColumn<QString>("filename");
0158     QTest::addColumn<QString>("resource");
0159 
0160     QTest::newRow("asl/test_all_style.asl") << TestUtil::fetchDataFileLazy("asl/test_all_style.asl") << "{0701cdb9-df8a-11e4-adaf-ce8e6f81a66e}";
0161 
0162     //QTest::newRow("asl/test_all_with_pattern.asl") << TestUtil::fetchDataFileLazy("asl/test_all_with_pattern.asl") << 1 << 1;
0163 
0164     QTest::newRow("asl/multiple_styles.asl") << TestUtil::fetchDataFileLazy("asl/multiple_styles.asl") << "8122fc0c-58b9-11d4-b895-a898787104c1.pat";
0165     QTest::newRow("asl/multiple_styles.asl") << TestUtil::fetchDataFileLazy("asl/multiple_styles.asl") << "{81a5a778-bd9f-11d5-b8ba-b73f8571793d}";
0166     QTest::newRow("asl/multiple_styles.asl") << TestUtil::fetchDataFileLazy("asl/multiple_styles.asl") << "{81a5a779-bd9f-11d5-b8ba-b73f8571793d}";
0167     QTest::newRow("asl/multiple_styles.asl") << TestUtil::fetchDataFileLazy("asl/multiple_styles.asl") << "{81a5a77a-bd9f-11d5-b8ba-b73f8571793d}";
0168     QTest::newRow("asl/multiple_styles.asl") << TestUtil::fetchDataFileLazy("asl/multiple_styles.asl") << "{4ae237f2-bda0-11d5-b8ba-b73f8571793d}";
0169 
0170 
0171     QTest::newRow("asl/freebie_with_pattern.asl") << TestUtil::fetchDataFileLazy("asl/testset/freebie_with_pattern.asl")  << "{47c8b792-b27f-11e1-a082-d6e8ee17595d}";
0172     QTest::newRow("asl/freebie_with_pattern.asl") << TestUtil::fetchDataFileLazy("asl/testset/freebie_with_pattern.asl")  << "47c8b78c-b27f-11e1-a082-d6e8ee17595d.pat";
0173 
0174 
0175 }
0176 
0177 void TestAslStorage::testResource()
0178 {
0179     QFETCH(QString, filename);
0180     QFETCH(QString, resource);
0181 
0182 
0183     KisAslStorage storage(filename);
0184     KoResourceSP res = storage.resource(resource);
0185     QVERIFY(res);
0186     QCOMPARE(res->filename(), resource);
0187 }
0188 
0189 
0190 SIMPLE_TEST_MAIN(TestAslStorage)
0191