void FilteredModelTests::filterDescriptionTest() {
    DECLARE_MODELS_AND_GENERATE(10);
    Models::SettingsModel settingsModel;
    settingsModel.setSearchUsingAnd(false);
    commandManagerMock.InjectDependency(&settingsModel);

    for (int i = 0; i < 10; ++i) {
        Models::ArtworkMetadata *metadata = artItemsModelMock.getArtwork(i);

        if (i % 2) {
            metadata->initialize("title", "description", QStringList() << "keyword1" << "keyword2");
        } else {
            metadata->initialize("", "", QStringList());
        }
    }

    filteredItemsModel.setSearchTerm("desc");
    QCOMPARE(filteredItemsModel.getItemsCount(), 5);

    filteredItemsModel.setSearchTerm("!desc");
    QCOMPARE(filteredItemsModel.getItemsCount(), 0);

    filteredItemsModel.setSearchTerm("description");
    QCOMPARE(filteredItemsModel.getItemsCount(), 5);

    // strict match does not work for description/title
    filteredItemsModel.setSearchTerm("!description");
    QCOMPARE(filteredItemsModel.getItemsCount(), 0);
}
void FilteredModelTests::filterTitleAndKeywordsTest() {
    DECLARE_MODELS_AND_GENERATE(10);
    Models::SettingsModel settingsModel;
    settingsModel.setSearchUsingAnd(false);
    commandManagerMock.InjectDependency(&settingsModel);

    for (int i = 0; i < 10; ++i) {
        Models::ArtworkMetadata *metadata = artItemsModelMock.getArtwork(i);

        if (i % 2 == 0) {
            metadata->initialize("title", "description", QStringList() << "keyword1" << "mess1");
        } else {
            metadata->initialize("title", "description", QStringList() << "keyword2" << "mess2");
        }
    }

    filteredItemsModel.setSearchTerm("keyword1 tit");
    QCOMPARE(filteredItemsModel.getItemsCount(), 10);

    filteredItemsModel.setSearchTerm("!keyword tit");
    QCOMPARE(filteredItemsModel.getItemsCount(), 10);

    settingsModel.setSearchUsingAnd(true);

    filteredItemsModel.setSearchTerm("!keyword tit");
    QCOMPARE(filteredItemsModel.getItemsCount(), 0);

    filteredItemsModel.setSearchTerm("!keyword2 title");
    QCOMPARE(filteredItemsModel.getItemsCount(), 5);
}
Beispiel #3
0
void ReplaceTests::caseSensitiveTest() {
    const int itemsToGenerate = 10;
    DECLARE_MODELS_AND_GENERATE(itemsToGenerate);

    QString replaceFrom = "rePLace";
    QString replaceTo = "Replaced";
    QString initString = "ReplaceMe";
    QString finalString = "ReplacedMe";

    auto flags = Common::SearchFlags::Description |
            Common::SearchFlags::Title |
            Common::SearchFlags::Keywords;

    for (int i = 0; i < itemsToGenerate; i++) {
        Models::ArtworkMetadata *metadata = artItemsModelMock.getArtwork(i);
        metadata->initialize(initString, initString, QStringList() << initString);
    }

    auto artWorksInfo = filteredItemsModel.getSearchablePreviewOriginalItems(replaceFrom, flags);
    std::shared_ptr<Commands::FindAndReplaceCommand> replaceCommand(
                new Commands::FindAndReplaceCommand(artWorksInfo, replaceFrom, replaceTo, flags));
    auto result = commandManagerMock.processCommand(replaceCommand);

    for (int i = 0; i < itemsToGenerate; i++) {
        Models::ArtworkMetadata *metadata = artItemsModelMock.getArtwork(i);
        QCOMPARE(metadata->getDescription(), finalString);
        QCOMPARE(metadata->getTitle(), finalString);
        QCOMPARE(metadata->getKeywords()[0], finalString);
        QVERIFY(metadata->isModified());
    }
}
Beispiel #4
0
void PresetTests::parallelAccessTest() {
    const int initIterations = 100;
    const int itemsToGenerate = 5;
    DECLARE_MODELS_AND_GENERATE(itemsToGenerate);

    QString presetName = "preset";
    QStringList keywords;
    keywords << "keyword1" << "another keyword" << "test";

    Helpers::Barrier barrier1(2), barrier2(2);
    bool isAdded1, isAdded2;
    volatile bool removed1;
    volatile bool removed2;
    KeywordsPresets::ID_t id1 = 0;
    KeywordsPresets::ID_t id2 = 0;

    std::thread thread1([&]() {
        int n = initIterations;
        while (n--) {
            isAdded1 = false; id1 = 0;
            presetKeywordsModel.addOrUpdatePreset(presetName, keywords, id1, isAdded1);

            /*-------------*/barrier1.wait();

            Q_ASSERT(isAdded1 != isAdded2);
            Q_ASSERT(id1 == id2);

            removed1 = presetKeywordsModel.removePresetByID(id1);

            /*-------------*/barrier2.wait();

            Q_ASSERT(removed1 != removed2);
        }
    });

    std::thread thread2([&]() {

        int n = initIterations;
        while (n--) {
            isAdded2 = false; id2 = 1;
            presetKeywordsModel.addOrUpdatePreset(presetName, keywords, id2, isAdded2);

            /*-------------*/barrier1.wait();

            Q_ASSERT(isAdded1 != isAdded2);
            Q_ASSERT(id1 == id2);

            removed2 = presetKeywordsModel.removePresetByID(id2);

            /*-------------*/barrier2.wait();

            Q_ASSERT(removed1 != removed2);
        }
    });

    thread1.join();
    thread2.join();
}
void FilteredModelTests::clearEmptyKeywordsTest() {
    DECLARE_MODELS_AND_GENERATE(1);
    Models::ArtworkMetadata *metadata = artItemsModelMock.getArtwork(0);
    metadata->clearKeywords();

    commandManagerMock.resetAnyCommandProcessed();
    filteredItemsModel.clearKeywords(0);
    QVERIFY(!commandManagerMock.anyCommandProcessed());
}
void FilteredModelTests::findSelectedIndexTest() {
    DECLARE_MODELS_AND_GENERATE(10);
    artItemsModelMock.getArtwork(4)->setIsSelected(true);
    int index = filteredItemsModel.findSelectedItemIndex();
    QCOMPARE(index, 4);

    artItemsModelMock.getArtwork(9)->setIsSelected(true);
    index = filteredItemsModel.findSelectedItemIndex();
    QCOMPARE(index, -1);
}
void FilteredModelTests::invertSelectionForEmptyTest() {
    DECLARE_MODELS_AND_GENERATE(10);

    int allItemsCount = filteredItemsModel.getItemsCount();

    filteredItemsModel.invertSelectionArtworks();

    int selected = filteredItemsModel.retrieveNumberOfSelectedItems();
    QCOMPARE(selected, allItemsCount);
}
void FilteredModelTests::invertSelectionForSingleTest() {
    DECLARE_MODELS_AND_GENERATE(10);

    int allItemsCount = filteredItemsModel.getItemsCount();

    artItemsModelMock.getArtwork(0)->setIsSelected(true);

    filteredItemsModel.invertSelectionArtworks();

    int selected = filteredItemsModel.retrieveNumberOfSelectedItems();
    QCOMPARE(selected, (allItemsCount-1));
}
void FilteredModelTests::removeMetadataMarksAsModifiedTest() {
    DECLARE_MODELS_AND_GENERATE(1);

    Models::ArtworkMetadata *metadata = artItemsModelMock.getArtwork(0);

    QVERIFY(!metadata->isModified());

    metadata->setIsSelected(true);
    filteredItemsModel.removeMetadataInSelected();

    QVERIFY(metadata->isModified());
}
Beispiel #10
0
void PresetTests::registerGroupTwiceTest() {
    const int itemsToGenerate = 5;
    DECLARE_MODELS_AND_GENERATE(itemsToGenerate);

    const QString groupName = "group1";

    int groupID1 = 0, groupID2 = 1;

    presetKeywordsModel.findOrRegisterGroup(groupName, groupID1);
    presetKeywordsModel.findOrRegisterGroup(groupName, groupID2);

    QCOMPARE(groupID2, groupID1);
}
void FilteredModelTests::invertSelectionForOddCountTest() {
    DECLARE_MODELS_AND_GENERATE(11);

    int allItemsCount = filteredItemsModel.getItemsCount();
    for (int i =0; i<allItemsCount; i++) {
        artItemsModelMock.getArtwork(i)->setIsSelected(i < allItemsCount/3);
    }

    filteredItemsModel.invertSelectionArtworks();

    int selected = filteredItemsModel.retrieveNumberOfSelectedItems();
    QCOMPARE(selected, (allItemsCount - allItemsCount/3));
}
void FilteredModelTests::clearKeywordsTest() {
    DECLARE_MODELS_AND_GENERATE(1);

    Mocks::ArtworkMetadataMock *metadata = artItemsModelMock.getMockArtwork(0);
    metadata->initialize("title", "description", QStringList() << "keyword1" << "keyword2");

    filteredItemsModel.clearKeywords(0);

    QVERIFY(!metadata->isDescriptionEmpty());
    QVERIFY(!metadata->isTitleEmpty());
    QVERIFY(metadata->areKeywordsEmpty());
    QVERIFY(metadata->isModified());
}
Beispiel #13
0
void PresetTests::addAndRetrieveTest() {
    const int itemsToGenerate = 5;
    DECLARE_MODELS_AND_GENERATE(itemsToGenerate);

    const QString presetName = "preset";
    const QStringList keywords = QStringList() << "keyword1" << "test" << "another";

    KeywordsPresets::ID_t id = presetKeywordsModel.addItem(presetName, keywords);

    QStringList actual;
    presetKeywordsModel.tryGetPreset(id, actual);

    QCOMPARE(actual, keywords);
}
Beispiel #14
0
void PresetTests::strictFindPresetByNameTest() {
    const int itemsToGenerate = 5;
    DECLARE_MODELS_AND_GENERATE(itemsToGenerate);
    KeywordsPresets::ID_t id1 = presetKeywordsModel.addItem("Man", QStringList() << "some" << "keywords");
    KeywordsPresets::ID_t id2 = presetKeywordsModel.addItem("Woman", QStringList() << "other" << "keywords");

    KeywordsPresets::ID_t id;

    QVERIFY(!presetKeywordsModel.tryFindSinglePresetByName("man", true, id));
    QVERIFY(!presetKeywordsModel.tryFindSinglePresetByName("woman", true, id));

    QVERIFY(presetKeywordsModel.tryFindSinglePresetByName("Man", true, id)); QCOMPARE(id, id1);
    QVERIFY(presetKeywordsModel.tryFindSinglePresetByName("Woman", true, id)); QCOMPARE(id, id2);
}
Beispiel #15
0
void PresetTests::registerWithAnotherNameTest() {
    const int itemsToGenerate = 5;
    DECLARE_MODELS_AND_GENERATE(itemsToGenerate);

    const QString presetName = "preset";
    const QStringList keywords = QStringList() << "keyword1" << "test" << "another";

    KeywordsPresets::ID_t id1;
    presetKeywordsModel.findOrRegisterPreset(presetName, keywords, id1);

    KeywordsPresets::ID_t id2;
    presetKeywordsModel.findOrRegisterPreset(presetName + "1", keywords, id2);

    QVERIFY(id2 != id1);
}
Beispiel #16
0
void PresetTests::findPresetWithLongNamesByNameTest() {
    const int itemsToGenerate = 5;
    DECLARE_MODELS_AND_GENERATE(itemsToGenerate);
    KeywordsPresets::ID_t id1 = presetKeywordsModel.addItem("young woman", QStringList() << "some" << "keywords");
    KeywordsPresets::ID_t id2 = presetKeywordsModel.addItem("old woman", QStringList() << "other" << "keywords");

    KeywordsPresets::ID_t id;

    QVERIFY(!presetKeywordsModel.tryFindSinglePresetByName("woman", false, id));
    QVERIFY(!presetKeywordsModel.tryFindSinglePresetByName("woman", true, id));

    QVERIFY(presetKeywordsModel.tryFindSinglePresetByName("young", false, id)); QCOMPARE(id, id1);
    QVERIFY(presetKeywordsModel.tryFindSinglePresetByName("old", false, id)); QCOMPARE(id, id2);

    QVERIFY(presetKeywordsModel.tryFindSinglePresetByName("Young woman", false, id)); QCOMPARE(id, id1);
    QVERIFY(presetKeywordsModel.tryFindSinglePresetByName("old Woman", false, id)); QCOMPARE(id, id2);
}
Beispiel #17
0
void PresetTests::addAndRegisterTest() {
    const int itemsToGenerate = 5;
    DECLARE_MODELS_AND_GENERATE(itemsToGenerate);

    const QString presetName = "preset";
    const QStringList keywords = QStringList() << "keyword1" << "test" << "another";

    KeywordsPresets::ID_t id1;
    bool isAdded = false;
    presetKeywordsModel.addOrUpdatePreset(presetName, keywords, id1, isAdded);
    QCOMPARE(isAdded, true);

    KeywordsPresets::ID_t id2;
    presetKeywordsModel.findOrRegisterPreset(presetName, keywords, id2);

    QCOMPARE(id2, id1);
}
void FilteredModelTests::detachVectorFromSelectedTest() {
    DECLARE_MODELS_AND_GENERATE(10);

    for (int i = 0; i < 10; ++i) {
        Mocks::ArtworkMetadataMock *metadata = artItemsModelMock.getMockArtwork(i);
        metadata->initialize("title", "description", QStringList() << "keyword1" << "keyword2");
        metadata->attachVector(QString(metadata->getFilepath()).replace(".jpg", ".eps"));
        metadata->setIsSelected(true);
    }

    filteredItemsModel.detachVectorFromSelected();

    for (int i = 0; i < 10; ++i) {
        Mocks::ArtworkMetadataMock *metadata = artItemsModelMock.getMockArtwork(i);
        QVERIFY(!metadata->isModified());
        QVERIFY(!metadata->hasVectorAttached());
    }
}
Beispiel #19
0
void PresetTests::addRemovePresetTest() {
    const int itemsToGenerate = 5;
    DECLARE_MODELS_AND_GENERATE(itemsToGenerate);

    bool isAdded = false;

    int n = 10;
    while (n--) {
        qDebug() << (5 - n - 1);
        KeywordsPresets::ID_t id = 0;
        presetKeywordsModel.addOrUpdatePreset("bike", QStringList() << "downhill" << "slope" <<
                                              "uphill" << "slope", id, isAdded);
        QCOMPARE(isAdded, true);

        bool isRemoved = presetKeywordsModel.removePresetByID(id);
        QCOMPARE(isRemoved, true);
    }
}
Beispiel #20
0
void PresetTests::setPresetUnknownGroupTest() {
    const int itemsToGenerate = 5;
    DECLARE_MODELS_AND_GENERATE(itemsToGenerate);

    bool isAdded = false;
    KeywordsPresets::ID_t id = 0;
    presetKeywordsModel.addOrUpdatePreset("bike", QStringList() << "downhill" << "slope" <<
                                          "uphill" << "slope", id, isAdded);

    bool setGroupSuccess = presetKeywordsModel.setPresetGroup(id, 1234);
    QCOMPARE(setGroupSuccess, false);

    int groupID = 0;
    presetKeywordsModel.findOrRegisterGroup("test group", groupID);

    setGroupSuccess = presetKeywordsModel.setPresetGroup(id, groupID);
    QCOMPARE(setGroupSuccess, true);
}
void FilteredModelTests::setSelectedForZippingTest() {
    DECLARE_MODELS_AND_GENERATE(10);
    Models::ZipArchiver zipArchiver;
    commandManagerMock.InjectDependency(&zipArchiver);

    for (int i = 0; i < 10; ++i) {
        Models::ArtworkMetadata *metadata = artItemsModelMock.getArtwork(i);
        metadata->initialize("title", "description", QStringList() << "keyword1" << "keyword2");

        if (i % 2) {
            metadata->setIsSelected(true);
        }
    }

    filteredItemsModel.setSelectedForZipping();

    const QVector<Models::ArtworkMetadata*> &artworks = zipArchiver.getArtworkList();
    QCOMPARE(artworks.length(), 5);
}
Beispiel #22
0
void PresetTests::addPresetKeywordsWithDuplicatesTest() {
    const int itemsToGenerate = 5;
    DECLARE_MODELS_AND_GENERATE(itemsToGenerate);

    bool isAdded = false;
    KeywordsPresets::ID_t id = 0;
    presetKeywordsModel.addOrUpdatePreset("bike", QStringList() << "downhill" << "slope" <<
                                          "uphill" << "slope", id, isAdded);

    QVERIFY(isAdded == true);
    QStringList keywords;
    bool found = presetKeywordsModel.tryGetPreset(id, keywords);
    QVERIFY(found);

    QStringList expectedKeywords;
    expectedKeywords << "downhill" << "slope" << "uphill";

    QCOMPARE(keywords, expectedKeywords);
}
void FilteredModelTests::removeMetadataDeletesMetadataTest() {
    DECLARE_MODELS_AND_GENERATE(10);

    for (int i = 0; i < 10; ++i) {
        Models::ArtworkMetadata *metadata = artItemsModelMock.getArtwork(i);
        metadata->initialize("title", "description", QStringList() << "keyword1" << "keyword2");
        metadata->setIsSelected(true);
    }

    filteredItemsModel.removeMetadataInSelected();

    for (int i = 0; i < 10; ++i) {
        Mocks::ArtworkMetadataMock *metadata = artItemsModelMock.getMockArtwork(i);
        QVERIFY(metadata->isDescriptionEmpty());
        QVERIFY(metadata->isTitleEmpty());
        QVERIFY(metadata->areKeywordsEmpty());
        QVERIFY(metadata->isModified());
    }
}
Beispiel #24
0
void PresetTests::addGroupTest() {
    const int itemsToGenerate = 5;
    DECLARE_MODELS_AND_GENERATE(itemsToGenerate);

    bool isAdded = false;
    KeywordsPresets::ID_t id = 0;
    presetKeywordsModel.addOrUpdatePreset("bike", QStringList() << "downhill" << "slope" <<
                                          "uphill" << "slope", id, isAdded);

    int groupID = 0;
    presetKeywordsModel.findOrRegisterGroup("test group", groupID);

    bool success = presetKeywordsModel.setPresetGroup(id, groupID);
    QVERIFY(success);

    int foundID = 0;
    bool foundGroup = presetKeywordsModel.tryGetGroupFromIndex(0, foundID);
    QVERIFY(foundGroup);
    QCOMPARE(foundID, groupID);
}
Beispiel #25
0
void ReplaceTests::replaceKeywordsTest() {
    const int itemsToGenerate = 10;
    DECLARE_MODELS_AND_GENERATE(itemsToGenerate);

    QString replaceFrom = "keywordOld";
    QString replaceTo = "keywordNew";
    QString replaceToLower = replaceTo.toLower();

    auto flags = Common::SearchFlags::CaseSensitive |
                Common::SearchFlags::Description |
                Common::SearchFlags::Title |
                Common::SearchFlags::Keywords;

    for (int i = 0; i < itemsToGenerate; i++) {
        Models::ArtworkMetadata *metadata = artItemsModelMock.getArtwork(i);
        metadata->initialize(QString("title"), QString("description"),
                             QStringList() << replaceToLower << "dummyKey" << replaceFrom);
    }

    auto artWorksInfo = filteredItemsModel.getSearchablePreviewOriginalItems(replaceFrom, flags);
    std::shared_ptr<Commands::FindAndReplaceCommand> replaceCommand(
                new Commands::FindAndReplaceCommand(artWorksInfo, replaceFrom, replaceTo, flags));
    auto result = commandManagerMock.processCommand(replaceCommand);

    for (int i = 0; i < itemsToGenerate; i++) {
        Models::ArtworkMetadata *metadata = artItemsModelMock.getArtwork(i);
        QCOMPARE(metadata->getDescription(), QString("description"));
        QCOMPARE(metadata->getTitle(), QString("title"));

        QStringList test = metadata->getKeywords();
        QStringList gold;

        gold << replaceToLower << "dummyKey";
        qSort(gold.begin(), gold.end());
        qSort(test.begin(), test.end());

        QCOMPARE(gold, test);
        QVERIFY(metadata->isModified());
    }
}
Beispiel #26
0
void PresetTests::appendToProxyModelTest() {
    const int itemsToGenerate = 5;
    DECLARE_MODELS_AND_GENERATE(itemsToGenerate);
    for (int i = 0; i < itemsToGenerate; i++) {
        auto metadata = artworksListModel.getMockArtwork(i);
        metadata->set("title", "description", QStringList());
    }

    Mocks::ArtworksUpdaterMock updater;
    Models::ArtworkProxyModel proxyModel(commandManager, presetKeywordsModel, updater);
    proxyModel.setSourceArtwork(artworksListModel.getMockArtwork(0), 0);
    artworksListModel.setUpdatesBlocked(false);

    QStringList keywords;
    keywords << "some" << "keywords";

    KeywordsPresets::ID_t id1 = presetKeywordsModel.addItem("test", keywords);
    proxyModel.addPreset(id1);

    QCOMPARE(artworksListModel.getMockArtwork(0)->getKeywords(), keywords);
    QVERIFY(artworksListModel.getMockArtwork(0)->isModified());
}
Beispiel #27
0
void PresetTests::addWithAnotherNameTest() {
    const int itemsToGenerate = 5;
    DECLARE_MODELS_AND_GENERATE(itemsToGenerate);

    const QString presetName = "preset";
    const QStringList keywords = QStringList() << "keyword1" << "test" << "another";

    KeywordsPresets::ID_t id1;
    bool isAdded = false;
    presetKeywordsModel.addOrUpdatePreset(presetName, keywords, id1, isAdded);
    QCOMPARE(isAdded, true);

    KeywordsPresets::ID_t id2;
    bool isAdded2 = false;
    const QStringList keywords2 = QStringList() << "keyword5" << "something" << "here";
    presetKeywordsModel.addOrUpdatePreset(presetName + "1", keywords2, id2, isAdded2);
    QCOMPARE(isAdded2, true);
    QVERIFY(id2 != id1);

    QStringList actualKeyowrds;
    presetKeywordsModel.tryGetPreset(id2, actualKeyowrds);
    QCOMPARE(actualKeyowrds, keywords2);
}
Beispiel #28
0
void PresetTests::appendFromPresetTrivial() {
    const int itemsToGenerate = 5;
    DECLARE_MODELS_AND_GENERATE(itemsToGenerate);
    presetKeywordsModel.addItem();
    presetKeywordsModel.setName(0, QString("keyword_0"));
    presetKeywordsModel.appendKeyword(0, "keyword_1");
    presetKeywordsModel.appendKeyword(0, "keyword_2");
    presetKeywordsModel.appendKeyword(0, "keyword_3");
    presetKeywordsModel.appendKeyword(0, "keyword_4");
    presetKeywordsModel.appendKeyword(0, "keyword_5");

    for (int i = 0; i < itemsToGenerate; i++) {
        auto metadata = artworksListModel.getMockArtwork(i);
        metadata->set("title", "description", QStringList() << "keyword_0" << "keyword_1" << "keyword_2");
    }

    artworksListModel.addPreset(0, 0, presetKeywordsModel)->execute();
    auto metadata = artworksListModel.getMockArtwork(0);
    QStringList finalString;
    finalString << "keyword_0" << "keyword_1" << "keyword_2" << "keyword_3" << "keyword_4" << "keyword_5";
    QCOMPARE(metadata->getKeywords(), finalString);
    QVERIFY(metadata->isModified());
}