void OcaOctaveController::readStdout() { char buf[ 1024 ]; //fprintf( stderr, "OcaOctaveController::readStdout $$$ %d (%d)\n", result, m_pipeFd ); int result = -1; do { result = read( m_pipeFd, buf, 1023 ); if( 0 < result ) { //fprintf( stderr, "OcaOctaveController::readStdout\n" ); //fwrite( buf, 1, result, stderr ); //fprintf( stderr, "OcaOctaveController::readStdout - END\n" ); buf[ result ] = 0; m_stdoutBuf += QString::fromLocal8Bit( buf ); QStringList lines = m_stdoutBuf.split( '\n' ); m_stdoutBuf = lines.takeLast(); //Q_ASSERT( ! lines.isEmpty() ); /* if( '\n' != m_stdoutBuf[ m_stdoutBuf.length() - 1 ] ) { m_stdoutBuf = lines.takeLast(); } else { m_stdoutBuf.clear(); QString s = lines.takeLast(); Q_ASSERT( s.isEmpty() ); } */ while( ! lines.isEmpty() ) { QString s = lines.takeFirst(); //fprintf( stderr, "readStdout: %s\n", s.toLocal8Bit().data() ); emit outputReceived( s, 0 ); } } } while( ( 1023 == result ) && ( e_StateReady == m_state ) ); }
void OcaOctaveController::runCommand( const QString& command, OcaTrackGroup* group ) { if( e_StateReady == m_state ) { m_state = e_StateWaiting; m_lastError = 0; m_lastErrorString.clear(); QStringList list = command.split( '\n' ); QString command_fixed; for( int i = 0; i < list.size(); i++ ) { QString s = list.at(i).trimmed(); if( ! s.isEmpty() ) { if( ! command_fixed.isEmpty() ) { command_fixed.append( '\n' ); } command_fixed.append( s ); } } fprintf( stderr, "OcaOctaveController => WAITING\n" ); addCommandToHistory( command_fixed ); m_host->evalCommand( command_fixed, group ); emit readyStateChanged( false, 0 ); } else { emit outputReceived( "OcaOctaveController::runCommand failed: not ready", 128 ); fprintf( stderr, "OcaOctaveController => ERROR (not ready)\n" ); } }
void OcaOctaveController::onListenerStateChanged( int listener_state ) { if( ( e_StateReady != m_state ) && ( 1 == listener_state ) ) { m_state = e_StateReady; #ifndef Q_OS_WIN32 readStdout(); #endif if( 0 != m_lastError ) { emit outputReceived( m_lastErrorString, m_lastError ); } fprintf( stderr, "OcaOctaveController => READY\n" ); emit readyStateChanged( true, 0 ); } else { Q_ASSERT( false ); } }
/*! called whenever tests fails with given \param message and \param backtrace */ void Server::onFail( const QString& message, const QString& backtrace ) { TestFunction* testFunction = _testCase ? _testCase->getCurrentTestFunction() : 0; Message* messageObject = new Message( message, backtrace ); if ( testFunction ) { testFunction->fail( messageObject ); } // in case of Syntax error else { delete _failedMessage; _failedMessage = messageObject; } emit failMessageAdded( messageObject, testFunction ); // TODO to be removed (still used in MainWindow for output display) emit outputReceived(); }
/*! called whenever a message from the client is received */ void Server::onMessageReceived() { QDataStream in(_localSocket); in.setVersion(QDataStream::Qt_4_0); // read all while ( !in.atEnd() ) { QString testFunctionName, message, backtrace, actual, expected, testCaseName; TestFunction* testFunction = 0; Message* messageObject = 0; int type; // parse message and build internal data model in >> type; switch ( type ) { case Test::WARN: in >> message >> backtrace; testFunction = _testCase ? _testCase->getCurrentTestFunction() : 0; Q_ASSERT( testFunction ); messageObject = new Message( message, backtrace ); testFunction->addWarnMessage( messageObject ); emit warnMessageAdded( messageObject, testFunction ); break; case Test::FAIL: in >> message >> backtrace; onFail( message, backtrace ); break; case Test::FUNCTION_START: in >> testFunctionName; Q_ASSERT( _testCase ); testFunction = new TestFunction( testFunctionName ); _testCase->addTestFunction( testFunction ); emit testFunctionStarted( testFunction ); break; case Test::FUNCTION_PASS: testFunction = _testCase ? _testCase->getCurrentTestFunction() : 0; Q_ASSERT( testFunction ); testFunction->pass(); emit testFunctionPassed( testFunction ); break; case Test::TESTCASE_START: delete _testCase; in >> testCaseName; _testCase = new TestCase( testCaseName, this ); emit testCaseStarted( _testCase ); break; case Test::TESTCASE_END: emit testCaseEnded( _testCase ); break; } } // TODO to be removed (still used in MainWindow for output display) emit outputReceived(); }
void ProcessHandler::printProcessOutput() { QString out = myProcess->readAll(); qDebug() << "Proc out: " << out; emit outputReceived(out); }