Beispiel #1
0
void Tests::basicTests()
{
    // Some basic tests to save our COMBINE archive either directly or to a
    // different file and checking that its contents is sound

    QString otherFileName = OpenCOR::Core::temporaryFileName();

    doBasicTests();
    doBasicTests(otherFileName);

    // Check that we can load our other COMBINE archive and save it in yet
    // another file

    OpenCOR::COMBINESupport::CombineArchive otherCombineArchive(otherFileName);

    QString yetAnotherFileName = OpenCOR::Core::temporaryFileName();

    QVERIFY(otherCombineArchive.load());
    QVERIFY(otherCombineArchive.isValid());
    QVERIFY(otherCombineArchive.save(yetAnotherFileName));

    // Unzip our two COMBINE archives and make sure that their contents is the
    // same
    // Note: the original plan was to check that the SHA-1 value of the two
    //       files was the same, but the fact is that the ZIP file format
    //       contains various date and time information, so the SHA-1 value of
    //       two files may be different...

    QTemporaryDir temporaryDir;
    QString otherDir = temporaryDir.path()+"/otherDir";
    QString yetAnotherDir = temporaryDir.path()+"/yetAnotherDir";
    OpenCOR::ZIPSupport::QZipReader otherZipReader(otherFileName);
    OpenCOR::ZIPSupport::QZipReader yetAnotherZipReader(yetAnotherFileName);

    QVERIFY(otherZipReader.extractAll(otherDir));
    QVERIFY(yetAnotherZipReader.extractAll(yetAnotherDir));

    QDirIterator dirIterator(otherDir, QStringList() << "*",
                             QDir::Files, QDirIterator::Subdirectories);

    while (dirIterator.hasNext()) {
        QString otherFileName = dirIterator.next();
        QString yetAnotherFileName = otherFileName.replace(otherDir, yetAnotherDir);
        QByteArray otherFileContents;
        QByteArray yetAnotherFileContents;

        QVERIFY(OpenCOR::Core::readFileContentsFromFile(otherFileName, otherFileContents));
        QVERIFY(OpenCOR::Core::readFileContentsFromFile(yetAnotherFileName, yetAnotherFileContents));

        QCOMPARE(OpenCOR::Core::sha1(otherFileContents),
                 OpenCOR::Core::sha1(yetAnotherFileContents));
    }

    // Clean up after ourselves

    QFile::remove(otherFileName);
    QFile::remove(yetAnotherFileName);
}
// ---------------------------------------------------------------------------
//  Test entry point
// ---------------------------------------------------------------------------
bool testValueVector()
{
    XERCES_STD_QUALIFIER wcout  << L"----------------------------------\n"
                << L"Testing ValueVectorOf template class\n"
                << L"----------------------------------" << XERCES_STD_QUALIFIER endl;

    bool retVal = true;

    try
    {
        // Do the basic suite of tests, which is templatized
        if (!doBasicTests())
            retVal = false;

        // Test the enumerator
        XERCES_STD_QUALIFIER wcout << L"Testing ValueVectorEnumerator" << XERCES_STD_QUALIFIER endl;
        if (!enumTests())
        {
            XERCES_STD_QUALIFIER wcout << L"ValueVectorEnumeration failed" << XERCES_STD_QUALIFIER endl;
            retVal = false;
        }
         else
        {
            XERCES_STD_QUALIFIER wcout << L"ValueVectorEnumeration passed" << XERCES_STD_QUALIFIER endl;
        }
        XERCES_STD_QUALIFIER wcout << XERCES_STD_QUALIFIER endl;
    }

    catch(const XMLException& toCatch)
    {
        XERCES_STD_QUALIFIER wcout  << L"  ERROR: Unexpected exception!\n   Msg: "
                    << toCatch.getMessage() << XERCES_STD_QUALIFIER endl;
        return false;
    }

    return retVal;
}