Example #1
0
void visualTests() {
	Set s;
	Set t;
	int i;
	createEmptySet(&s);
	showOutput("The set constructed with the default constructor: ", &s);

	for (i = 0; i < 10; i += 1) {
	  insertSet(&s, i);
	}
	showOutput("The set should be {0, ..., 9}:  ", &s);
	
	// test Insert() and Contains() with '<<'
	for (i = 0; i < 10; i += 1) {
		insertSet(&s, i);
	}
	showOutput("The set should be {0, ..., 9}:  ", &s);

	createCopySet(&t, &s);
	showOutput("The copy of s constructed with the copy constructor = ", &t);

	randomSet(&t);
	showOutput("The random set generated equals = ", &t);

	printf("The visual tests are over\n"); 
	destroySet(&s);
	destroySet(&t);
}
Example #2
0
static void readBody(HttpConn *conn)
{
    char    buf[HTTP_BUFSIZE];
    ssize   bytes;

    while (!conn->error && conn->sock && (bytes = httpRead(conn, buf, sizeof(buf))) > 0) {
        showOutput(conn, buf, bytes);
    }
}
Example #3
0
  void AdvancedScriptManager::displayScriptExecLog(QString name) {
    tblExecute->clear();
    setupHeaderLog();
    tblExecute->setRowCount(0);
    unsigned int rowCount =0;
    QSqlQuery query;
    query.exec("SELECT * FROM TSCRIPT_HISTORY WHERE SCRIPT = '" + name + "'");
    QString strLine;
    int i =0;
    int totalTime = 0;
    KIcon icnEye(KStandardDirs::locate( "appdata", "pixmap/22x22/eye.png"));
    while (query.next())  {
      QTableWidgetItem* anItem = new QTableWidgetItem();
      QTableWidgetItem* aDateStart = new QTableWidgetItem();
      QTableWidgetItem* aDateEnd = new QTableWidgetItem();
      
      QDateTime aDateTime;
      aDateTime.setTime_t(query.value(2).toString().toUInt());
      QString date = aDateTime.toString("dd/MM/yyyy hh:mm:ss");
      
      aDateStart->setText(date);
      anItem->setText(query.value(1).toString());
      
      QDateTime aDateTime2;
      aDateTime2.setTime_t(query.value(3).toString().toUInt());
      QString date2 = aDateTime2.toString("dd/MM/yyyy hh:mm:ss");
      aDateEnd->setText(date2);
      
      OutputViewerButton* btnView = new OutputViewerButton(0);
      btnView->setText("View");
      btnView->setIcon(icnEye);
      btnView->setStyleSheet("margin:-5px;spacing:0px;height:25px;min-height:25px;max-height:25px;");
      btnView->setMinimumSize(80, 25);
      btnView->setMaximumSize(9999, 25);
      btnView->id = query.value(0).toInt();
      if (KStandardDirs::exists(KStandardDirs::locateLocal("appdata", "/output/"+QString::number(query.value(0).toInt()))) == false)
        btnView->setDisabled(true);
      QObject::connect(btnView, SIGNAL(clicked(uint)), this, SLOT(showOutput(uint)));

      tblExecute->setRowCount(++rowCount);
      tblExecute->setItem(rowCount-1,0,anItem);
      tblExecute->setItem(rowCount-1,1,aDateStart);
      tblExecute->setItem(rowCount-1,2,aDateEnd);
      tblExecute->setCellWidget(rowCount-1, 3, btnView);
      tblExecute->setRowHeight(rowCount-1, 20);
      
      i++;
      totalTime += query.value(3).toString().toUInt() - query.value(2).toString().toUInt();
    }
    
    if (i != 0)
      lblMoyExecTimeValue->setText(QString::number(totalTime / i) + " second"); 
    else
       lblMoyExecTimeValue->setText("N/A");
  }
void CvsProcessWidget::slotReceivedOutput( QString someOutput )
{
    kdDebug(9006) << "CvsProcessWidget::slotReceivedOutput(QString)  here!" << endl;
#ifdef MYDCOPDEBUG
    g_dcopOutCounter++;
    kdDebug(9006) << "MYDCOPDEBUG: dcopOutCounter == " << g_dcopOutCounter << endl;
#endif

    QStringList strings = m_outputBuffer.process( someOutput );
    if (strings.count() > 0)
    {
        m_output += strings;
        showOutput( strings );
        scrollToBottom();
    }
}
Example #5
0
  void AdvancedScriptManager::displayScriptVersion(QString name) {
    tblVersion->clear();
    setupHeaderVersion();
    tblVersion->setRowCount(0);
    unsigned int rowCount =0;
    QSqlQuery query;
    query.exec("SELECT * FROM TSCRIPT_VERSION WHERE NAME = '" + name + "'");
    QString strLine;
    KIcon icnEye(KStandardDirs::locate( "appdata", "pixmap/22x22/eye.png"));
    int i =0;
    while (query.next())  {
      QTableWidgetItem* anItem = new QTableWidgetItem();
      QTableWidgetItem* aDate = new QTableWidgetItem();
      
      QDateTime aDateTime;
      aDateTime.setTime_t(query.value(2).toString().toUInt());
      QString date = aDateTime.toString("dd/MM/yyyy hh:mm:ss");
      
      aDate->setText(date);
      anItem->setText(query.value(1).toString());
      
      OutputViewerButton* btnView = new OutputViewerButton(0);
      btnView->setText("View");
      btnView->setIcon(icnEye);
      btnView->setStyleSheet("margin:-5px;spacing:0px;height:25px;min-height:25px;max-height:25px;");
      btnView->setMinimumSize(80, 25);
      btnView->setMaximumSize(9999, 25);
      btnView->id = query.value(0).toInt();
      if (KStandardDirs::exists(KStandardDirs::locateLocal("appdata", "/output/"+QString::number(query.value(0).toInt()))) == false)
        btnView->setDisabled(true);
      QObject::connect(btnView, SIGNAL(clicked(uint)), this, SLOT(showOutput(uint)));

      tblVersion->setRowCount(++rowCount);
      tblVersion->setItem(rowCount-1,0,aDate);
      tblVersion->setCellWidget(rowCount-1, 1, btnView);
      tblVersion->setRowHeight(rowCount-1, 20);
      i++;
    }
    lblNbEditionValue->setText(QString::number(i) + " time");
  }
