void TestResultView::displayTestResult(const TestResult *const result) { if(!result) { displayNone(); return; } /* ------- the Test Status Label --------- */ resultStatus->setText(result->status() ? TestResult::displayName(result->status()) : QLatin1String("Not Applicable")); /* --------------------------------------- */ /* ------------ the AST View ------------- */ ASTItem *astTree = result->astTree(); static_cast<TreeModel *>(astView->model())->setRoot(astTree); /* --------------------------------------- */ /* ------- the Error code/msg View ------- */ ErrorItem *msgRoot = new ErrorItem(ErrorHandler::Message(), 0); const ErrorHandler::Message::List msgs(result->messages()); ErrorHandler::Message::List::const_iterator it(msgs.constBegin()); const ErrorHandler::Message::List::const_iterator end(msgs.constEnd()); for(; it != end; ++it) msgRoot->appendChild(new ErrorItem(*it, msgRoot)); TreeModel *etm = static_cast<TreeModel *>(messageOutput->model()); etm->setRoot(msgRoot); /* --------------------------------------- */ const QPatternist::Item::List items(result->items()); /* ----- the Serialized Output View ------ */ serializedResult->setPlainText(result->asSerialized()); /* --------------------------------------- */ /* ------ the Item List Output View ------ */ XDTItemItem *itemRoot = new XDTItemItem(QPatternist::Item(), 0); QPatternist::Item item; QPatternist::Item::List::const_iterator itemIt(items.constBegin()); const QPatternist::Item::List::const_iterator itemsEnd(items.constEnd()); for(; itemIt != itemsEnd; ++itemIt) itemRoot->appendChild(new XDTItemItem(*itemIt, itemRoot)); TreeModel *itm = static_cast<TreeModel *>(itemListResult->model()); itm->setRoot(itemRoot); /* --------------------------------------- */ }
TestResult::Status TestBaseLine::scanErrors(const ErrorHandler::Message::List &errors, const TestBaseLine::List &lines) { pDebug() << "TestBaseLine::scanErrors()"; /* 1. Find the first error in @p errors that's a Patternist * error(not warning and not from Qt) and extract the error code. */ QString errorCode; const ErrorHandler::Message::List::const_iterator end(errors.constEnd()); ErrorHandler::Message::List::const_iterator it(errors.constBegin()); for(; it != end; ++it) { if((*it).type() != QtFatalMsg) continue; errorCode = QUrl((*it).identifier()).fragment(); pDebug() << "ERR:" << (*it).description(); /* This is hackish. We have no way of determining whether a Message * is actually issued from Patternist, so we try to narrow it down like this. */ if(errorRegExp()->exactMatch(errorCode)) break; /* It's an error code. */ else errorCode.clear(); } pDebug() << "Got error code: " << errorCode; /* 2. Loop through @p lines, and for the first base line * which is of type ExpectedError and which matches @p errorCode * return Pass, otherwise Fail. */ const TestBaseLine::List::const_iterator blend(lines.constEnd()); TestBaseLine::List::const_iterator blit(lines.constBegin()); for(; blit != blend; ++blit) { const Type t = (*blit)->type(); if(t == TestBaseLine::ExpectedError) { const QString d((*blit)->details()); if(d == errorCode || d == QChar::fromLatin1('*')) return TestResult::Pass; } } return TestResult::Fail; }
TestResult::List TestCase::execute(const ExecutionStage stage) { ErrorHandler errHandler; ErrorHandler::installQtMessageHandler(&errHandler); pDebug() << "TestCase::execute()"; delete m_result; QXmlQuery query(language(), Global::namePoolAsPublic()); query.d->setExpressionFactory(s_exprFact); query.setInitialTemplateName(initialTemplateName()); QXmlQuery openDoc(query.namePool()); if(contextItemSource().isValid()) { openDoc.setQuery(QString::fromLatin1("doc('") + contextItemSource().toString() + QLatin1String("')")); Q_ASSERT(openDoc.isValid()); QXmlResultItems result; openDoc.evaluateTo(&result); const QXmlItem item(result.next()); Q_ASSERT(!item.isNull()); query.setFocus(item); } TestResult::List retval; const Scenario scen(scenario()); TestResult::Status resultStatus = TestResult::Unknown; bool ok = false; const QString queryString(sourceCode(ok)); if(!ok) { /* Loading the query file failed, or similar. */ resultStatus = TestResult::Fail; m_result = new TestResult(name(), resultStatus, s_exprFact->astTree(), errHandler.messages(), QPatternist::Item::List(), QString()); retval.append(m_result); ErrorHandler::installQtMessageHandler(0); changed(this); return retval; } query.setMessageHandler(&errHandler); QXmlNamePool namePool(query.namePool()); /* Bind variables. */ QPatternist::ExternalVariableLoader::Ptr loader(externalVariableLoader()); if(loader) { Q_ASSERT(loader); const ExternalSourceLoader::VariableMap vMap(static_cast<const ExternalSourceLoader *>(loader.data())->variableMap()); const QStringList variables(vMap.keys()); for(int i = 0; i < variables.count(); ++i) { const QXmlName name(namePool, variables.at(i)); const QXmlItem val(QPatternist::Item::toPublic(loader->evaluateSingleton(name, QPatternist::DynamicContext::Ptr()))); query.bindVariable(name, val); } } /* We pass in the testCasePath(), such that the base URI is correct fort * XSL-T stylesheets. */ query.setQuery(queryString, testCasePath()); if(!query.isValid()) { pDebug() << "Got compilation exception."; resultStatus = TestBaseLine::scanErrors(errHandler.messages(), baseLines()); Q_ASSERT(resultStatus != TestResult::Unknown); m_result = new TestResult(name(), resultStatus, s_exprFact->astTree(), errHandler.messages(), QPatternist::Item::List(), QString()); retval.append(m_result); ErrorHandler::installQtMessageHandler(0); changed(this); return retval; } if(stage == CompileOnly) { m_result = new TestResult(name(), TestResult::Fail, s_exprFact->astTree(), errHandler.messages(), QPatternist::Item::List(), QString()); retval.append(m_result); return retval; } Q_ASSERT(stage == CompileAndRun); if(scen == ParseError) /* We're supposed to have received an error at this point. */ { m_result = new TestResult(name(), TestResult::Fail, s_exprFact->astTree(), errHandler.messages(), QPatternist::Item::List(), QString()); ErrorHandler::installQtMessageHandler(0); retval.append(m_result); changed(this); return retval; } QPatternist::Item::List itemList; QByteArray output; QBuffer buffer(&output); buffer.open(QIODevice::WriteOnly); QXmlSerializer serializer(query, &buffer); pDebug() << "-------------------------- evaluateToPushCallback() ---------------------------- "; const bool success = query.evaluateTo(&serializer); pDebug() << "------------------------------------------------------------------------------------ "; buffer.close(); const QString serialized(QString::fromUtf8(output.constData(), output.size())); if(!success) { resultStatus = TestBaseLine::scanErrors(errHandler.messages(), baseLines()); Q_ASSERT(resultStatus != TestResult::Unknown); m_result = new TestResult(name(), resultStatus, s_exprFact->astTree(), errHandler.messages(), QPatternist::Item::List(), serialized); retval.append(m_result); ErrorHandler::installQtMessageHandler(0); changed(this); return retval; } /* It's a regular test. */ Q_ASSERT(scen == Standard || scen == RuntimeError); resultStatus = TestBaseLine::scan(serialized, baseLines()); Q_ASSERT(resultStatus != TestResult::Unknown); /* Check that errHandler()->messages() at most only contains * warnings, since it shouldn't have errors at this point. */ const ErrorHandler::Message::List errors (errHandler.messages()); const ErrorHandler::Message::List::const_iterator end(errors.constEnd()); ErrorHandler::Message::List::const_iterator it(errors.constBegin()); for(; it != end; ++it) { const QtMsgType type = (*it).type(); if(type == QtFatalMsg) { m_result = new TestResult(name(), TestResult::Fail, s_exprFact->astTree(), errHandler.messages(), itemList, serialized); retval.append(m_result); ErrorHandler::installQtMessageHandler(0); changed(this); return retval; } } m_result = new TestResult(name(), resultStatus, s_exprFact->astTree(), errHandler.messages(), itemList, serialized); retval.append(m_result); ErrorHandler::installQtMessageHandler(0); changed(this); return retval; }