TestResult::List XSDTSTestCase::execute(const ExecutionStage, TestSuite*) { ErrorHandler errHandler; ErrorHandler::installQtMessageHandler(&errHandler); TestResult::List retval; TestResult::Status resultStatus = TestResult::Unknown; QString serialized; if (m_testType == SchemaTest) { executeSchemaTest(resultStatus, serialized, &errHandler); } else { executeInstanceTest(resultStatus, serialized, &errHandler); } resultStatus = TestBaseLine::scan(serialized, baseLines()); Q_ASSERT(resultStatus != TestResult::Unknown); m_result = new TestResult(name(), resultStatus, 0, errHandler.messages(), QPatternist::Item::List(), serialized); retval.append(m_result); ErrorHandler::installQtMessageHandler(0); changed(this); return retval; }
void MainWindow::on_actionExecute_triggered() { Q_ASSERT(testCaseView); TestSuite *const ts = static_cast<TestSuite *>(sourceModel()->root()); const TestItem::ExecutionStage stage = compileOnly->isChecked() ? TestItem::CompileOnly : TestItem::CompileAndRun; m_userTC->setLanguage(isXSLT20->isChecked() ? QXmlQuery::XSLT20 : QXmlQuery::XQuery10); if(m_currentTC) { const TestResult::List rlist(m_currentTC->execute(stage, ts)); Q_ASSERT(rlist.count() == 1); const TestResult *const result = rlist.first(); Q_ASSERT(result); testResultView->displayTestResult(result); } else { const QModelIndexList indexes = testSuiteView->selectionModel()->selectedIndexes(); for (int i = 0; i < indexes.count(); ++i) { const QModelIndex source(sourceIndex(indexes.at(i))); TestItem *const ti = static_cast<TestItem *>(source.internalPointer()); if(!ti) return; /* ti is a TestGroup. It now executes its children, changed(TreeItem *) signals is * emitted which the view receives, and thus updates. */ ti->execute(stage, ts); } } }
TestResult::List TestCase::execute(const ExecutionStage stage, TestSuite *) { if(name() == QLatin1String("Constr-cont-document-3")) { TestResult::List result; result.append(createTestResult(TestResult::Fail, QLatin1String("Skipped this test, because we loop infinitely on it."))); return result; } else if(name() == QLatin1String("Axes089")) { TestResult::List result; result.append(createTestResult(TestResult::Fail, QLatin1String("Skipped this test, we crash on it."))); return result; } else if (name() == QLatin1String("op-numeric-unary-minus-1")) { TestResult::List result; result.append(createTestResult(TestResult::Fail, QLatin1String("Skipped this test, we crash on it."))); return result; } else if (name() == QLatin1String("emptyorderdecl-13")) { TestResult::List result; result.append(createTestResult(TestResult::Fail, QLatin1String("Skipped this test, we crash on it."))); return result; } else if (name() == QLatin1String("emptyorderdecl-21")) { TestResult::List result; result.append(createTestResult(TestResult::Fail, QLatin1String("Skipped this test, we crash on it."))); return result; } qDebug() << "Running test case: " << name(); return execute(stage); Q_ASSERT(false); return TestResult::List(); }
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; }