示例#1
0
    inline std::size_t listTests( Config const& config ) {
        if( config.filters().empty() )
            std::cout << "All available test cases:\n";
        else
            std::cout << "Matching test cases:\n";

        std::size_t matchedTests = 0;
        TextAttributes nameAttr, tagsAttr;
        nameAttr.setInitialIndent( 2 ).setIndent( 4 );
        tagsAttr.setIndent( 6 );

        std::vector<TestCase> const& allTests = getRegistryHub().getTestCaseRegistry().getAllTests();
        for( std::vector<TestCase>::const_iterator it = allTests.begin(), itEnd = allTests.end();
                it != itEnd;
                ++it )
            if( matchesFilters( config.filters(), *it ) ) {
                matchedTests++;
                TestCaseInfo const& testCaseInfo = it->getTestCaseInfo();
                Colour::Code colour = testCaseInfo.isHidden
                    ? Colour::SecondaryText
                    : Colour::None;
                Colour colourGuard( colour );

                std::cout << Text( testCaseInfo.name, nameAttr ) << std::endl;
                if( !testCaseInfo.tags.empty() )
                    std::cout << Text( testCaseInfo.tagsAsString, tagsAttr ) << std::endl;
            }

        if( config.filters().empty() )
            std::cout << pluralise( matchedTests, "test case" ) << "\n" << std::endl;
        else
            std::cout << pluralise( matchedTests, "matching test case" ) << "\n" << std::endl;
        return matchedTests;
    }
示例#2
0
/*!
    \internal
*/
void QDirIteratorPrivate::advance()
{
    while (!fileEngineIterators.isEmpty()) {

        // Find the next valid iterator that matches the filters.
        while (fileEngineIterators.top()->hasNext()) {
            QAbstractFileEngineIterator *it = fileEngineIterators.top();
            it->next();

            const QFileInfo info = it->currentFileInfo();
            checkAndPushDirectory(it->currentFileInfo());

            if (matchesFilters(it->currentFileName(), info)) {
                currentFileInfo = nextFileInfo;
                nextFileInfo = info;

                //We found a matching entry.
                return;
            }
        }

        delete fileEngineIterators.pop();
    }

    currentFileInfo = nextFileInfo;
    nextFileInfo = QFileInfo();
}
示例#3
0
/*!
    \internal
*/
void QDirIteratorPrivate::advance()
{
    // Store the current entry
    if (!fileEngineIterators.isEmpty())
        currentFilePath = fileEngineIterators.top()->currentFilePath();

    // Advance to the next entry
    if (followNextDir) {
        // Start by navigating into the current directory.
        followNextDir = false;

        QAbstractFileEngineIterator *it = fileEngineIterators.top();

        QString subDir = it->currentFilePath();
#ifdef Q_OS_WIN
        if (currentFileInfo.isSymLink())
            subDir = currentFileInfo.canonicalFilePath();
#endif
        pushSubDirectory(subDir, it->nameFilters(), it->filters());
    }

    while (!fileEngineIterators.isEmpty()) {
        QAbstractFileEngineIterator *it = fileEngineIterators.top();

        // Find the next valid iterator that matches the filters.
        bool foundDirectory = false;
        while (it->hasNext()) {
            it->next();
            if (matchesFilters(it)) {
                currentFileInfo = nextFileInfo;
                nextFileInfo = it->currentFileInfo();
                // Signal that we want to follow this entry.
                followNextDir = shouldFollowDirectory(nextFileInfo);
                //We found a matching entry.
                return;

            } else if (iteratorFlags & QDirIterator::Subdirectories) {
                QFileInfo fileInfo = it->currentFileInfo();

                if (!shouldFollowDirectory(fileInfo))
                    continue;
                QString subDir = it->currentFilePath();
#ifdef Q_OS_WIN
                if (fileInfo.isSymLink())
                    subDir = fileInfo.canonicalFilePath();
#endif
                pushSubDirectory(subDir, it->nameFilters(), it->filters());
                
                foundDirectory = true;
                break;
            }
        }
        if (!foundDirectory)
            delete fileEngineIterators.pop();
    }
    currentFileInfo = nextFileInfo;
    done = true;
}
示例#4
0
文件: WDataSrc.cpp 项目: zwvc/wagic-x
bool WSrcCards::setOffset(int pos)
{
    if (pos < 0 || pos >= (int) cards.size()) return false;

    currentPos = pos;
    if (!matchesFilters(cards[currentPos])) return next();

    return true;
}
示例#5
0
文件: WDataSrc.cpp 项目: zwvc/wagic-x
void WSrcCards::validate()
{
    validated.clear();
    updateCounts();
    if (!filtersRoot) return;
    for (size_t t = 0; t < cards.size(); t++)
    {
        if (matchesFilters(cards[t])) validated.push_back(t);
    }
}
示例#6
0
文件: WDataSrc.cpp 项目: zwvc/wagic-x
bool WSrcCards::thisCard(int mtgid)
{
    for (size_t t = 0; t < cards.size(); t++)
    {
        if (cards[t] && cards[t]->getId() == mtgid)
        {
            currentPos = (int) t;
            return matchesFilters(cards[currentPos]);
        }
    }
    return false;
}
示例#7
0
inline bool ZipDirIteratorPrivate::entryMatches(const QString & fileName, CentralDirFileHeader* header)
{
    if (matchesFilters(fileName, header))
    {
        //We found a matching entry.
        currentHeader = nextHeader;
        nextHeader = header;
        return true;
    }

    return false;
}
示例#8
0
    inline std::size_t listTags( Config const& config ) {
        if( config.filters().empty() )
            std::cout << "All available tags:\n";
        else
            std::cout << "Matching tags:\n";
        std::vector<TestCase> const& allTests = getRegistryHub().getTestCaseRegistry().getAllTests();
        std::vector<TestCase>::const_iterator it = allTests.begin(), itEnd = allTests.end();

        std::map<std::string, int> tagCounts;

        std::size_t maxTagLen = 0;

        for(; it != itEnd; ++it ) {
            if( matchesFilters( config.filters(), *it ) ) {
                for( std::set<std::string>::const_iterator  tagIt = it->getTestCaseInfo().tags.begin(),
                                                            tagItEnd = it->getTestCaseInfo().tags.end();
                        tagIt != tagItEnd;
                        ++tagIt ) {
                    std::string tagName = *tagIt;
                    maxTagLen = (std::max)( maxTagLen, tagName.size() );
                    std::map<std::string, int>::iterator countIt = tagCounts.find( tagName );
                    if( countIt == tagCounts.end() )
                        tagCounts.insert( std::make_pair( tagName, 1 ) );
                    else
                        countIt->second++;
                }
            }
        }
        maxTagLen +=4;
        if( maxTagLen > CATCH_CONFIG_CONSOLE_WIDTH-10 )
            maxTagLen = CATCH_CONFIG_CONSOLE_WIDTH-10;

        for( std::map<std::string, int>::const_iterator countIt = tagCounts.begin(), countItEnd = tagCounts.end();
                countIt != countItEnd;
                ++countIt ) {
            Text wrapper( "[" + countIt->first + "]", TextAttributes()
                                                        .setIndent(2)
                                                        .setWidth( maxTagLen ) );
            std::cout << wrapper;
            std::size_t dots = 2;
            if( maxTagLen > wrapper.last().size() )
                dots += maxTagLen - wrapper.last().size();
            {
                Colour colourGuard( Colour::SecondaryText );
                std::cout << std::string( dots, '.' );
            }
            std::cout   << countIt->second
                        << "\n";
        }
        std::cout << pluralise( tagCounts.size(), "tag" ) << "\n" << std::endl;
        return tagCounts.size();
    }
