qt5/src/Doxyfile | 2 qt5/src/poppler-private.h | 2 qt5/tests/CMakeLists.txt | 1 qt5/tests/Makefile.am | 13 + qt5/tests/stress-threads-qt5.cpp | 304 +++++++++++++++++++++++++++++++++++++++ qt5/tests/test-poppler-qt5.cpp | 2 6 files changed, 320 insertions(+), 4 deletions(-)
New commits: commit 9d0a5b6afb25a1273504383e108bdb95ca82f099 Author: Albert Astals Cid <[email protected]> Date: Tue Jun 18 23:19:30 2013 +0200 Bring changes from the qt4 dir diff --git a/qt5/src/Doxyfile b/qt5/src/Doxyfile index f89d5f7..8a6e6d9 100644 --- a/qt5/src/Doxyfile +++ b/qt5/src/Doxyfile @@ -31,7 +31,7 @@ PROJECT_NAME = "Poppler Qt5" # This could be handy for archiving the generated documentation or # if some version control system is used. -PROJECT_NUMBER = 0.23.0 +PROJECT_NUMBER = 0.23.2 # The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) # base path where the generated documentation will be put. diff --git a/qt5/src/poppler-private.h b/qt5/src/poppler-private.h index 172c988..0a132f0 100644 --- a/qt5/src/poppler-private.h +++ b/qt5/src/poppler-private.h @@ -88,7 +88,7 @@ namespace Poppler { wchar_t *fileName = new WCHAR[filePath.length()]; int length = filePath.toWCharArray(fileName); doc = new PDFDoc(fileName, length, ownerPassword, userPassword); - delete fileName; + delete[] fileName; #else GooString *fileName = new GooString(QFile::encodeName(filePath)); doc = new PDFDoc(fileName, ownerPassword, userPassword); diff --git a/qt5/tests/CMakeLists.txt b/qt5/tests/CMakeLists.txt index 4e2d05f..dfeb1fb 100644 --- a/qt5/tests/CMakeLists.txt +++ b/qt5/tests/CMakeLists.txt @@ -52,6 +52,7 @@ qt5_add_simpletest(poppler-fonts poppler-fonts.cpp) qt5_add_simpletest(poppler_attachments poppler-attachments.cpp) qt5_add_simpletest(stress-poppler-qt5 stress-poppler-qt5.cpp) qt5_add_simpletest(stress-poppler-dir stress-poppler-dir.cpp) +qt5_add_simpletest(stress-threads-qt5 stress-threads-qt5.cpp) qt5_add_simpletest(poppler-texts poppler-texts.cpp) qt5_add_qtest(check_attachments check_attachments.cpp) diff --git a/qt5/tests/Makefile.am b/qt5/tests/Makefile.am index d787a6b..be9fa44 100644 --- a/qt5/tests/Makefile.am +++ b/qt5/tests/Makefile.am @@ -19,7 +19,8 @@ SUFFIXES: .moc noinst_PROGRAMS = test-poppler-qt5 stress-poppler-qt5 \ poppler-fonts test-password-qt5 stress-poppler-dir \ - poppler-attachments poppler-texts + poppler-attachments poppler-texts poppler-forms \ + stress-threads-qt5 test_poppler_qt5_SOURCES = \ @@ -49,6 +50,11 @@ poppler_texts_SOURCES = \ poppler_texts_LDADD = $(LDADDS) +poppler_forms_SOURCES = \ + poppler-forms.cpp + +poppler_forms_LDADD = $(LDADDS) + stress_poppler_qt5_SOURCES = \ stress-poppler-qt5.cpp @@ -60,6 +66,11 @@ stress_poppler_dir_SOURCES = \ stress_poppler_dir_LDADD = $(LDADDS) +stress_threads_qt5_SOURCES = \ + stress-threads-qt5.cpp + +stress_threads_qt5_LDADD = $(LDADDS) + clean-generic: rm -f *.moc diff --git a/qt5/tests/stress-threads-qt5.cpp b/qt5/tests/stress-threads-qt5.cpp new file mode 100644 index 0000000..2a24a35 --- /dev/null +++ b/qt5/tests/stress-threads-qt5.cpp @@ -0,0 +1,304 @@ + +#include <unistd.h> +#include <time.h> + +#include <poppler-qt5.h> +#include <poppler-form.h> + +#include <QtCore/QDebug> +#include <QtCore/QFile> +#include <QtCore/QMutex> +#include <QtCore/QThread> +#include <QtGui/QImage> + +class SillyThread : public QThread +{ +public: + SillyThread(Poppler::Document* document, QObject* parent = 0); + + void run(); + +private: + Poppler::Document* m_document; + QVector< Poppler::Page* > m_pages; + +}; + +class CrazyThread : public QThread +{ +public: + CrazyThread(uint seed, Poppler::Document* document, QMutex* annotationMutex, QObject* parent = 0); + + void run(); + +private: + uint m_seed; + Poppler::Document* m_document; + QMutex* m_annotationMutex; + +}; + +static Poppler::Page* loadPage(Poppler::Document* document, int index) +{ + Poppler::Page* page = document->page(index); + + if(page == 0) + { + qDebug() << "!Document::page"; + + exit(EXIT_FAILURE); + } + + return page; +} + +static Poppler::Page* loadRandomPage(Poppler::Document* document) +{ + return loadPage(document, qrand() % document->numPages()); +} + +SillyThread::SillyThread(Poppler::Document* document, QObject* parent) : QThread(parent), + m_document(document), + m_pages() +{ + m_pages.reserve(m_document->numPages()); + + for(int index = 0; index < m_document->numPages(); ++index) + { + m_pages.append(loadPage(m_document, index)); + } +} + + +void SillyThread::run() +{ + forever + { + foreach(Poppler::Page* page, m_pages) + { + QImage image = page->renderToImage(); + + if(image.isNull()) + { + qDebug() << "!Page::renderToImage"; + + ::exit(EXIT_FAILURE); + } + } + } +} + +CrazyThread::CrazyThread(uint seed, Poppler::Document* document, QMutex* annotationMutex, QObject* parent) : QThread(parent), + m_seed(seed), + m_document(document), + m_annotationMutex(annotationMutex) +{ +} + +void CrazyThread::run() +{ + typedef QScopedPointer< Poppler::Page > PagePointer; + + qsrand(m_seed); + + forever + { + if(qrand() % 2 == 0) + { + qDebug() << "search..."; + + PagePointer page(loadRandomPage(m_document)); + + page->search("c", Poppler::Page::CaseInsensitive); + page->search("r", Poppler::Page::CaseSensitive); + page->search("a", Poppler::Page::CaseInsensitive); + page->search("z", Poppler::Page::CaseSensitive); + page->search("y", Poppler::Page::CaseInsensitive); + } + + if(qrand() % 2 == 0) + { + qDebug() << "links..."; + + PagePointer page(loadRandomPage(m_document)); + + QList< Poppler::Link* > links = page->links(); + + qDeleteAll(links); + } + + if(qrand() % 2 == 0) + { + qDebug() << "form fields..."; + + PagePointer page(loadRandomPage(m_document)); + + QList< Poppler::FormField* > formFields = page->formFields(); + + qDeleteAll(formFields); + } + + if(qrand() % 2 == 0) + { + qDebug() << "thumbnail..."; + + PagePointer page(loadRandomPage(m_document)); + + page->thumbnail(); + } + + if(qrand() % 2 == 0) + { + qDebug() << "text..."; + + PagePointer page(loadRandomPage(m_document)); + + page->text(QRectF(QPointF(), page->pageSizeF())); + } + + if(qrand() % 2 == 0) + { + QMutexLocker mutexLocker(m_annotationMutex); + + qDebug() << "add annotation..."; + + PagePointer page(loadRandomPage(m_document)); + + Poppler::Annotation* annotation = 0; + + switch(qrand() % 3) + { + default: + case 0: + annotation = new Poppler::TextAnnotation(qrand() % 2 == 0 ? Poppler::TextAnnotation::Linked : Poppler::TextAnnotation::InPlace); + break; + case 1: + annotation = new Poppler::HighlightAnnotation(); + break; + case 2: + annotation = new Poppler::InkAnnotation(); + break; + } + + annotation->setBoundary(QRectF(0.0, 0.0, 0.5, 0.5)); + annotation->setContents("crazy"); + + page->addAnnotation(annotation); + + delete annotation; + } + + if(qrand() % 2 == 0) + { + QMutexLocker mutexLocker(m_annotationMutex); + + for(int index = 0; index < m_document->numPages(); ++index) + { + PagePointer page(loadPage(m_document, index)); + + QList< Poppler::Annotation* > annotations = page->annotations(); + + if(!annotations.isEmpty()) + { + qDebug() << "modify annotation..."; + + annotations.at(qrand() % annotations.size())->setBoundary(QRectF(0.5, 0.5, 0.25, 0.25)); + annotations.at(qrand() % annotations.size())->setAuthor("foo"); + annotations.at(qrand() % annotations.size())->setContents("bar"); + annotations.at(qrand() % annotations.size())->setCreationDate(QDateTime::currentDateTime()); + annotations.at(qrand() % annotations.size())->setModificationDate(QDateTime::currentDateTime()); + } + + qDeleteAll(annotations); + + if(!annotations.isEmpty()) + { + break; + } + } + } + + if(qrand() % 2 == 0) + { + QMutexLocker mutexLocker(m_annotationMutex); + + for(int index = 0; index < m_document->numPages(); ++index) + { + PagePointer page(loadPage(m_document, index)); + + QList< Poppler::Annotation* > annotations = page->annotations(); + + if(!annotations.isEmpty()) + { + qDebug() << "remove annotation..."; + + page->removeAnnotation(annotations.takeAt(qrand() % annotations.size())); + } + + qDeleteAll(annotations); + + if(!annotations.isEmpty()) + { + break; + } + } + } + + if(qrand() % 2 == 0) + { + qDebug() << "fonts..."; + + m_document->fonts(); + } + } +} + +int main(int argc, char** argv) +{ + if(argc < 5) + { + qDebug() << "usage: stress-threads-qt duration sillyCount crazyCount file(s)"; + + return EXIT_FAILURE; + } + + const int duration = atoi(argv[1]); + const int sillyCount = atoi(argv[2]); + const int crazyCount = atoi(argv[3]); + + qsrand(time(0)); + + for(int argi = 4; argi < argc; ++argi) + { + const QString file = QFile::decodeName(argv[argi]); + Poppler::Document* document = Poppler::Document::load(file); + + if(document == 0) + { + qDebug() << "Could not load" << file; + continue; + } + + if(document->isLocked()) + { + qDebug() << file << "is locked"; + continue; + } + + for(int i = 0; i < sillyCount; ++i) + { + (new SillyThread(document))->start(); + } + + QMutex* annotationMutex = new QMutex(); + + for(int i = 0; i < crazyCount; ++i) + { + (new CrazyThread(qrand(), document, annotationMutex))->start(); + } + } + + sleep(duration); + + return EXIT_SUCCESS; +} diff --git a/qt5/tests/test-poppler-qt5.cpp b/qt5/tests/test-poppler-qt5.cpp index 985b920..d16728b 100644 --- a/qt5/tests/test-poppler-qt5.cpp +++ b/qt5/tests/test-poppler-qt5.cpp @@ -148,7 +148,7 @@ int main( int argc, char **argv ) argc > 3) { // use argument as file name - qWarning() << "usage: test-poppler-qt filename [-extract|-arthur|-textRects]"; + qWarning() << "usage: test-poppler-qt5 filename [-extract|-arthur|-textRects]"; exit(1); } _______________________________________________ poppler mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/poppler
