⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 staf.cpp

📁 Software Testing Automation Framework (STAF)的开发代码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
        // Make sure we are still in a valid table        if (thisObj->type() != kSTAFMapObject) return false;        if (thisObj->get(sMapClassKey)->asString() != mapClassName)            return false;        // Update table info with this object        for (clIter = columnList.begin(); clIter != columnList.end(); ++clIter)        {            STAFObjectPtr thisValueObj = thisObj->get(clIter->key);            if ((thisValueObj->type() != kSTAFScalarStringObject) &&                (thisValueObj->type() != kSTAFNoneObject))            {                if (gStrictTables) return false;            }            unsigned int thisItemColumnWidth =                thisObj->get(clIter->key)->asString().length(STAFString::kChar);            ++clIter->sizeCounts[STAF_MIN(maxSizeCount, thisItemColumnWidth)];            for (unsigned int columnIndex = 0, columnWidth = 1;                 columnIndex < gMaxTableWidth;                 ++columnIndex, ++columnWidth)            {                // At least one line is needed even if the length of an entry                // in the table is 0 (e.g. due to an empty string, etc.)                unsigned int linesNeeded = STAF_MAX(                    1, thisItemColumnWidth / columnWidth);                                if (thisItemColumnWidth % columnWidth != 0)                    ++linesNeeded;                linesNeeded = STAF_MIN(linesNeeded, gMaxLinesPerTableRecord);                                ++clIter->cwLineCounts[columnIndex][linesNeeded - 1];                clIter->cwLineSums[columnIndex] += linesNeeded;                for (unsigned int lineIndex = linesNeeded - 1;                     lineIndex < gMaxLinesPerTableRecord + 1;                     ++lineIndex)                {                    ++clIter->cwLineCountSums[columnIndex][lineIndex];                }            }            clIter->maxValueLength = STAF_MAX(clIter->maxValueLength,                                              thisItemColumnWidth);        }    }        // Now determine appropriate column widths    unsigned int minimumTableWidth = (columnList.size() - 1) *                                     gColumnSeparator.length(STAFString::kChar);    unsigned int maximumTableWidth = minimumTableWidth;    for (clIter = columnList.begin(); clIter != columnList.end(); ++clIter)    {        minimumTableWidth += clIter->shortHeaderLength;        clIter->minimumWidth = clIter->shortHeaderLength;        if (clIter->longHeaderLength > clIter->maxValueLength)        {            maximumTableWidth += clIter->longHeaderLength;            clIter->maximumWidth = clIter->longHeaderLength;        }        else        {            maximumTableWidth += clIter->maxValueLength;            clIter->maximumWidth = clIter->maxValueLength;        }        clIter->width = clIter->maximumWidth;    }    // Check to make sure the table will fit at its minimum size        if (minimumTableWidth > gMaxTableWidth) return false;    // Adjust column sizings if necessary    if (maximumTableWidth > gMaxTableWidth)    {        unsigned int remainingTableWidth = gMaxTableWidth - minimumTableWidth;        if (gDebug)            cout << "remainingWidth: " << remainingTableWidth << endl;        // Initialize test width data in columns        unsigned int index = 0;        for (index = 0; index < columnList.size(); ++index)        {            columnList[index].currTestWidth = columnList[index].minimumWidth;            columnList[index].bestTestWidth = columnList[index].minimumWidth;            columnList[index].maxTestWidth =                columnList[index].minimumWidth + remainingTableWidth;        }        // Update last column to start testing with the maximum width        columnList[columnList.size() - 1].currTestWidth =            columnList[columnList.size() - 1].maxTestWidth;        // Now evaluate the different permutations        do        {            evalColumnWidths(columnList);        } while (incColumnTestWidths(columnList, remainingTableWidth));        // Now, set width to bestTestWidth and update headers if necessary        for (clIter = columnList.begin(); clIter != columnList.end(); ++clIter)        {            clIter->width = clIter->bestTestWidth;            if (clIter->width < clIter->longHeaderLength)                clIter->header = clIter->shortHeader;        }    }    if (gDebug) dumpTableColumnList(columnList);    // Now, print out the table header    for (clIter = columnList.begin(); clIter != columnList.end();)    {        cout << clIter->header;        unsigned int spacesNeeded =            clIter->width - clIter->header.length(STAFString::kChar);        while (spacesNeeded > gSpaces.length())        {            cout << gSpaces;            spacesNeeded -= gSpaces.length();        }        cout << gSpaces.subString(0, spacesNeeded);        if (++clIter != columnList.end())            cout << gColumnSeparator;    }    cout << endl;        for (clIter = columnList.begin(); clIter != columnList.end();)    {        unsigned int hyphensNeeded = clIter->width;        while (hyphensNeeded > gHyphens.length())        {            cout << gHyphens;            hyphensNeeded -= gHyphens.length();        }        cout << gHyphens.subString(0, hyphensNeeded);        if (++clIter != columnList.end())            cout << gColumnSeparator;    }        cout << endl;    // Now, loop through and print out each object        for (iter = objPtr->iterate (); iter->hasNext();)    {        STAFObjectPtr thisObj = iter->next();        bool done = false;        for (unsigned int lineNum = 0;             !done && lineNum < gMaxLinesPerTableRecord;             ++lineNum)        {            done = true;            for (clIter = columnList.begin(); clIter != columnList.end();)            {                STAFString thisColumnFullString =                    thisObj->get(clIter->key)->asString();                if (thisColumnFullString.length(STAFString::kChar) >                    (lineNum + 1) * clIter->width)                {                    done = false;                }                STAFString thisColumnString = thisColumnFullString.subString(                    clIter->width * lineNum, clIter->width, STAFString::kChar);                if ((lineNum == gMaxLinesPerTableRecord - 1) && !done)                {                    cout << "(More...)";                }                else                {                    cout << thisColumnString.replace(gCR, gSpace)                            .replace(gLF, gSpace).replace(gTab, gSpace);                }                unsigned int spacesNeeded =                    clIter->width - thisColumnString.length(STAFString::kChar);                while (spacesNeeded > gSpaces.length())                {                    cout << gSpaces;                    spacesNeeded -= gSpaces.length();                }                cout << gSpaces.subString(0, spacesNeeded);                if (++clIter != columnList.end())                    cout << gColumnSeparator;            }            cout << endl;        }    }        return true;}void printResult(const STAFString &resultString){    // Update display settings    if ((getenv("STAF_PRINT_MODE") != 0) && !gPrintModeLocked)    {        STAFString pMode = STAFString(getenv("STAF_PRINT_MODE")).lowerCase();        if      (pMode == "verbose") gPrintMode = kPMVerbose;        else if (pMode == "auto")    gPrintMode = kPMAuto;        else if (pMode == "raw")     gPrintMode = kPMRaw;    }    if (getenv("STAF_PRINT_NO_TABLES") != 0)        gPrintTables = false;    if (getenv("STAF_NO_STRICT_TABLES") != 0)        gStrictTables = false;    if (getenv("STAF_IGNORE_INDIRECT_OBJECTS") != 0)        gUnmarshallingFlags = kSTAFIgnoreIndirectObjects;    if (getenv("STAF_INDENT_DELTA") != 0)    {        STAFString indentDeltaString = getenv("STAF_INDENT_DELTA");        try { gIndentDelta = indentDeltaString.asUInt(); }        catch (...) { /* Do nothing */ }    }    if (getenv("STAF_TABLE_WIDTH") != 0)    {        STAFString tableWidth = getenv("STAF_TABLE_WIDTH");        try { gMaxTableWidth = tableWidth.asUInt(); }        catch (...) { /* Do nothing */ }    }    if (getenv("STAF_TABLE_LINES_PER_RECORD") != 0)    {        STAFString linesPerRecord = getenv("STAF_TABLE_LINES_PER_RECORD");        try { gMaxLinesPerTableRecord = linesPerRecord.asUInt(); }        catch (...) { /* Do nothing */ }    }    // Now output the data    // If requested, just dump out the literal string returned    if (gPrintMode == kPMRaw)    {        cout << resultString;        return;    }    // Otherwise, unmarshall the result and go from there    STAFObjectPtr objPtr = STAFObject::unmarshall(resultString,                                                  gUnmarshallingFlags);    if (gPrintMode == kPMAuto)    {        if (!printSimple(objPtr->getRootObject(), objPtr) &&            !printTable(objPtr->getRootObject(), objPtr))        {            printVerbose(objPtr->getRootObject(), objPtr, 0);        }    }    else    {        printVerbose(objPtr->getRootObject(), objPtr, 0);    }}int main(int argc, char **argv){    if (argc < 4)    {        cout << "Usage: STAF [-verbose] <Endpoint | LOCAL> <Service> "             << "<Request>" << endl;        return 1;    }    unsigned int argsBase = 1;    if (STAFString(argv[1]).lowerCase() == "-verbose")    {        gPrintMode = kPMVerbose;        gPrintModeLocked = true;        argsBase += 1;    }    unsigned int verboseOutput = (getenv("STAF_QUIET_MODE") == 0) ? 1 : 0;    unsigned int staticHandle = 0;    if (getenv("STAF_STATIC_HANDLE") != 0)        staticHandle = strtoul(getenv("STAF_STATIC_HANDLE"), 0, 10);        STAFHandlePtr handlePtr;    unsigned int rc = 0;    if (staticHandle != 0)        rc = STAFHandle::create(staticHandle, handlePtr);    else        rc = STAFHandle::create("STAF/Client", handlePtr);    if (rc != 0)    {        cout << "Error registering with STAF, RC: " << rc << endl;        return rc;    }    STAFString request;    for (int i = argsBase + 2; i < (argc - 1); i++)    {        request += massageArgument(argv[i]) + STAFString(" ");    }    request += massageArgument(argv[argc - 1]);    STAFResultPtr result = handlePtr->submit(argv[argsBase], argv[argsBase + 1],                                             request, kSTAFReqSync);    if (getenv("STAF_REPLACE_NULLS") != 0)    {        STAFString replaceNullStr = getenv("STAF_REPLACE_NULLS");        result->result = result->result.replace(kUTF8_NULL, replaceNullStr);        result->result = result->result.replace(kUTF8_NULL2, replaceNullStr);    }    if (result->rc != 0)    {        if (verboseOutput)        {            cout << "Error submitting request, RC: " << result->rc << endl;            if (result->result.length() != 0)            {                cout << "Additional info" << endl << "---------------" << endl;                printResult(result->result);                cout << endl;            }        }        else printResult(result->result);        return result->rc;    }    if (verboseOutput)    {        cout << "Response" << endl << "--------" << endl;        printResult(result->result);        cout << endl;    }    else printResult(result->result);    return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -