Esempio n. 1
0
 bool JsonSingleValue::value(uint32_t& value) const
 {
     return parseUnsignedInteger(value);
 }
void QTestLibArgsParser::parse(bool incremental)
{
    if (!incremental)
        initDefaults();

    QStringList knownFlags;
    // Output flag
    knownFlags << QLatin1String("o");
    // ParserFormat flags
    knownFlags << QLatin1String("txt") << QLatin1String("csv") << QLatin1String("xunitxml") << QLatin1String("xml") << QLatin1String("lightxml");
    // Verbosity flags
    knownFlags << QLatin1String("silent") << QLatin1String("") << QLatin1String("v1") << QLatin1String("v2") << QLatin1String("vs") << QLatin1String("vb");
    // Options affecting output
    knownFlags << QLatin1String("functions") << QLatin1String("datatags") << QLatin1String("help") << QLatin1String("perfcounterlist");
    // Other test flags
    knownFlags << QLatin1String("eventdelay") << QLatin1String("keydelay") << QLatin1String("mousedelay") << QLatin1String("maxwarnings") << QLatin1String("nocrashhandler");
    // Other benchmark flags
    knownFlags << QLatin1String("callgrind") << QLatin1String("perf") << QLatin1String("perfcounter") << QLatin1String("tickcounter") << QLatin1String("eventcounter") << QLatin1String("minimumvalue") << QLatin1String("minimumtotal") << QLatin1String("iterations") << QLatin1String("median");

    int currentFlag = -1;
    QString token;

    while (!(token = nextToken()).isNull()) {
        qDebug() << token;
        if (currentFlag == -1) {
            // Token is not a flag argument
            if (token.startsWith(QLatin1Char('-')))
                currentFlag = knownFlags.indexOf(token.mid(1));
            else
                currentFlag = -2;
            qDebug() << currentFlag;
            switch (currentFlag) {
            case -2: // Test case name?
                parseSelectedTest(token);
                break;
            case -1: // Unknown flag
                mError = UnknownFlagError;
                mErrorString = QCoreApplication::translate("QTestLibPlugin::Internal::QTestLibArgsParser", "Unknown flag \"%1\"").arg(token);
                break;
            case 7: // Impossible
                Q_ASSERT(false);
            case 0: // -o
                continue;
            case 1: // -txt
            case 2: // -csv
            case 3: // -xunitxml
            case 4: // -xml
            case 5: // -lightXml
                if (!mSeenOutputWithFormat)
                    mParser = (TestOutputFormat) currentFlag;
                break;
            case 6: // -silent
            case 8: // -v1
            case 9: // -v2
            case 10: // -vs
            case 11: // -vb
                mVerbosity = (TestVerbosity) (currentFlag - 7);
                break;
            case 12: // -functions
                if (mOutput == NormalOutput) {
                    mParser = NoneFormat;
                    mOutput = FunctionsOutput;
                }
                break;
            case 13: // -datatags
                if (mOutput == NormalOutput) {
                    mParser = NoneFormat;
                    mOutput = DataTagsOutput;
                }
                break;
            case 14: // -help
                if (mOutput == NormalOutput) {
                    mParser = NoneFormat;
                    mOutput = HelpOutput;
                }
                break;
            case 15: // -perfcounterlist
                if (mOutput == NormalOutput) {
                    mParser = NoneFormat;
                    mOutput = PerfCounterNamesOutput;
                }
                break;
            case 16: // -eventdelay
            case 17: // -keydelay
            case 18: // -mousedelay
            case 19: // -maxwarnings
                continue;
            case 20: // -nocrashhandler
                mCrashHandlerEnabled = false;
                break;
            default:
                qWarning() << "Benchmark flags are not supported yet";
                break;
            }
        } else {
            // Token is a flag argument
            switch(currentFlag) {
            case 0: // -o
                parseOutput(token);
                break;
            case 16: // -eventdelay
                mEventDelay = parseInteger(token, mEventDelay);
                break;
            case 17: // -keydelay
                mKeyDelay = parseInteger(token, mKeyDelay);
                break;
            case 18: // -mousedelay
                mMouseDelay = parseInteger(token, mMouseDelay);
                break;
            case 19: // -maxwarnings
                mMaxWarnings = parseUnsignedInteger(token, mMaxWarnings);
                break;
            }
        }
        currentFlag = -1;
    }

    if (currentFlag != -1) {
        mError = PrematureEndError;
        mErrorString = QCoreApplication::translate("QTestLibPlugin::Internal::QTestLibArgsParser", "String of command line arguments ended prematurely");
    }
}