示例#9
0
 inline std::size_t listTestsNamesOnly( Config const& config ) {
     std::size_t matchedTests = 0;
     std::vector<TestCase> const& allTests = getRegistryHub().getTestCaseRegistry().getAllTests();
     for( std::vector<TestCase>::const_iterator it = allTests.begin(), itEnd = allTests.end();
             it != itEnd;
             ++it )
         if( matchesFilters( config.filters(), *it ) ) {
             matchedTests++;
             TestCaseInfo const& testCaseInfo = it->getTestCaseInfo();
             std::cout << testCaseInfo.name << std::endl;
         }
     return matchedTests;
 }
示例#10
0
inline bool QDirIteratorPrivate::entryMatches(const QString & fileName, const QFileInfo &fileInfo)
{
    checkAndPushDirectory(fileInfo);

    if (matchesFilters(fileName, fileInfo)) {
        currentFileInfo = nextFileInfo;
        nextFileInfo = fileInfo;

        //We found a matching entry.
        return true;
    }

    return false;
}
示例#11
0
文件: WDataSrc.cpp 项目: zwvc/wagic-x
//WSrcDeck
int WSrcDeck::loadMatches(MTGDeck * deck)
{
    map<int, int>::iterator it;
    int count = 0;
    if (!deck) return count;
    for (it = deck->cards.begin(); it != deck->cards.end(); it++)
    {
        MTGCard * c = deck->getCardById(it->first);
        if (c && matchesFilters(c))
        {
            Add(c, it->second);
            count++;
        }
    }
    validate();
    return count;
}
示例#12
0
文件: WDataSrc.cpp 项目: zwvc/wagic-x
int WSrcCards::loadMatches(MTGAllCards* ac)
{
    map<int, MTGCard *>::iterator it;
    int count = 0;
    if (!ac) return count;

    for (it = ac->collection.begin(); it != ac->collection.end(); it++)
    {
        if (it->second && (matchesFilters(it->second)))
        {
            cards.push_back(it->second);
            count++;
        }
    }
    validate();
    return count;
}
示例#13
0
    inline std::size_t listTags( Config const& config ) {
        if( config.filters().empty() )
            std::cout << "All available tags:\n";
        else
            std::cout << "Matching tags:\n";

        std::map<std::string, int> tagCounts;

        std::vector<TestCase> const& allTests = getRegistryHub().getTestCaseRegistry().getAllTests();
        for( std::vector<TestCase>::const_iterator  it = allTests.begin(),
                                                    itEnd = allTests.end();
                it != itEnd;
                ++it ) {
            if( matchesFilters( config.filters(), *it ) ) {
                for( std::set<std::string>::const_iterator  tagIt = it->getTestCaseInfo().tags.begin(),
                                                            tagItEnd = it->getTestCaseInfo().tags.end();
                        tagIt != tagItEnd;
                        ++tagIt ) {
                    std::string tagName = *tagIt;
                    std::map<std::string, int>::iterator countIt = tagCounts.find( tagName );
                    if( countIt == tagCounts.end() )
                        tagCounts.insert( std::make_pair( tagName, 1 ) );
                    else
                        countIt->second++;
                }
            }
        }

        for( std::map<std::string, int>::const_iterator countIt = tagCounts.begin(),
                                                        countItEnd = tagCounts.end();
                countIt != countItEnd;
                ++countIt ) {
            std::ostringstream oss;
            oss << "  " << countIt->second << "  ";
            Text wrapper( "[" + countIt->first + "]", TextAttributes()
                                                        .setInitialIndent( 0 )
                                                        .setIndent( oss.str().size() )
                                                        .setWidth( CATCH_CONFIG_CONSOLE_WIDTH-10 ) );
            std::cout << oss.str() << wrapper << "\n";
        }
        std::cout << pluralise( tagCounts.size(), "tag" ) << "\n" << std::endl;
        return tagCounts.size();
    }
