bool CSourceEmitter::createSourcesAtPath(const ParseContext& context, const std::string& outputBasePath) {
        Three::CCodeGenVisitor visitor;

        context.rootNode()->accept(visitor);

        std::ofstream bodyFile(outputBasePath + ".c");

        assert(bodyFile);

        // make sure to import the headers
        visitor.addInternalHeader(true, outputBasePath + ".h");
        visitor.addDeclarationsHeader(true, outputBasePath + "_internal.h");

        bodyFile << "// Declarations" << std::endl;
        bodyFile << visitor.declarationsString();
        bodyFile << std::endl << "// Definitions" << std::endl;
        bodyFile << visitor.bodyString();

        std::ofstream internalHeaderFile(outputBasePath + "_internal.h");

        internalHeaderFile << Three::CSource::includeGuard("");
        internalHeaderFile << visitor.internalHeaderString();

        std::ofstream externalHeaderFile(outputBasePath + ".h");

        externalHeaderFile << Three::CSource::includeGuard("");
        externalHeaderFile << visitor.externalHeaderString();

        return true;
    }
Exemple #2
0
bool TestHTTPServer::wait(const QUrl &expect, const QUrl &reply, const QUrl &body)
{
    m_state = AwaitingHeader;
    m_data.clear();

    QFile expectFile(expect.toLocalFile());
    if (!expectFile.open(QIODevice::ReadOnly)) return false;

    QFile replyFile(reply.toLocalFile());
    if (!replyFile.open(QIODevice::ReadOnly)) return false;

    bodyData = QByteArray();
    if (body.isValid()) {
        QFile bodyFile(body.toLocalFile());
        if (!bodyFile.open(QIODevice::ReadOnly)) return false;
        bodyData = bodyFile.readAll();
    }

    const QByteArray serverHostUrl = QByteArrayLiteral("127.0.0.1:") + QByteArray::number(server.serverPort());

    QByteArray line;
    bool headers_done = false;
    while (!(line = expectFile.readLine()).isEmpty()) {
        line.replace('\r', "");
        if (line.at(0) == '\n') {
            headers_done = true;
            continue;
        }
        if (headers_done) {
            waitData.body.append(line);
        } else {
            line.replace("{{ServerHostUrl}}", serverHostUrl);
            waitData.headers.append(line);
        }
    }
    /*
    while (waitData.endsWith('\n'))
        waitData = waitData.left(waitData.count() - 1);
        */

    replyData = replyFile.readAll();

    if (!replyData.endsWith('\n'))
        replyData.append("\n");
    replyData.append("Content-length: " + QByteArray::number(bodyData.length()));
    replyData .append("\n\n");

    for (int ii = 0; ii < replyData.count(); ++ii) {
        if (replyData.at(ii) == '\n' && (!ii || replyData.at(ii - 1) != '\r')) {
            replyData.insert(ii, '\r');
            ++ii;
        }
    }
    replyData.append(bodyData);

    return true;
}
BodyMeasures::BodyMeasures(QDir dir, bool withData) : dir(dir), withData(withData) {
    // don't load data if not requested
    if (!withData) return;

    // get body measurements if the file exists
    QFile bodyFile(QString("%1/bodymeasures.json").arg(dir.canonicalPath()));
    if (bodyFile.exists()) {
        QList<BodyMeasure> bodyData;
        if (BodyMeasureParser::unserialize(bodyFile, bodyData)){
            setBodyMeasures(bodyData);
        }
    }
}
Exemple #4
0
bool TestHTTPServer::wait(const QUrl &expect, const QUrl &reply, const QUrl &body)
{
    m_hasFailed = false;

    QFile expectFile(expect.toLocalFile());
    if (!expectFile.open(QIODevice::ReadOnly)) return false;
    
    QFile replyFile(reply.toLocalFile());
    if (!replyFile.open(QIODevice::ReadOnly)) return false;

    bodyData = QByteArray();
    if (body.isValid()) {
        QFile bodyFile(body.toLocalFile());
        if (!bodyFile.open(QIODevice::ReadOnly)) return false;
        bodyData = bodyFile.readAll();
    }

    waitData = expectFile.readAll();
    /*
    while (waitData.endsWith('\n'))
        waitData = waitData.left(waitData.count() - 1);
        */

    replyData = replyFile.readAll();

    if (!replyData.endsWith('\n'))
        replyData.append("\n");
    replyData.append("Content-length: " + QByteArray::number(bodyData.length()));
    replyData .append("\n\n");

    for (int ii = 0; ii < replyData.count(); ++ii) {
        if (replyData.at(ii) == '\n' && (!ii || replyData.at(ii - 1) != '\r')) {
            replyData.insert(ii, '\r');
            ++ii;
        }
    }
    replyData.append(bodyData);

    return true;
}