diff --git a/libs/odf/tests/TestStorage.cpp b/libs/odf/tests/TestStorage.cpp index f2e3e88091..5ea955e1f4 100644 --- a/libs/odf/tests/TestStorage.cpp +++ b/libs/odf/tests/TestStorage.cpp @@ -1,257 +1,257 @@ /* This file is part of the KDE project Copyright (C) 2002 Werner Trobin Copyright (C) 2008 Thomas Zander This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include #include #include #include #include #include #include #include class TestStorage : public QObject { Q_OBJECT private Q_SLOTS: void storage_data(); void storage(); void storage2_data(); void storage2(); private: char getch(QIODevice * dev); }; char TestStorage::getch(QIODevice * dev) { char c = 0; dev->getChar(&c); return c; } void TestStorage::storage_data() { QTest::addColumn("type"); QTest::addColumn("testFile"); QTest::newRow("directory") << (int) KoStore::Directory << "testdir"; QTest::newRow("zip") << (int) KoStore::Zip <<"test.zip"; } void TestStorage::storage() { const char test1[] = "This test checks whether we're able to write to some arbitrary directory.\n"; const char testDir[] = "0"; const char testDirResult[] = "0/"; const char test2[] = "This time we try to append the given relative path to the current dir.\n"; const char test3[] = "Hello World"; const char testDir2[] = "test2/with/a"; const char testDir2Result[] = "0/test2/with/a/"; const char test4[] = "Heureka, it works"; QFETCH(int, type); QFETCH(QString, testFile); KoStore::Backend backend = static_cast(type); if (QFile::exists(testFile)) QFile::remove(testFile); QDir dirTest(testFile); if (dirTest.exists()) { #ifdef Q_OS_UNIX QByteArray ba = QByteArray("rm -rf ") + QFile::encodeName(testFile); - system(ba.constData()); // QDir::rmdir isn't recursive! + Q_UNUSED(system(ba.constData())); // QDir::rmdir isn't recursive! #else QFAIL("build dir not empty"); #endif } KoStore* store = KoStore::createStore(testFile, KoStore::Write, "", backend); QVERIFY(store); QVERIFY(store->bad() == false); if (store->isEncrypted()) store->setPassword("password"); QVERIFY(store->open("test1/with/a/relative/dir.txt")); for (int i = 0; i < 100; ++i) store->write(test1, strlen(test1)); store->close(); store->enterDirectory(testDir); QCOMPARE(store->currentPath(), QString(testDirResult)); QVERIFY(store->open("test2/with/a/relative/dir.txt")); for (int i = 0; i < 100; ++i) store->write(test2, strlen(test2)); store->close(); QVERIFY(store->open("root")); store->write(test3, strlen(test3)); store->close(); store->enterDirectory(testDir2); QCOMPARE(store->currentPath(), QString(testDir2Result)); QVERIFY(store->open("root")); store->write(test4, strlen(test4)); store->close(); if (store->isOpen()) store->close(); delete store; store = KoStore::createStore(testFile, KoStore::Read, "", backend); QVERIFY(store->bad() == false); if (store->isEncrypted()) store->setPassword("password"); QVERIFY (store->open("test1/with/a/relative/dir.txt")); QIODevice* dev = store->device(); int i = 0, lim = strlen(test1), count = 0; while (static_cast(getch(dev)) == test1[i++]) { if (i == lim) { i = 0; ++count; } } store->close(); QCOMPARE(count, 100); store->enterDirectory(testDir); QCOMPARE (store->currentPath(), QString(testDirResult)); QVERIFY (store->open("test2/with/a/relative/dir.txt")); dev = store->device(); i = 0; lim = strlen(test2); count = 0; while (static_cast(getch(dev)) == test2[i++]) { if (i == lim) { i = 0; ++count; } } store->close(); QCOMPARE(count, 100); store->enterDirectory(testDir2); store->pushDirectory(); while (store->leaveDirectory()) { ; } store->enterDirectory(testDir); QCOMPARE (store->currentPath(), QString(testDirResult)); QVERIFY (store->open("root")); QCOMPARE (store->size(), (qint64) 22); dev = store->device(); QByteArray dataReadBack = dev->read(strlen(test3)); store->close(); QCOMPARE (dataReadBack, QByteArray(test3)); store->popDirectory(); QCOMPARE(store->currentPath(), QString(testDir2Result)); QVERIFY (store->hasFile("relative/dir.txt")); QVERIFY (store->open("root")); char buf[29]; store->read(buf, 28); buf[28] = '\0'; store->close(); QVERIFY(strncmp(buf, test4, 28) == 0); if (store->isOpen()) store->close(); delete store; QFile::remove(testFile); } #define DATALEN 64 void TestStorage::storage2_data() { QTest::addColumn("type"); QTest::addColumn("testFile"); QTest::newRow("directory") << (int) KoStore::Directory << "testdir"; QTest::newRow("zip") << (int) KoStore::Zip <<"test.zip"; } void TestStorage::storage2() { QFETCH(int, type); QFETCH(QString, testFile); KoStore::Backend backend = static_cast(type); if (QFile::exists(testFile)) QFile::remove(testFile); QDir dirTest(testFile); if (dirTest.exists()) { #ifdef Q_OS_UNIX QByteArray ba = QByteArray("rm -rf ") + QFile::encodeName(testFile); - system(ba.constData()); // QDir::rmdir isn't recursive! + Q_UNUSED(system(ba.constData())); // QDir::rmdir isn't recursive! #else QFAIL("build dir not empty"); #endif } KoStore* store = KoStore::createStore(testFile, KoStore::Write, "", backend); QVERIFY(store->bad() == false); // Write QVERIFY (store->open("layer")); char str[DATALEN]; sprintf(str, "1,2,3,4\n"); store->write(str, strlen(str)); memset(str, '\0', DATALEN); store->write(str, DATALEN); store->close(); delete store; store = KoStore::createStore(testFile, KoStore::Read, "", backend); QVERIFY(store->bad() == false); // Read back QVERIFY (store->open("layer")); char str2[DATALEN]; QIODevice *stream = store->device(); // << Possible suspect! stream->readLine(str2, DATALEN); // << as is this qint64 len = store->read(str2, DATALEN); QCOMPARE(len, (qint64) DATALEN); store->close(); delete store; QFile::remove(testFile); } QTEST_GUILESS_MAIN(TestStorage) #include