示例#14
0
文件: WDataSrc.cpp 项目: zwvc/wagic-x
void WSrcDeck::addCount(MTGCard * c, int qty)
{
    if (!c || !c->data) return;
    map<int, int>::iterator cp = copies.find(c->getMTGId());

    if (matchesFilters(c))
    {
        counts[FILTERED_COPIES] += qty;
        if (qty > 0 && cp != copies.end() && (*cp).second == qty)
            counts[FILTERED_UNIQUE]++;
        else if (qty < 0 && (cp == copies.end() || (*cp).second == 0)) counts[FILTERED_UNIQUE]--;
    }
    counts[UNFILTERED_COPIES] += qty;
    if (qty > 0 && cp != copies.end() && (*cp).second == qty)
        counts[UNFILTERED_UNIQUE]++;
    else if (qty < 0 && (cp == copies.end() || (*cp).second == 0)) counts[UNFILTERED_UNIQUE]--;
    for (int i = Constants::MTG_COLOR_ARTIFACT; i <= Constants::MTG_COLOR_LAND; i++)
        if (c->data->hasColor(i)) counts[i] += qty;
    if (counts[UNFILTERED_MIN_COPIES] < 0 || qty < counts[UNFILTERED_MIN_COPIES]) counts[UNFILTERED_MIN_COPIES] = qty;
    if (qty > counts[UNFILTERED_MAX_COPIES]) counts[UNFILTERED_MAX_COPIES] = qty;
}
示例#15
0
文件: WDataSrc.cpp 项目: zwvc/wagic-x
int WSrcCards::loadMatches(WSrcCards* src, bool all)
{
    int count = 0;
    if (!src) return count;

    MTGCard * c = NULL;

    int oldp = src->getOffset();
    src->setOffset(0);
    for (int t = 0; t < src->Size(all); t++)
    {
        c = src->getCard(t, all);
        if (matchesFilters(c))
        {
            cards.push_back(c);
            count++;
        }
    }
    src->setOffset(oldp);
    validate();
    return count;
}
示例#16
0
/*!
    \internal
*/
void QDirIteratorPrivate::advance()
{
    // Store the current entry
    if (!fileEngineIterators.isEmpty())
        currentFilePath = fileEngineIterators.top()->currentFilePath();

    // Advance to the next entry
    if (followNextDir) {
        // Start by navigating into the current directory.
        followNextDir = false;

        QAbstractFileEngineIterator *it = fileEngineIterators.top();

        QString subDir = it->currentFilePath();
#ifdef Q_OS_WIN
        if (fileInfo.isSymLink())
            subDir = fileInfo.canonicalFilePath();
#endif
        pushSubDirectory(subDir, it->nameFilters(), it->filters());
    }

    if (fileEngineIterators.isEmpty())
        done = true;

    bool foundValidEntry = false;
    while (!fileEngineIterators.isEmpty()) {
        QAbstractFileEngineIterator *it = fileEngineIterators.top();

        // Find the next valid iterator that matches the filters.
        foundValidEntry = false;
        while (it->hasNext()) {
            it->next();
            if (matchesFilters(it)) {
                foundValidEntry = true;
                break;
            }
        }

        if (!foundValidEntry) {
            // If this iterator is done, pop and delete it, and continue
            // iteration on the parent. Otherwise break, we're done.
            if (!fileEngineIterators.isEmpty()) {
                delete it;
                it = fileEngineIterators.pop();
                continue;
            }
            break;
        }

        fileInfo = it->currentFileInfo();

        // If we're doing flat iteration, we're done.
        if (!(iteratorFlags & QDirIterator::Subdirectories))
            break;

        // Subdirectory iteration.
        QString filePath = fileInfo.filePath();

        // Never follow . and ..
        if (fileInfo.fileName() == QLatin1String(".") || fileInfo.fileName() == QLatin1String(".."))
            break;

        // Never follow non-directory entries
        if (!fileInfo.isDir())
            break;
      
        // Check symlinks
        if (fileInfo.isSymLink() && !(iteratorFlags & QDirIterator::FollowSymlinks)) {
            // Follow symlinks only if FollowSymlinks was passed
            break;
        }

        // Stop link loops
        if (visitedLinks.contains(fileInfo.canonicalFilePath()))
            break;

        // Signal that we want to follow this entry.
        followNextDir = true;
        break;
    }

    if (!foundValidEntry)
        done = true;
}
示例#17
0
    inline std::size_t listTests( Config const& config ) {
        if( config.filters().empty() )
            std::cout << "All available test cases:\n";
        else
            std::cout << "Matching test cases:\n";
        std::vector<TestCase> const& allTests = getRegistryHub().getTestCaseRegistry().getAllTests();
        std::vector<TestCase>::const_iterator it = allTests.begin(), itEnd = allTests.end();

        // First pass - get max tags
        std::size_t maxTagLen = 0;
        std::size_t maxNameLen = 0;
        for(; it != itEnd; ++it ) {
            if( matchesFilters( config.filters(), *it ) ) {
                maxTagLen = (std::max)( it->getTestCaseInfo().tagsAsString.size(), maxTagLen );
                maxNameLen = (std::max)( it->getTestCaseInfo().name.size(), maxNameLen );
            }
        }

        // Try to fit everything in. If not shrink tag column first, down to 30
        // then shrink name column until it all fits (strings will be wrapped within column)
        while( maxTagLen + maxNameLen > CATCH_CONFIG_CONSOLE_WIDTH-5 ) {
            if( maxTagLen > 30 )
                --maxTagLen;
            else
                --maxNameLen;
        }

        std::size_t matchedTests = 0;
        for( it = allTests.begin(); it != itEnd; ++it ) {
            if( matchesFilters( config.filters(), *it ) ) {
                matchedTests++;
                Text nameWrapper(   it->getTestCaseInfo().name,
                                    TextAttributes()
                                        .setWidth( maxNameLen )
                                        .setInitialIndent(2)
                                        .setIndent(4) );

                Text tagsWrapper(   it->getTestCaseInfo().tagsAsString,
                                    TextAttributes()
                                        .setWidth( maxTagLen )
                                        .setInitialIndent(0)
                                        .setIndent( 2 ) );

                for( std::size_t i = 0; i < (std::max)( nameWrapper.size(), tagsWrapper.size() ); ++i ) {
                    Colour::Code colour = Colour::None;
                    if( it->getTestCaseInfo().isHidden )
                        colour = Colour::SecondaryText;
                    std::string nameCol;
                    if( i < nameWrapper.size() ) {
                        nameCol = nameWrapper[i];
                    }
                    else {
                        nameCol = "    ...";
                        colour = Colour::SecondaryText;
                    }

                    {
                        Colour colourGuard( colour );
                        std::cout << nameCol;
                    }
                    if( i < tagsWrapper.size() && !tagsWrapper[i].empty() ) {
                        if( i == 0 ) {
                            Colour colourGuard( Colour::SecondaryText );
                            std::cout << "  " << std::string( maxNameLen - nameCol.size(), '.' ) << "  ";
                        }
                        else {
                            std::cout << std::string( maxNameLen - nameCol.size(), ' ' ) << "    ";
                        }
                        std::cout << tagsWrapper[i];
                    }
                    std::cout << "\n";
                }
            }
        }
        if( config.filters().empty() )
            std::cout << pluralise( matchedTests, "test case" ) << "\n" << std::endl;
        else
            std::cout << pluralise( matchedTests, "matching test case" ) << "\n" << std::endl;
        return matchedTests;
    }