void tst_rcc::rcc() { QFETCH(QString, directory); QFETCH(QString, qrcfile); QFETCH(QString, expected); if (!QDir::setCurrent(directory)) { QString message = QString::fromLatin1("Unable to cd from '%1' to '%2'").arg(QDir::currentPath(), directory); QFAIL(qPrintable(message)); } // If the file expectedoutput.txt exists, compare the // console output with the content of that file const QString expected2 = findExpectedFile(expected); QFile expectedFile(expected2); if (!expectedFile.exists()) { qDebug() << "NO EXPECTATIONS? " << expected2; return; } // Launch const QString command = QLatin1String("rcc"); QProcess process; process.start(command, QStringList(qrcfile)); if (!process.waitForFinished()) { const QString path = QString::fromLocal8Bit(qgetenv("PATH")); QString message = QString::fromLatin1("'%1' could not be found when run from '%2'. Path: '%3' "). arg(command, QDir::currentPath(), path); QFAIL(qPrintable(message)); } const QChar cr = QLatin1Char('\r'); const QString err = QString::fromLocal8Bit(process.readAllStandardError()).remove(cr); const QString out = QString::fromLatin1(process.readAllStandardOutput()).remove(cr); if (!err.isEmpty()) { qDebug() << "UNEXPECTED STDERR CONTENTS: " << err; QFAIL("UNEXPECTED STDERR CONTENTS"); } const QChar nl = QLatin1Char('\n'); const QStringList actualLines = out.split(nl); QVERIFY(expectedFile.open(QIODevice::ReadOnly|QIODevice::Text)); const QStringList expectedLines = QString::fromLatin1(expectedFile.readAll()).split(nl); const QString diff = doCompare(actualLines, expectedLines); if (diff.size()) QFAIL(qPrintable(diff)); }
Task::ReportResult GTest_LoadRemoteDocumentTask::report(){ if(t != NULL){ if(!t->hasError()){ QFile expectedFile(expectedDoc), actualFile(t->getLocalUrl()); expectedFile.open(QIODevice::ReadOnly), actualFile.open(QIODevice::ReadOnly); QByteArray expectedContent(expectedFile.readAll()), actualContent(actualFile.readAll()); if(expectedContent != actualContent){ stateInfo.setError(GTest::tr("File %1 content not equal with expected").arg(t->getLocalUrl())); } expectedFile.close(), actualFile.close(); } return ReportResult_Finished; } return ReportResult_Finished; }
// The validate() method validates the MMFF force field using the MMFF94 // Validation Suite from <http://www.ccl.net/cca/data/MMFF94/>. The suite // includes 753 molecules and each is check for correct atom typing, atom // charge assignment, and total energy. void MmffTest::validate() { // open molecule data file chemkit::MoleculeFile dataFile(dataPath + "MMFF94_hypervalent.mol2"); bool ok = dataFile.read(); if(!ok) qDebug() << dataFile.errorString().c_str(); QVERIFY(ok); QCOMPARE(dataFile.moleculeCount(), size_t(753)); // open expected results file QFile expectedFile("mmff94.expected"); if(!expectedFile.open(QFile::ReadOnly)){ qDebug() << expectedFile.errorString(); QFAIL("Failed to open expected data file."); } QDomDocument expectedFileDocument; expectedFileDocument.setContent(&expectedFile); QDomElement expectedMolecule = expectedFileDocument.documentElement().firstChildElement(); QCOMPARE(expectedMolecule.tagName(), QString("molecule")); // validate molecules QList<chemkit::ForceField *> failedMolecules; foreach(const boost::shared_ptr<chemkit::Molecule> &molecule, dataFile.molecules()){ bool failed = false; // check for correct expected molecule QByteArray name = expectedMolecule.attribute("name").toAscii(); QCOMPARE(name.constData(), molecule->name().c_str()); // create mmff force field chemkit::ForceField *forceField = chemkit::ForceField::create("mmff"); QVERIFY(forceField); // add molecule and setup force field forceField->setMolecule(molecule.get()); bool setup = forceField->setup(); if(!setup){ //failed = true; } // verify atoms int atomCount = forceField->atomCount(); int expectedAtomCount = expectedMolecule.attribute("atomCount").toInt(); if(atomCount != expectedAtomCount){ failed = true; } QDomElement expectedAtom = expectedMolecule.firstChildElement(); QCOMPARE(expectedAtom.tagName(), QString("atom")); foreach(const chemkit::ForceFieldAtom *forceFieldAtom, forceField->atoms()){ std::string type = forceFieldAtom->type(); QByteArray expectedType = expectedAtom.attribute("type").toAscii(); if(type != expectedType.constData()){ failed = true; } double charge = forceFieldAtom->charge(); double expectedCharge = expectedAtom.attribute("charge").toDouble(); double chargeDifference = std::abs(charge - expectedCharge); if(chargeDifference > 0.1){ failed = true; } expectedAtom = expectedAtom.nextSiblingElement(); } // verify energy double energy = forceField->energy(); double expectedEnergy = expectedMolecule.attribute("energy").toDouble(); double energyDifference = std::abs(energy - expectedEnergy); if(energyDifference > 1.0){ failed = true; } // move expected molecule to next molecule element expectedMolecule = expectedMolecule.nextSiblingElement(); if(failed){ failedMolecules.append(forceField); } else{ delete forceField; } } // write actual results file if any molecules failed if(failedMolecules.size() > 0){ QFile actualFile("mmff94.actual"); actualFile.open(QFile::WriteOnly); actualFile.write("<molecules>\n"); foreach(chemkit::ForceField *forceField, failedMolecules){ const chemkit::Molecule *molecule = forceField->molecule(); actualFile.write(QString(" <molecule name=\"%1\" energy=\"%2\" atomCount=\"%3\">\n") .arg(molecule->name().c_str()) .arg(forceField->energy()) .arg(forceField->atomCount()) .toAscii()); foreach(const chemkit::ForceFieldAtom *forceFieldAtom, forceField->atoms()){ actualFile.write(QString(" <atom type=\"%1\" charge=\"%2\"/>\n") .arg(forceFieldAtom->type().c_str()) .arg(forceFieldAtom->charge()) .toAscii()); } actualFile.write(" </molecule>\n"); delete forceField; } actualFile.write("</molecules>\n"); actualFile.close(); }
void KopeteMessage_Test::testLinkParser() { QString basePath = QString::fromLatin1( SRCDIR ) + QString::fromLatin1("/link-parser-testcases"); QDir testCasesDir(basePath); QStringList inputFileNames = testCasesDir.entryList(QStringList(QLatin1String("*.input"))); for ( QStringList::ConstIterator it = inputFileNames.constBegin(); it != inputFileNames.constEnd(); ++it) { QString fileName = *it; QString outputFileName = fileName; outputFileName.replace("input","output"); // open the input file QFile inputFile(basePath + QString::fromLatin1("/") + fileName); QFile expectedFile(basePath + QString::fromLatin1("/") + outputFileName); // check if the expected output file exists // if it doesn't, skip the testcase if ( ! expectedFile.exists() ) { QSKIP("Warning! expected output for testcase not found. Skiping testcase", SkipSingle); continue; } if ( inputFile.open( QIODevice::ReadOnly ) && expectedFile.open( QIODevice::ReadOnly )) { QTextStream inputStream(&inputFile); QTextStream expectedStream(&expectedFile); QString inputData; QString expectedData; inputData = inputStream.readAll(); expectedData = expectedStream.readAll(); inputFile.close(); expectedFile.close(); // use a concrete url inputData.replace( "$URL","http://www.kde.org" ); expectedData.replace( "$URL","http://www.kde.org" ); // set message format for parsing according to textcase filename convention Qt::TextFormat format; if ( fileName.section('-', 1, 1) == QString::fromLatin1("plaintext") ) format = Qt::PlainText; else format = Qt::RichText; QString result = Kopete::Message::parseLinks( inputData, format ); // HACK to know the test case we applied, concatenate testcase name to both // input and expected string. WIll remove when I can add some sort of metadata // to a QCOMPARE so debug its origin testcase result = fileName + QString::fromLatin1(": ") + result; expectedData = fileName + QString::fromLatin1(": ") + expectedData; // if the test case begins with broken, we expect it to fail, then use XFAIL // otherwise use QCOMPARE if ( fileName.section('-', 0, 0) == QString::fromLatin1("broken") ) { //kDebug() << "checking known-broken testcase: " << fileName; QEXPECT_FAIL("", "Checking know-broken testcase", Continue); QCOMPARE(result, expectedData); } else { //kDebug() << "checking known-working testcase: " << fileName; QCOMPARE(result, expectedData); } } else { QSKIP("Warning! can't open testcase files for. Skiping testcase", SkipSingle); continue; } } }