void showOutput(std::ostringstream& output, bool showIfGraphical, bool showIfConsole) {
    showOutput(output.str(), showIfGraphical, showIfConsole);
    output.str("");   // clear output
}
Example #7
0
static int doRequest(MprHttp *http, cchar *url, MprList *fields, MprList *files)
{
    MprHttpResponse *resp;
    MprKeyValue     *header;
    char            buf[MPR_HTTP_BUFSIZE], seqBuf[16], *responseHeaders, *redirect;
    int64           contentLen;
    int             code, next, count, bytes, transCount;

    mprAssert(url && *url);

    mprLog(http, MPR_DEBUG, "fetch: %s %s", method, url);

    /*
     *  Send the request
     */
    count = -1;
    transCount = 0;
    do {
        for (next = 0; (header = mprGetNextItem(headers, &next)) != 0; ) {
            mprSetHttpHeader(http, 0, header->key, header->value);
        }
        if (sequence) {
            static int next = 0;
            mprItoa(seqBuf, sizeof(seqBuf), next++, 10);
            mprSetHttpHeader(http, 1, "X-Http-Seq", seqBuf);
        }
        if (ranges) {
            mprSetHttpHeader(http, 1, "Range", ranges);
        }
        if (fields) {
            mprSetHttpHeader(http, 1, "Content-Type", "application/x-www-form-urlencoded");
        }
        if (chunkSize) {
            mprSetHttpChunked(http, 1);
        }
        if (setContentLength(http, fields, files) < 0) {
            return MPR_ERR_CANT_OPEN;
        }
        if (mprStartHttpRequest(http, method, url) < 0) {
            mprError(http, "Can't process request for \"%s\". %s", url, mprGetHttpError(http));
            return MPR_ERR_CANT_OPEN;
        }
        /*
         *  This program does not do full-duplex writes with reads. ie. if you have a request that sends and receives
         *  data in parallel -- http will do the writes first then read the response.
         */
        if (files || fields) {
            if (writeBody(http, fields, files) < 0) {
                mprError(http, "Can't write body data to \"%s\". %s", url, mprGetHttpError(http));
                return MPR_ERR_CANT_WRITE;
            }
        } else {
            if (chunkSize) {
                mprFinalizeHttpWriting(http);
            }
            mprWaitForHttpResponse(http, -1);
        }
#if WIN
        _setmode(fileno(stdout), O_BINARY);
#endif
        while ((bytes = mprReadHttp(http, buf, sizeof(buf))) > 0) {
            showOutput(http, buf, bytes);
        }
        mprWaitForHttp(http, MPR_HTTP_STATE_COMPLETE, -1);
        /* May not be complete if a disconnect occurs */
        if (http->state >= MPR_HTTP_STATE_CONTENT) {
            if (mprNeedHttpRetry(http, &redirect)) {
                if (redirect) {
                    url = resolveUrl(http, redirect);
                }
                count--;
                transCount++;
                continue;
            }
            break;
        }
    } while (++count < http->retries && transCount < 4 && !mprIsExiting(http));

    if (count >= http->retries) {
        mprError(http, "http: failed \"%s\" request for %s after %d attempt(s)", method, url, count);
        return MPR_ERR_TOO_MANY;
    }
    if (mprIsExiting(http)) {
        return MPR_ERR_BAD_STATE;
    }

    /*
     *  Request now complete
     */
    code = mprGetHttpCode(http);
    contentLen = mprGetHttpContentLength(http);

    mprLog(http, 6, "Response code %d, content len %d", code, contentLen);

    if (http->response) {
        if (showCode) {
            mprPrintf(http, "%d\n", code);
        }
        if (showHeaders) {
            responseHeaders = mprGetHttpHeaders(http);
            resp = http->response;
            mprPrintf(http, "%s %d %s\n", resp->protocol, resp->code, resp->message);
            mprPrintf(http, "%s\n", responseHeaders);
            mprFree(responseHeaders);
        }
    }

    if (code < 0) {
        mprError(http, "Can't process request for \"%s\" %s", url, mprGetHttpError(http));
        return MPR_ERR_CANT_READ;

    } else if (code == 0 && http->protocolVersion == 0) {
        ;

    } else if (!(200 <= code && code <= 206) && !(301 <= code && code <= 304)) {
        if (!showCode) {
            mprError(http, "Can't process request for \"%s\" (%d) %s", url, code, mprGetHttpError(http));
            return MPR_ERR_CANT_READ;
        }
    }

    lock();
    if (verbose && noout) {
        trace(http, url, fetchCount, method, code, (int) contentLen);
    }
    unlock();
    return 0;
}