From 01f5c74b8ecddfc192895ccb85c1627467bb6ff5 Mon Sep 17 00:00:00 2001 From: mread Date: Fri, 5 Nov 2010 08:10:14 +0000 Subject: Generating QFileOpenEvent messages when S60 UI receives OpenFileL S60 applications can receive OpenFileL requests from other apps in the OpenFileL method of their main document class. This S60 main document class is internal to QtGui, so the request is turned into a QFileOpenEvent for the application to pick up if it want to implenment this service. If an application wants to receive the QFileOpenEvent before UI construction, it should do something like: app->sendPostedEvents(app, QEvent::FileOpen); Task-number: QTBUG-15015 Reviewed-by: Shane Kearns --- src/gui/s60framework/qs60mainappui.cpp | 10 ++++++++++ src/gui/s60framework/qs60mainappui.h | 1 + src/gui/s60framework/qs60maindocument.cpp | 20 +++++++++++++++++--- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/gui/s60framework/qs60mainappui.cpp b/src/gui/s60framework/qs60mainappui.cpp index b5b8b81..454f90d 100644 --- a/src/gui/s60framework/qs60mainappui.cpp +++ b/src/gui/s60framework/qs60mainappui.cpp @@ -49,6 +49,7 @@ #include #endif #include +#include #include #include "qs60mainappui.h" @@ -401,6 +402,15 @@ void QS60MainAppUi::HandleForegroundEventL(TBool aForeground) QS60MainAppUiBase::HandleForegroundEventL(aForeground); } +/*! + \internal +*/ +TBool QS60MainAppUi::ProcessCommandParametersL(TApaCommand /*aCommand*/, TFileName &aDocumentName, const TDesC8 &/*aTail*/) +{ + // bypass CEikAppUi::ProcessCommandParametersL(..) which modifies aDocumentName, preventing apparc document opening from working. + return ConeUtils::FileExists(aDocumentName); +} + #ifndef Q_WS_S60 void QS60StubAknAppUi::HandleViewDeactivation(const TVwsViewId &, const TVwsViewId &) {} diff --git a/src/gui/s60framework/qs60mainappui.h b/src/gui/s60framework/qs60mainappui.h index ce3b5b0..bf118ff 100644 --- a/src/gui/s60framework/qs60mainappui.h +++ b/src/gui/s60framework/qs60mainappui.h @@ -131,6 +131,7 @@ public: virtual void HandleViewDeactivation(const TVwsViewId &aViewIdToBeDeactivated, const TVwsViewId &aNewlyActivatedViewId); virtual void PrepareToExit(); virtual void HandleTouchPaneSizeChange(); + virtual TBool ProcessCommandParametersL(TApaCommand aCommand, TFileName &aDocumentName, const TDesC8 &aTail); protected: virtual void HandleScreenDeviceChangedL(); diff --git a/src/gui/s60framework/qs60maindocument.cpp b/src/gui/s60framework/qs60maindocument.cpp index a8886ac..071aa5b 100644 --- a/src/gui/s60framework/qs60maindocument.cpp +++ b/src/gui/s60framework/qs60maindocument.cpp @@ -41,6 +41,8 @@ #include "qs60mainappui.h" #include "qs60maindocument.h" +#include "qcoreapplication.h" +#include "qevent.h" #include @@ -108,9 +110,15 @@ CEikAppUi *QS60MainDocument::CreateAppUiL() /*! \internal */ -CFileStore *QS60MainDocument::OpenFileL(TBool aDoOpen, const TDesC &aFilename, RFs &aFs) +CFileStore *QS60MainDocument::OpenFileL(TBool aDoOpen, const TDesC &aFilename, RFs &/*aFs*/) { - return QS60MainDocumentBase::OpenFileL(aDoOpen, aFilename, aFs); + if (aDoOpen) { + QCoreApplication* app = QCoreApplication::instance(); + QString qname((QChar*)aFilename.Ptr(), aFilename.Length()); + QFileOpenEvent* event = new QFileOpenEvent(qname); + app->postEvent(app, event); + } + return 0; } /*! @@ -118,7 +126,13 @@ CFileStore *QS60MainDocument::OpenFileL(TBool aDoOpen, const TDesC &aFilename, R */ void QS60MainDocument::OpenFileL(CFileStore *&aFileStore, RFile &aFile) { - QS60MainDocumentBase::OpenFileL(aFileStore, aFile); + QCoreApplication* app = QCoreApplication::instance(); + TFileName name; + aFile.FullName(name); + QString qname((QChar*)name.Ptr(), name.Length()); + QFileOpenEvent* event = new QFileOpenEvent(qname); + app->postEvent(app, event); + aFileStore = 0; } QT_END_NAMESPACE -- cgit v0.12 From edcaa583aa9232f48c92d7c78a7b3e6c71212bc1 Mon Sep 17 00:00:00 2001 From: mread Date: Fri, 5 Nov 2010 10:40:44 +0000 Subject: used official descriptor to QString conversion The OpenFileL code now uses qt_TDesC2QString to convert from the TFileName to a QString. Task-number: QTBUG-15015 Reviewed-by: Shane Kearns --- src/gui/s60framework/qs60maindocument.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/gui/s60framework/qs60maindocument.cpp b/src/gui/s60framework/qs60maindocument.cpp index 071aa5b..95effbc 100644 --- a/src/gui/s60framework/qs60maindocument.cpp +++ b/src/gui/s60framework/qs60maindocument.cpp @@ -43,6 +43,7 @@ #include "qs60maindocument.h" #include "qcoreapplication.h" #include "qevent.h" +#include "private/qcore_symbian_p.h" #include @@ -114,7 +115,7 @@ CFileStore *QS60MainDocument::OpenFileL(TBool aDoOpen, const TDesC &aFilename, R { if (aDoOpen) { QCoreApplication* app = QCoreApplication::instance(); - QString qname((QChar*)aFilename.Ptr(), aFilename.Length()); + QString qname = qt_TDesC2QString(aFilename); QFileOpenEvent* event = new QFileOpenEvent(qname); app->postEvent(app, event); } @@ -129,7 +130,7 @@ void QS60MainDocument::OpenFileL(CFileStore *&aFileStore, RFile &aFile) QCoreApplication* app = QCoreApplication::instance(); TFileName name; aFile.FullName(name); - QString qname((QChar*)name.Ptr(), name.Length()); + QString qname = qt_TDesC2QString(name); QFileOpenEvent* event = new QFileOpenEvent(qname); app->postEvent(app, event); aFileStore = 0; -- cgit v0.12 From 776a9aeaa8006e789d3f956250876867c350a209 Mon Sep 17 00:00:00 2001 From: mread Date: Fri, 5 Nov 2010 13:23:38 +0000 Subject: Added a file handle to QFileOpenEvent on Symbian QFileOpenEvent needs to tell the recipient what file to open. Normally that is by filename. But on Symbian, some files can only be opened from an already-open file handle that has been passed in. For example data caged files in c:\private or z:\sys. So QFileOpenEvent needs to be able to hold a Symbian file handle so that the recipient can access any file requested of it. Coming soon... a method by which the reciever can access the file without knowing about all this messy file handle stuff going on behind the scenes. Task-number: QTBUG-15015 Reviewed-by: Shane Kearns --- src/gui/kernel/qevent.cpp | 28 ++++++++++++++++++++++++++-- src/gui/kernel/qevent.h | 7 +++++++ src/gui/kernel/qevent_p.h | 7 +++++++ src/gui/s60framework/qs60maindocument.cpp | 17 ++++++----------- 4 files changed, 46 insertions(+), 13 deletions(-) diff --git a/src/gui/kernel/qevent.cpp b/src/gui/kernel/qevent.cpp index e7abb47..f7bc54c 100644 --- a/src/gui/kernel/qevent.cpp +++ b/src/gui/kernel/qevent.cpp @@ -53,6 +53,10 @@ #include "qgesture.h" #include "qgesture_p.h" +#ifdef Q_OS_SYMBIAN +#include "private/qcore_symbian_p.h" +#endif + QT_BEGIN_NAMESPACE /*! @@ -3023,7 +3027,7 @@ QShowEvent::~QShowEvent() This event is only used to notify the application of a request. It may be safely ignored. - \note This class is currently supported for Mac OS X only. + \note This class is currently supported for Mac OS X and Symbian only. */ /*! @@ -3049,11 +3053,31 @@ QFileOpenEvent::QFileOpenEvent(const QUrl &url) f = url.toLocalFile(); } +#ifdef Q_OS_SYMBIAN +/*! \internal +*/ +QFileOpenEvent::QFileOpenEvent(const RFile &fileHandle) + : QEvent(FileOpen) +{ + TFileName fullName; + fileHandle.FullName(fullName); + QString file = qt_TDesC2QString(fullName); + f = file; + QScopedPointer priv(new QFileOpenEventPrivate(QUrl::fromLocalFile(file))); + qt_symbian_throwIfError(priv->file.Duplicate(fileHandle)); + d = reinterpret_cast(priv.take()); +} +#endif + /*! \internal */ QFileOpenEvent::~QFileOpenEvent() { - delete reinterpret_cast(d); + QFileOpenEventPrivate *priv = reinterpret_cast(d); +#ifdef Q_OS_SYMBIAN + priv->file.Close(); +#endif + delete priv; } /*! diff --git a/src/gui/kernel/qevent.h b/src/gui/kernel/qevent.h index a7b06f4..2f5c486 100644 --- a/src/gui/kernel/qevent.h +++ b/src/gui/kernel/qevent.h @@ -55,6 +55,10 @@ #include #include +#ifdef Q_OS_SYMBIAN +class RFile; +#endif + QT_BEGIN_HEADER QT_BEGIN_NAMESPACE @@ -641,6 +645,9 @@ class Q_GUI_EXPORT QFileOpenEvent : public QEvent public: QFileOpenEvent(const QString &file); QFileOpenEvent(const QUrl &url); +#ifdef Q_OS_SYMBIAN + QFileOpenEvent(const RFile &fileHandle); +#endif ~QFileOpenEvent(); inline QString file() const { return f; } diff --git a/src/gui/kernel/qevent_p.h b/src/gui/kernel/qevent_p.h index 3a27023..01af384 100644 --- a/src/gui/kernel/qevent_p.h +++ b/src/gui/kernel/qevent_p.h @@ -46,6 +46,10 @@ #include #include +#ifdef Q_OS_SYMBIAN +#include +#endif + QT_BEGIN_NAMESPACE // @@ -176,6 +180,9 @@ public: } QUrl url; +#ifdef Q_OS_SYMBIAN + RFile file; +#endif }; diff --git a/src/gui/s60framework/qs60maindocument.cpp b/src/gui/s60framework/qs60maindocument.cpp index 95effbc..eafbcb0 100644 --- a/src/gui/s60framework/qs60maindocument.cpp +++ b/src/gui/s60framework/qs60maindocument.cpp @@ -111,14 +111,12 @@ CEikAppUi *QS60MainDocument::CreateAppUiL() /*! \internal */ -CFileStore *QS60MainDocument::OpenFileL(TBool aDoOpen, const TDesC &aFilename, RFs &/*aFs*/) +CFileStore *QS60MainDocument::OpenFileL(TBool /*aDoOpen*/, const TDesC &aFilename, RFs &/*aFs*/) { - if (aDoOpen) { - QCoreApplication* app = QCoreApplication::instance(); - QString qname = qt_TDesC2QString(aFilename); - QFileOpenEvent* event = new QFileOpenEvent(qname); - app->postEvent(app, event); - } + QCoreApplication* app = QCoreApplication::instance(); + QString qname = qt_TDesC2QString(aFilename); + QFileOpenEvent* event = new QFileOpenEvent(qname); + app->postEvent(app, event); return 0; } @@ -128,10 +126,7 @@ CFileStore *QS60MainDocument::OpenFileL(TBool aDoOpen, const TDesC &aFilename, R void QS60MainDocument::OpenFileL(CFileStore *&aFileStore, RFile &aFile) { QCoreApplication* app = QCoreApplication::instance(); - TFileName name; - aFile.FullName(name); - QString qname = qt_TDesC2QString(name); - QFileOpenEvent* event = new QFileOpenEvent(qname); + QFileOpenEvent* event = new QFileOpenEvent(aFile); app->postEvent(app, event); aFileStore = 0; } -- cgit v0.12 From 5f5e67e39bfc073d65857f6edae1df0db8507edd Mon Sep 17 00:00:00 2001 From: mread Date: Fri, 5 Nov 2010 16:01:58 +0000 Subject: added an openFile method to QFileOpenEvent An application needs some way to get an open QFile when a QFileOpenEvent contains a Symbian file handle. Rather than exposing that file handle and forcing platform specific code to the application, this method hides the details giving an effective universal method for turning a QFileOpenEvent into an open QFile. Task-number: QTBUG-15015 Reviewed-by: Shane Kearns --- src/gui/kernel/qevent.cpp | 14 ++++++++++++++ src/gui/kernel/qevent.h | 2 ++ 2 files changed, 16 insertions(+) diff --git a/src/gui/kernel/qevent.cpp b/src/gui/kernel/qevent.cpp index f7bc54c..8a67b91 100644 --- a/src/gui/kernel/qevent.cpp +++ b/src/gui/kernel/qevent.cpp @@ -3098,6 +3098,20 @@ QUrl QFileOpenEvent::url() const return reinterpret_cast(d)->url; } +void QFileOpenEvent::openFile(QFile &file, QIODevice::OpenMode flags) const +{ + file.setFileName(f); +#ifdef Q_OS_SYMBIAN + const QFileOpenEventPrivate *priv = reinterpret_cast(d); + if (priv->file.SubSessionHandle()) { + // TODO return a QFile opened from the file handle + file.open(flags); + return; + } +#endif + file.open(flags); +} + #ifndef QT_NO_TOOLBAR /*! \internal diff --git a/src/gui/kernel/qevent.h b/src/gui/kernel/qevent.h index 2f5c486..0499a6d 100644 --- a/src/gui/kernel/qevent.h +++ b/src/gui/kernel/qevent.h @@ -54,6 +54,7 @@ #include #include #include +#include #ifdef Q_OS_SYMBIAN class RFile; @@ -652,6 +653,7 @@ public: inline QString file() const { return f; } QUrl url() const; + void openFile(QFile &file, QIODevice::OpenMode flags) const; private: QString f; }; -- cgit v0.12 From 6b452ea0757414965fa00bfb7285f7d687c9c8d0 Mon Sep 17 00:00:00 2001 From: mread Date: Tue, 9 Nov 2010 13:02:56 +0000 Subject: documentation for QFileOpenEvent::openFile Task-number: QTBUG-15015 Reviewed-by: Shane Kearns --- src/gui/kernel/qevent.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/gui/kernel/qevent.cpp b/src/gui/kernel/qevent.cpp index 8a67b91..8f2e6cb 100644 --- a/src/gui/kernel/qevent.cpp +++ b/src/gui/kernel/qevent.cpp @@ -3098,6 +3098,17 @@ QUrl QFileOpenEvent::url() const return reinterpret_cast(d)->url; } +/*! + \fn void openFile(QFile &file, QIODevice::OpenMode flags) const + + Opens a QFile on the file referenced by this event. + This is necessary as some files cannot be opened with the filename alone, but require specific + information stored in this event. + For example, if this QFileOpenEvent contains a request to open a Symbian data caged file, + this function must be used to open a QFile on it. + + \since 4.8 +*/ void QFileOpenEvent::openFile(QFile &file, QIODevice::OpenMode flags) const { file.setFileName(f); -- cgit v0.12 From 7322556ec759d25ead3d0ba26ebd44a82a574872 Mon Sep 17 00:00:00 2001 From: mread Date: Fri, 5 Nov 2010 08:10:14 +0000 Subject: Generating QFileOpenEvent messages when S60 UI receives OpenFileL S60 applications can receive OpenFileL requests from other apps in the OpenFileL method of their main document class. This S60 main document class is internal to QtGui, so the request is turned into a QFileOpenEvent for the application to pick up if it want to implenment this service. If an application wants to receive the QFileOpenEvent before UI construction, it should do something like: app->sendPostedEvents(app, QEvent::FileOpen); Task-number: QTBUG-15015 Reviewed-by: Shane Kearns --- src/gui/s60framework/qs60maindocument.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/gui/s60framework/qs60maindocument.cpp b/src/gui/s60framework/qs60maindocument.cpp index eafbcb0..7114735 100644 --- a/src/gui/s60framework/qs60maindocument.cpp +++ b/src/gui/s60framework/qs60maindocument.cpp @@ -127,8 +127,10 @@ void QS60MainDocument::OpenFileL(CFileStore *&aFileStore, RFile &aFile) { QCoreApplication* app = QCoreApplication::instance(); QFileOpenEvent* event = new QFileOpenEvent(aFile); - app->postEvent(app, event); - aFileStore = 0; + TFileName name; + aFile.FullName(name); + QString qname((QChar*)name.Ptr(), name.Length()); + QFileOpenEvent* event = new QFileOpenEvent(qname); } QT_END_NAMESPACE -- cgit v0.12 From 713eed0b830dc11c69adab3bc5a9b1b6b3814a18 Mon Sep 17 00:00:00 2001 From: mread Date: Fri, 5 Nov 2010 10:40:44 +0000 Subject: used official descriptor to QString conversion The OpenFileL code now uses qt_TDesC2QString to convert from the TFileName to a QString. Task-number: QTBUG-15015 Reviewed-by: Shane Kearns --- src/gui/s60framework/qs60maindocument.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/s60framework/qs60maindocument.cpp b/src/gui/s60framework/qs60maindocument.cpp index 7114735..51a6ac9 100644 --- a/src/gui/s60framework/qs60maindocument.cpp +++ b/src/gui/s60framework/qs60maindocument.cpp @@ -129,7 +129,7 @@ void QS60MainDocument::OpenFileL(CFileStore *&aFileStore, RFile &aFile) QFileOpenEvent* event = new QFileOpenEvent(aFile); TFileName name; aFile.FullName(name); - QString qname((QChar*)name.Ptr(), name.Length()); + QString qname = qt_TDesC2QString(name); QFileOpenEvent* event = new QFileOpenEvent(qname); } -- cgit v0.12 From 977638104d091dd8780f4d1bee79bf014d6a2fe9 Mon Sep 17 00:00:00 2001 From: mread Date: Fri, 5 Nov 2010 13:23:38 +0000 Subject: Added a file handle to QFileOpenEvent on Symbian QFileOpenEvent needs to tell the recipient what file to open. Normally that is by filename. But on Symbian, some files can only be opened from an already-open file handle that has been passed in. For example data caged files in c:\private or z:\sys. So QFileOpenEvent needs to be able to hold a Symbian file handle so that the recipient can access any file requested of it. Coming soon... a method by which the reciever can access the file without knowing about all this messy file handle stuff going on behind the scenes. Task-number: QTBUG-15015 Reviewed-by: Shane Kearns --- src/gui/kernel/qevent.h | 4 ++++ src/gui/s60framework/qs60maindocument.cpp | 4 ---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/gui/kernel/qevent.h b/src/gui/kernel/qevent.h index 0499a6d..88a7a8a 100644 --- a/src/gui/kernel/qevent.h +++ b/src/gui/kernel/qevent.h @@ -60,6 +60,10 @@ class RFile; #endif +#ifdef Q_OS_SYMBIAN +class RFile; +#endif + QT_BEGIN_HEADER QT_BEGIN_NAMESPACE diff --git a/src/gui/s60framework/qs60maindocument.cpp b/src/gui/s60framework/qs60maindocument.cpp index 51a6ac9..d53aac1 100644 --- a/src/gui/s60framework/qs60maindocument.cpp +++ b/src/gui/s60framework/qs60maindocument.cpp @@ -127,10 +127,6 @@ void QS60MainDocument::OpenFileL(CFileStore *&aFileStore, RFile &aFile) { QCoreApplication* app = QCoreApplication::instance(); QFileOpenEvent* event = new QFileOpenEvent(aFile); - TFileName name; - aFile.FullName(name); - QString qname = qt_TDesC2QString(name); - QFileOpenEvent* event = new QFileOpenEvent(qname); } QT_END_NAMESPACE -- cgit v0.12 From f29b95cef0441958050c86d3544cdfde32e9e62e Mon Sep 17 00:00:00 2001 From: mread Date: Fri, 7 Jan 2011 11:07:08 +0000 Subject: Using QFile open by RFile and take ownership of handle QFileOpenEvent's open method now opens the QFile with an RFile handle if possible. It takes a duplicate of the handle and transfers ownership to the QFile, so that the QFile can be used many times and outside of the lifetime of the QFileOpenEvent. Task-number: QTBUG-15015 Reviewed-by: Shane Kearns --- src/corelib/kernel/qcore_symbian_p.h | 16 ++++++++++++++++ src/gui/kernel/qevent.cpp | 18 ++++++++++++------ src/gui/kernel/qevent.h | 2 +- src/gui/s60framework/qs60maindocument.cpp | 18 ++++++++++++------ src/s60installs/bwins/QtGuiu.def | 4 +++- src/s60installs/eabi/QtGuiu.def | 8 ++++---- 6 files changed, 48 insertions(+), 18 deletions(-) diff --git a/src/corelib/kernel/qcore_symbian_p.h b/src/corelib/kernel/qcore_symbian_p.h index 3ef71e0..5b48689 100644 --- a/src/corelib/kernel/qcore_symbian_p.h +++ b/src/corelib/kernel/qcore_symbian_p.h @@ -158,6 +158,22 @@ Q_CORE_EXPORT RFs& qt_s60GetRFs(); // Defined in qlocale_symbian.cpp. Q_CORE_EXPORT QByteArray qt_symbianLocaleName(int code); +template +struct QScopedPointerRCloser +{ + static inline void cleanup(R *rPointer) + { + // Enforce a complete type. + // If you get a compile error here, read the section on forward declared + // classes in the QScopedPointer documentation. + typedef char IsIncompleteType[ sizeof(R) ? 1 : -1 ]; + (void) sizeof(IsIncompleteType); + + if (rPointer) + rPointer->Close(); + } +}; + QT_END_NAMESPACE QT_END_HEADER diff --git a/src/gui/kernel/qevent.cpp b/src/gui/kernel/qevent.cpp index 8f2e6cb..17bcbfb 100644 --- a/src/gui/kernel/qevent.cpp +++ b/src/gui/kernel/qevent.cpp @@ -3099,9 +3099,11 @@ QUrl QFileOpenEvent::url() const } /*! - \fn void openFile(QFile &file, QIODevice::OpenMode flags) const + \fn bool openFile(QFile &file, QIODevice::OpenMode flags) const Opens a QFile on the file referenced by this event. + Returns true if successful; otherwise returns false. + This is necessary as some files cannot be opened with the filename alone, but require specific information stored in this event. For example, if this QFileOpenEvent contains a request to open a Symbian data caged file, @@ -3109,18 +3111,22 @@ QUrl QFileOpenEvent::url() const \since 4.8 */ -void QFileOpenEvent::openFile(QFile &file, QIODevice::OpenMode flags) const +bool QFileOpenEvent::openFile(QFile &file, QIODevice::OpenMode flags) const { file.setFileName(f); #ifdef Q_OS_SYMBIAN const QFileOpenEventPrivate *priv = reinterpret_cast(d); if (priv->file.SubSessionHandle()) { - // TODO return a QFile opened from the file handle - file.open(flags); - return; + RFile dup; + if (dup.Duplicate(priv->file) == KErrNone) { + QScopedPointer > dupCloser(&dup); + bool open = file.open(dup, flags, QFile::AutoCloseHandle); + dupCloser.take(); + return open; + } } #endif - file.open(flags); + return file.open(flags); } #ifndef QT_NO_TOOLBAR diff --git a/src/gui/kernel/qevent.h b/src/gui/kernel/qevent.h index 88a7a8a..997ac0c 100644 --- a/src/gui/kernel/qevent.h +++ b/src/gui/kernel/qevent.h @@ -657,7 +657,7 @@ public: inline QString file() const { return f; } QUrl url() const; - void openFile(QFile &file, QIODevice::OpenMode flags) const; + bool openFile(QFile &file, QIODevice::OpenMode flags) const; private: QString f; }; diff --git a/src/gui/s60framework/qs60maindocument.cpp b/src/gui/s60framework/qs60maindocument.cpp index d53aac1..37bd55f 100644 --- a/src/gui/s60framework/qs60maindocument.cpp +++ b/src/gui/s60framework/qs60maindocument.cpp @@ -113,10 +113,12 @@ CEikAppUi *QS60MainDocument::CreateAppUiL() */ CFileStore *QS60MainDocument::OpenFileL(TBool /*aDoOpen*/, const TDesC &aFilename, RFs &/*aFs*/) { - QCoreApplication* app = QCoreApplication::instance(); - QString qname = qt_TDesC2QString(aFilename); - QFileOpenEvent* event = new QFileOpenEvent(qname); - app->postEvent(app, event); + QT_TRYCATCH_LEAVING( { + QCoreApplication* app = QCoreApplication::instance(); + QString qname = qt_TDesC2QString(aFilename); + QFileOpenEvent* event = new QFileOpenEvent(qname); + app->postEvent(app, event); + }) return 0; } @@ -125,8 +127,12 @@ CFileStore *QS60MainDocument::OpenFileL(TBool /*aDoOpen*/, const TDesC &aFilenam */ void QS60MainDocument::OpenFileL(CFileStore *&aFileStore, RFile &aFile) { - QCoreApplication* app = QCoreApplication::instance(); - QFileOpenEvent* event = new QFileOpenEvent(aFile); + QT_TRYCATCH_LEAVING( { + QCoreApplication* app = QCoreApplication::instance(); + QFileOpenEvent* event = new QFileOpenEvent(aFile); + app->postEvent(app, event); + aFileStore = 0; + }) } QT_END_NAMESPACE diff --git a/src/s60installs/bwins/QtGuiu.def b/src/s60installs/bwins/QtGuiu.def index 322d88b..9475728 100644 --- a/src/s60installs/bwins/QtGuiu.def +++ b/src/s60installs/bwins/QtGuiu.def @@ -13142,4 +13142,6 @@ EXPORTS ?viewportSize@QScrollPrepareEvent@@QBE?AVQSizeF@@XZ @ 13141 NONAME ; class QSizeF QScrollPrepareEvent::viewportSize(void) const ?staticMetaObject@QScroller@@2UQMetaObject@@B @ 13142 NONAME ; struct QMetaObject const QScroller::staticMetaObject ?staticMetaObject@QFlickGesture@@2UQMetaObject@@B @ 13143 NONAME ; struct QMetaObject const QFlickGesture::staticMetaObject - + ?ProcessCommandParametersL@QS60MainAppUi@@UAEHW4TApaCommand@@AAV?$TBuf@$0BAA@@@ABVTDesC8@@@Z @ 13144 NONAME ; int QS60MainAppUi::ProcessCommandParametersL(enum TApaCommand, class TBuf<256> &, class TDesC8 const &) + ?openFile@QFileOpenEvent@@QBE_NAAVQFile@@V?$QFlags@W4OpenModeFlag@QIODevice@@@@@Z @ 13145 NONAME ; bool QFileOpenEvent::openFile(class QFile &, class QFlags) const + ??0QFileOpenEvent@@QAE@ABVRFile@@@Z @ 13146 NONAME ; QFileOpenEvent::QFileOpenEvent(class RFile const &) diff --git a/src/s60installs/eabi/QtGuiu.def b/src/s60installs/eabi/QtGuiu.def index 8064fa3..a4937a7 100644 --- a/src/s60installs/eabi/QtGuiu.def +++ b/src/s60installs/eabi/QtGuiu.def @@ -12227,10 +12227,10 @@ EXPORTS _ZTV19QBlitterPaintEngine @ 12226 NONAME _ZTV20QBlittablePixmapData @ 12227 NONAME _Zls6QDebugPK13QSymbianEvent @ 12228 NONAME - _ZN13QS60MainAppUi25ProcessCommandParametersLE11TApaCommandR4TBufILi256EERK6TDesC8 @ 12229 NONAME ABSENT - _ZN14QFileOpenEventC1ERK5RFile @ 12230 NONAME ABSENT - _ZN14QFileOpenEventC2ERK5RFile @ 12231 NONAME ABSENT - _ZNK14QFileOpenEvent8openFileER5QFile6QFlagsIN9QIODevice12OpenModeFlagEE @ 12232 NONAME ABSENT + _ZN13QS60MainAppUi25ProcessCommandParametersLE11TApaCommandR4TBufILi256EERK6TDesC8 @ 12229 NONAME + _ZN14QFileOpenEventC1ERK5RFile @ 12230 NONAME + _ZN14QFileOpenEventC2ERK5RFile @ 12231 NONAME + _ZNK14QFileOpenEvent8openFileER5QFile6QFlagsIN9QIODevice12OpenModeFlagEE @ 12232 NONAME _ZN11QFontEngine16alphaMapForGlyphEj6QFixed @ 12233 NONAME _ZN11QFontEngine16alphaMapForGlyphEj6QFixedRK10QTransform @ 12234 NONAME _Z32qGamma_correct_back_to_linear_csP6QImage @ 12235 NONAME -- cgit v0.12 From b93dc7717a9d19fef4c9a27145c5fbf0cd68ba81 Mon Sep 17 00:00:00 2001 From: mread Date: Fri, 7 Jan 2011 11:29:29 +0000 Subject: Fixed a trailing whitespace Task-number: QTBUG-15015 Reviewed-by: Shane Kearns --- src/gui/kernel/qevent.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/kernel/qevent.cpp b/src/gui/kernel/qevent.cpp index 17bcbfb..f6f2694 100644 --- a/src/gui/kernel/qevent.cpp +++ b/src/gui/kernel/qevent.cpp @@ -3103,7 +3103,7 @@ QUrl QFileOpenEvent::url() const Opens a QFile on the file referenced by this event. Returns true if successful; otherwise returns false. - + This is necessary as some files cannot be opened with the filename alone, but require specific information stored in this event. For example, if this QFileOpenEvent contains a request to open a Symbian data caged file, -- cgit v0.12 From 82f3b68a555df557529e8dce5396f1de8242d2d3 Mon Sep 17 00:00:00 2001 From: mread Date: Mon, 10 Jan 2011 16:44:29 +0000 Subject: removed double forward declaration Task-number: QTBUG-15015 Reviewed-by: Shane Kearns --- src/gui/kernel/qevent.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/gui/kernel/qevent.h b/src/gui/kernel/qevent.h index 997ac0c..93c2bc5 100644 --- a/src/gui/kernel/qevent.h +++ b/src/gui/kernel/qevent.h @@ -60,10 +60,6 @@ class RFile; #endif -#ifdef Q_OS_SYMBIAN -class RFile; -#endif - QT_BEGIN_HEADER QT_BEGIN_NAMESPACE -- cgit v0.12 From f274fac046b041a1d07d935ded50874c501e61fe Mon Sep 17 00:00:00 2001 From: mread Date: Mon, 10 Jan 2011 16:57:47 +0000 Subject: Started a QFileOpenEvent test for Symbian This is an autotest for QFileOpenEvent. Actually it's more generic than just Symbian. So maybe it will move out of the Symbian specific directory in the future. This autotest is not complete yet. Task-number: QTBUG-15015 Reviewed-by: Shane Kearns --- .../auto/symbian/qfileopenevent/qfileopenevent.pro | 6 + .../symbian/qfileopenevent/tst_qfileopenevent.cpp | 188 +++++++++++++++++++++ 2 files changed, 194 insertions(+) create mode 100644 tests/auto/symbian/qfileopenevent/qfileopenevent.pro create mode 100644 tests/auto/symbian/qfileopenevent/tst_qfileopenevent.cpp diff --git a/tests/auto/symbian/qfileopenevent/qfileopenevent.pro b/tests/auto/symbian/qfileopenevent/qfileopenevent.pro new file mode 100644 index 0000000..e2bc537 --- /dev/null +++ b/tests/auto/symbian/qfileopenevent/qfileopenevent.pro @@ -0,0 +1,6 @@ +load(qttest_p4) +HEADERS += +SOURCES += tst_qfileopenevent.cpp +symbian { + LIBS+=-lefsrv +} diff --git a/tests/auto/symbian/qfileopenevent/tst_qfileopenevent.cpp b/tests/auto/symbian/qfileopenevent/tst_qfileopenevent.cpp new file mode 100644 index 0000000..85ec04d --- /dev/null +++ b/tests/auto/symbian/qfileopenevent/tst_qfileopenevent.cpp @@ -0,0 +1,188 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include + +#ifdef Q_OS_SYMBIAN + +class tst_qfileopenevent : public QObject +{ + Q_OBJECT +public: + tst_qfileopenevent(){} + ~tst_qfileopenevent(); + +public slots: + void initTestCase(); + +private slots: + void constructor(); + void fileOpen(); + void handleLifetime(); + void multiOpen(); + void sendAndReceive(); + void viaApparc(); + void viasDocHandler(); + +private: + RFile createRFile(const TDesC& filename, const TDesC8& content); + void checkReadAndWrite(QFileOpenEvent& event, const QString& readContent, const QString& writeContent, bool writeOk); + QString readFileContent(QFileOpenEvent& event); + bool appendFileContent(QFileOpenEvent& event, const QString& writeContent); + +private: + RFs fsSession; +}; + +tst_qfileopenevent::~tst_qfileopenevent() +{ + fsSession.Close(); +}; + +void tst_qfileopenevent::initTestCase() +{ + qt_symbian_throwIfError(fsSession.Connect()); +} + +RFile tst_qfileopenevent::createRFile(const TDesC& filename, const TDesC8& content) +{ + RFile file; + qt_symbian_throwIfError(file.Replace(fsSession, filename, EFileWrite)); + qt_symbian_throwIfError(file.Write(content)); + return file; +} + +void tst_qfileopenevent::constructor() +{ + // check that filename get/set works + QFileOpenEvent nameTest(QLatin1String("fileNameTest")); + QCOMPARE(nameTest.file(), QLatin1String("fileNameTest")); + + // check that url get/set works + QFileOpenEvent urlTest(QUrl(QLatin1String("file:///urlNameTest"))); + QCOMPARE(urlTest.url().toString(), QLatin1String("file:///urlNameTest")); + + // check that RFile construction works + RFile rFile = createRFile(_L("testRFile"), _L8("test content")); + QFileOpenEvent rFileTest(rFile); + QString targetName(QLatin1String("testRFile")); + QCOMPARE(rFileTest.file().right(targetName.size()), targetName); + QCOMPARE(rFileTest.url().toString().right(targetName.size()), targetName); + rFile.Close(); +} + +QString tst_qfileopenevent::readFileContent(QFileOpenEvent& event) +{ + QFile file; + event.openFile(file, QFile::ReadOnly); + file.seek(0); + QByteArray data = file.readAll(); + return QString(data); +} + +bool tst_qfileopenevent::appendFileContent(QFileOpenEvent& event, const QString& writeContent) +{ + QFile file; + bool ok = event.openFile(file, QFile::Append | QFile::Unbuffered); + if (ok) + ok = file.write(writeContent.toUtf8()) == writeContent.size(); + return ok; +} + +void tst_qfileopenevent::checkReadAndWrite(QFileOpenEvent& event, const QString& readContent, const QString& writeContent, bool writeOk) +{ + QCOMPARE(readFileContent(event), readContent); + QCOMPARE(appendFileContent(event, writeContent), writeOk); + QCOMPARE(readFileContent(event), writeOk ? readContent+writeContent : readContent); +} + +void tst_qfileopenevent::fileOpen() +{ + // create writeable file + { + RFile rFile = createRFile(_L("testFileOpen"), _L8("test content")); + QFileOpenEvent rFileTest(rFile); + checkReadAndWrite(rFileTest, QLatin1String("test content"), QLatin1String("+RFileWrite"), true); + rFile.Close(); + } + + // open read-only RFile + { + RFile rFile; + int err = rFile.Open(fsSession, _L("testFileOpen"), EFileRead); + QFileOpenEvent rFileTest2(rFile); + checkReadAndWrite(rFileTest2, QLatin1String("test content+RFileWrite"), QLatin1String("+RFileRead"), false); + rFile.Close(); + } + + // test it with read and write + // filename event + // test it with read and write + // url event + // test it with read and write +} + +void tst_qfileopenevent::handleLifetime() +{ +} + +void tst_qfileopenevent::multiOpen() +{ +} + +void tst_qfileopenevent::sendAndReceive() +{ +} + +void tst_qfileopenevent::viaApparc() +{ +} + +void tst_qfileopenevent::viasDocHandler() +{ +} + +QTEST_MAIN(tst_qfileopenevent) +#include "tst_qfileopenevent.moc" +#else +QTEST_NOOP_MAIN +#endif -- cgit v0.12 From 4ef64530ed2f9d939d54aa4fdb5166725345a58c Mon Sep 17 00:00:00 2001 From: mread Date: Tue, 11 Jan 2011 14:38:06 +0000 Subject: Development of QFileOpenEvent testing for Symbian The source has been rearranged so that there is a main test program and a helper app, which helps test data caging. A bunch of new tests have been added. Task-number: QTBUG-15015 Reviewed-by: Shane Kearns --- .../auto/symbian/qfileopenevent/qfileopenevent.pro | 10 +- .../qfileopeneventexternal.cpp | 40 +++ .../qfileopeneventexternal.pro | 12 + .../qfileopenevent/test/tst_qfileopenevent.cpp | 304 +++++++++++++++++++++ .../qfileopenevent/test/tst_qfileopenevent.pro | 7 + .../symbian/qfileopenevent/tst_qfileopenevent.cpp | 188 ------------- 6 files changed, 368 insertions(+), 193 deletions(-) create mode 100644 tests/auto/symbian/qfileopenevent/qfileopeneventexternal/qfileopeneventexternal.cpp create mode 100644 tests/auto/symbian/qfileopenevent/qfileopeneventexternal/qfileopeneventexternal.pro create mode 100644 tests/auto/symbian/qfileopenevent/test/tst_qfileopenevent.cpp create mode 100644 tests/auto/symbian/qfileopenevent/test/tst_qfileopenevent.pro delete mode 100644 tests/auto/symbian/qfileopenevent/tst_qfileopenevent.cpp diff --git a/tests/auto/symbian/qfileopenevent/qfileopenevent.pro b/tests/auto/symbian/qfileopenevent/qfileopenevent.pro index e2bc537..e2bb6d8 100644 --- a/tests/auto/symbian/qfileopenevent/qfileopenevent.pro +++ b/tests/auto/symbian/qfileopenevent/qfileopenevent.pro @@ -1,6 +1,6 @@ -load(qttest_p4) -HEADERS += -SOURCES += tst_qfileopenevent.cpp -symbian { - LIBS+=-lefsrv +TEMPLATE = subdirs +symbian:{ + SUBDIRS = test qfileopeneventexternal +} else { + SUBDIRS = } diff --git a/tests/auto/symbian/qfileopenevent/qfileopeneventexternal/qfileopeneventexternal.cpp b/tests/auto/symbian/qfileopenevent/qfileopeneventexternal/qfileopeneventexternal.cpp new file mode 100644 index 0000000..77e8563 --- /dev/null +++ b/tests/auto/symbian/qfileopenevent/qfileopeneventexternal/qfileopeneventexternal.cpp @@ -0,0 +1,40 @@ +/* +============================================================================ + Name : QtFileOpeningApp.cpp + Author : + Copyright : Your copyright notice + Description : Main GUI Application +============================================================================ +*/ + +#include +#include +#include + +struct MyApplication : public QApplication +{ + MyApplication(int& argc, char** argv) + : QApplication(argc, argv) + {} + + bool event(QEvent * event) + { + if (event->type() == QEvent::FileOpen) { + QFileOpenEvent* ev = static_cast(event); + QFile file; + bool ok = ev->openFile(file, QFile::Append | QFile::Unbuffered); + if (ok) + file.write(QByteArray("+external")); + return true; + } else { + return QApplication::event(event); + } + } +}; + +int main(int argc, char *argv[]) +{ + MyApplication a(argc, argv); + a.sendPostedEvents(&a, QEvent::FileOpen); + return 0; +} diff --git a/tests/auto/symbian/qfileopenevent/qfileopeneventexternal/qfileopeneventexternal.pro b/tests/auto/symbian/qfileopenevent/qfileopeneventexternal/qfileopeneventexternal.pro new file mode 100644 index 0000000..1b888b8 --- /dev/null +++ b/tests/auto/symbian/qfileopenevent/qfileopeneventexternal/qfileopeneventexternal.pro @@ -0,0 +1,12 @@ +TEMPLATE = app +TARGET = qfileopeneventexternal +QT += core gui +SOURCES += qfileopeneventexternal.cpp +symbian: { + TARGET.UID3 = 0xe9410b39 + MMP_RULES += DEBUGGABLE_UDEBONLY + RSS_RULES += "embeddability=KAppEmbeddable;" + RSS_RULES.datatype_list += "priority = EDataTypePriorityHigh; type = \"application/x-tst_qfileopenevent\";" + LIBS += -lapparc \ + -leikcore -lefsrv -lcone +} diff --git a/tests/auto/symbian/qfileopenevent/test/tst_qfileopenevent.cpp b/tests/auto/symbian/qfileopenevent/test/tst_qfileopenevent.cpp new file mode 100644 index 0000000..77d53aa --- /dev/null +++ b/tests/auto/symbian/qfileopenevent/test/tst_qfileopenevent.cpp @@ -0,0 +1,304 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include + +#ifdef Q_OS_SYMBIAN +#include +#include "private/qcore_symbian_p.h" + +class tst_qfileopenevent : public QObject +{ + Q_OBJECT +public: + tst_qfileopenevent(){} + ~tst_qfileopenevent(); + +public slots: + void initTestCase(); + +private slots: + void constructor(); + void fileOpen(); + void handleLifetime(); + void multiOpen(); + void sendAndReceive(); + void external_data(); + void external(); + +private: + RFile createRFile(const TDesC& filename, const TDesC8& content); + void checkReadAndWrite(QFileOpenEvent& event, const QString& readContent, const QString& writeContent, bool writeOk); + QString readFileContent(QFileOpenEvent& event); + bool appendFileContent(QFileOpenEvent& event, const QString& writeContent); + + bool event(QEvent *); + +private: + RFs fsSession; +}; + +tst_qfileopenevent::~tst_qfileopenevent() +{ + fsSession.Close(); +}; + +void tst_qfileopenevent::initTestCase() +{ + qt_symbian_throwIfError(fsSession.Connect()); + qt_symbian_throwIfError(fsSession.ShareProtected()); +} + +RFile tst_qfileopenevent::createRFile(const TDesC& filename, const TDesC8& content) +{ + RFile file; + qt_symbian_throwIfError(file.Replace(fsSession, filename, EFileWrite)); + qt_symbian_throwIfError(file.Write(content)); + return file; +} + +void tst_qfileopenevent::constructor() +{ + // check that filename get/set works + QFileOpenEvent nameTest(QLatin1String("fileNameTest")); + QCOMPARE(nameTest.file(), QLatin1String("fileNameTest")); + + // check that url get/set works + QFileOpenEvent urlTest(QUrl(QLatin1String("file:///urlNameTest"))); + QCOMPARE(urlTest.url().toString(), QLatin1String("file:///urlNameTest")); + + // check that RFile construction works + RFile rFile = createRFile(_L("testRFile"), _L8("test content")); + QFileOpenEvent rFileTest(rFile); + QString targetName(QLatin1String("testRFile")); + QCOMPARE(rFileTest.file().right(targetName.size()), targetName); + QCOMPARE(rFileTest.url().toString().right(targetName.size()), targetName); + rFile.Close(); +} + +QString tst_qfileopenevent::readFileContent(QFileOpenEvent& event) +{ + QFile file; + event.openFile(file, QFile::ReadOnly); + file.seek(0); + QByteArray data = file.readAll(); + return QString(data); +} + +bool tst_qfileopenevent::appendFileContent(QFileOpenEvent& event, const QString& writeContent) +{ + QFile file; + bool ok = event.openFile(file, QFile::Append | QFile::Unbuffered); + if (ok) + ok = file.write(writeContent.toUtf8()) == writeContent.size(); + return ok; +} + +void tst_qfileopenevent::checkReadAndWrite(QFileOpenEvent& event, const QString& readContent, const QString& writeContent, bool writeOk) +{ + QCOMPARE(readFileContent(event), readContent); + QCOMPARE(appendFileContent(event, writeContent), writeOk); + QCOMPARE(readFileContent(event), writeOk ? readContent+writeContent : readContent); +} + +void tst_qfileopenevent::fileOpen() +{ + // create writeable file + { + RFile rFile = createRFile(_L("testFileOpen"), _L8("test content")); + QFileOpenEvent rFileTest(rFile); + checkReadAndWrite(rFileTest, QLatin1String("test content"), QLatin1String("+RFileWrite"), true); + rFile.Close(); + } + + // open read-only RFile + { + RFile rFile; + int err = rFile.Open(fsSession, _L("testFileOpen"), EFileRead); + QFileOpenEvent rFileTest(rFile); + checkReadAndWrite(rFileTest, QLatin1String("test content+RFileWrite"), QLatin1String("+RFileRead"), false); + rFile.Close(); + } + + // filename event + QUrl fileUrl; // need to get the URL during the file test, for use in the URL test + { + QFileOpenEvent nameTest(QLatin1String("testFileOpen")); + fileUrl = nameTest.url(); + checkReadAndWrite(nameTest, QLatin1String("test content+RFileWrite"), QLatin1String("+nameWrite"), true); + } + + // url event + { + QFileOpenEvent urlTest(fileUrl); + checkReadAndWrite(urlTest, QLatin1String("test content+RFileWrite+nameWrite"), QLatin1String("+urlWrite"), true); + } +} + +void tst_qfileopenevent::handleLifetime() +{ + RFile rFile = createRFile(_L("testHandleLifetime"), _L8("test content")); + QScopedPointer event(new QFileOpenEvent(rFile)); + rFile.Close(); + + // open a QFile after the original RFile is closed + QFile qFile; + QCOMPARE(event->openFile(qFile, QFile::Append | QFile::Unbuffered), true); + event.reset(0); + + // write to the QFile after the event is closed + QString writeContent(QLatin1String("+closed original handles")); + QCOMPARE(int(qFile.write(writeContent.toUtf8())), writeContent.size()); + qFile.close(); + + // check the content + QFile check("testHandleLifetime"); + check.open(QFile::ReadOnly); + QString content(check.readAll()); + QCOMPARE(content, QLatin1String("test content+closed original handles")); +} + +void tst_qfileopenevent::multiOpen() +{ + RFile rFile = createRFile(_L("testMultiOpen"), _L8("itlum")); + QFileOpenEvent event(rFile); + rFile.Close(); + + QFile files[5]; + for (int i=0; i<5; i++) { + QCOMPARE(event.openFile(files[i], QFile::ReadOnly), true); + } + for (int i=0; i<5; i++) + files[i].seek(i); + QString str; + for (int i=4; i>=0; i--) { + char c; + files[i].getChar(&c); + str.append(c); + files[i].close(); + } + QCOMPARE(str, QLatin1String("multi")); +} + +bool tst_qfileopenevent::event(QEvent *event) +{ + if (event->type() != QEvent::FileOpen) + return QObject::event(event); + QFileOpenEvent* fileOpenEvent = static_cast(event); + appendFileContent(*fileOpenEvent, "+received"); + return true; +} + +void tst_qfileopenevent::sendAndReceive() +{ + RFile rFile = createRFile(_L("testSendAndReceive"), _L8("sending")); + QFileOpenEvent* event = new QFileOpenEvent(rFile); + rFile.Close(); + QCoreApplication::instance()->postEvent(this, event); + QCoreApplication::instance()->processEvents(); + + // check the content + QFile check("testSendAndReceive"); + QCOMPARE(check.open(QFile::ReadOnly), true); + QString content(check.readAll()); + QCOMPARE(content, QLatin1String("sending+received")); +} + +void tst_qfileopenevent::external_data() +{ + QTest::addColumn("filename"); + QTest::addColumn("targetContent"); + QTest::addColumn("sendHandle"); + + QString privateName(QLatin1String("tst_qfileopenevent_external")); + QString publicName(QLatin1String("C:\\Data\\tst_qfileopenevent_external")); + QByteArray writeSuccess("original+external"); + QByteArray writeFail("original"); + QTest::newRow("public name") << publicName << writeSuccess << false; + QTest::newRow("data caged name") << privateName << writeFail << false; + QTest::newRow("public handle") << publicName << writeSuccess << true; + QTest::newRow("data caged handle") << privateName << writeSuccess << true; +} + +void tst_qfileopenevent::external() +{ + QFETCH(QString, filename); + QFETCH(QByteArray, targetContent); + QFETCH(bool, sendHandle); + + RFile rFile = createRFile(qt_QString2TPtrC(filename), _L8("original")); + + // launch app with the file + RApaLsSession apa; + QCOMPARE(apa.Connect(), KErrNone); + TThreadId threadId; + TDataType type(_L8("application/x-tst_qfileopenevent")); + if (sendHandle) { + QCOMPARE(apa.StartDocument(rFile, type, threadId), KErrNone); + rFile.Close(); + } else { + TFileName fullName; + rFile.FullName(fullName); + rFile.Close(); + QCOMPARE(apa.StartDocument(fullName, type, threadId), KErrNone); + } + + // wait for app exit + RThread appThread; + if (appThread.Open(threadId) == KErrNone) { + TRequestStatus status; + appThread.Logon(status); + User::WaitForRequest(status); + } + + // check the contents + QFile check(filename); + QCOMPARE(check.open(QFile::ReadOnly), true); + QCOMPARE(check.readAll(), targetContent); + bool ok = check.remove(); +} + +QTEST_MAIN(tst_qfileopenevent) +#include "tst_qfileopenevent.moc" +#else +QTEST_NOOP_MAIN +#endif diff --git a/tests/auto/symbian/qfileopenevent/test/tst_qfileopenevent.pro b/tests/auto/symbian/qfileopenevent/test/tst_qfileopenevent.pro new file mode 100644 index 0000000..3f16dcf --- /dev/null +++ b/tests/auto/symbian/qfileopenevent/test/tst_qfileopenevent.pro @@ -0,0 +1,7 @@ +load(qttest_p4) +TARGET = tst_qfileopenevent +HEADERS += +SOURCES += tst_qfileopenevent.cpp +symbian { + LIBS+=-lefsrv -lapgrfx -lapmime +} diff --git a/tests/auto/symbian/qfileopenevent/tst_qfileopenevent.cpp b/tests/auto/symbian/qfileopenevent/tst_qfileopenevent.cpp deleted file mode 100644 index 85ec04d..0000000 --- a/tests/auto/symbian/qfileopenevent/tst_qfileopenevent.cpp +++ /dev/null @@ -1,188 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include -#include - -#ifdef Q_OS_SYMBIAN - -class tst_qfileopenevent : public QObject -{ - Q_OBJECT -public: - tst_qfileopenevent(){} - ~tst_qfileopenevent(); - -public slots: - void initTestCase(); - -private slots: - void constructor(); - void fileOpen(); - void handleLifetime(); - void multiOpen(); - void sendAndReceive(); - void viaApparc(); - void viasDocHandler(); - -private: - RFile createRFile(const TDesC& filename, const TDesC8& content); - void checkReadAndWrite(QFileOpenEvent& event, const QString& readContent, const QString& writeContent, bool writeOk); - QString readFileContent(QFileOpenEvent& event); - bool appendFileContent(QFileOpenEvent& event, const QString& writeContent); - -private: - RFs fsSession; -}; - -tst_qfileopenevent::~tst_qfileopenevent() -{ - fsSession.Close(); -}; - -void tst_qfileopenevent::initTestCase() -{ - qt_symbian_throwIfError(fsSession.Connect()); -} - -RFile tst_qfileopenevent::createRFile(const TDesC& filename, const TDesC8& content) -{ - RFile file; - qt_symbian_throwIfError(file.Replace(fsSession, filename, EFileWrite)); - qt_symbian_throwIfError(file.Write(content)); - return file; -} - -void tst_qfileopenevent::constructor() -{ - // check that filename get/set works - QFileOpenEvent nameTest(QLatin1String("fileNameTest")); - QCOMPARE(nameTest.file(), QLatin1String("fileNameTest")); - - // check that url get/set works - QFileOpenEvent urlTest(QUrl(QLatin1String("file:///urlNameTest"))); - QCOMPARE(urlTest.url().toString(), QLatin1String("file:///urlNameTest")); - - // check that RFile construction works - RFile rFile = createRFile(_L("testRFile"), _L8("test content")); - QFileOpenEvent rFileTest(rFile); - QString targetName(QLatin1String("testRFile")); - QCOMPARE(rFileTest.file().right(targetName.size()), targetName); - QCOMPARE(rFileTest.url().toString().right(targetName.size()), targetName); - rFile.Close(); -} - -QString tst_qfileopenevent::readFileContent(QFileOpenEvent& event) -{ - QFile file; - event.openFile(file, QFile::ReadOnly); - file.seek(0); - QByteArray data = file.readAll(); - return QString(data); -} - -bool tst_qfileopenevent::appendFileContent(QFileOpenEvent& event, const QString& writeContent) -{ - QFile file; - bool ok = event.openFile(file, QFile::Append | QFile::Unbuffered); - if (ok) - ok = file.write(writeContent.toUtf8()) == writeContent.size(); - return ok; -} - -void tst_qfileopenevent::checkReadAndWrite(QFileOpenEvent& event, const QString& readContent, const QString& writeContent, bool writeOk) -{ - QCOMPARE(readFileContent(event), readContent); - QCOMPARE(appendFileContent(event, writeContent), writeOk); - QCOMPARE(readFileContent(event), writeOk ? readContent+writeContent : readContent); -} - -void tst_qfileopenevent::fileOpen() -{ - // create writeable file - { - RFile rFile = createRFile(_L("testFileOpen"), _L8("test content")); - QFileOpenEvent rFileTest(rFile); - checkReadAndWrite(rFileTest, QLatin1String("test content"), QLatin1String("+RFileWrite"), true); - rFile.Close(); - } - - // open read-only RFile - { - RFile rFile; - int err = rFile.Open(fsSession, _L("testFileOpen"), EFileRead); - QFileOpenEvent rFileTest2(rFile); - checkReadAndWrite(rFileTest2, QLatin1String("test content+RFileWrite"), QLatin1String("+RFileRead"), false); - rFile.Close(); - } - - // test it with read and write - // filename event - // test it with read and write - // url event - // test it with read and write -} - -void tst_qfileopenevent::handleLifetime() -{ -} - -void tst_qfileopenevent::multiOpen() -{ -} - -void tst_qfileopenevent::sendAndReceive() -{ -} - -void tst_qfileopenevent::viaApparc() -{ -} - -void tst_qfileopenevent::viasDocHandler() -{ -} - -QTEST_MAIN(tst_qfileopenevent) -#include "tst_qfileopenevent.moc" -#else -QTEST_NOOP_MAIN -#endif -- cgit v0.12 From c618f06e39eee1bf8110f5a0c56578fb44e986f5 Mon Sep 17 00:00:00 2001 From: mread Date: Tue, 11 Jan 2011 14:48:30 +0000 Subject: renamed .pro file to make qmake happy qmake got upset because tst_qfileopenevent.pro was not called test.pro. Task-number: QTBUG-15015 Reviewed-by: Shane Kearns --- tests/auto/symbian/qfileopenevent/test/test.pro | 7 +++++++ tests/auto/symbian/qfileopenevent/test/tst_qfileopenevent.pro | 7 ------- 2 files changed, 7 insertions(+), 7 deletions(-) create mode 100644 tests/auto/symbian/qfileopenevent/test/test.pro delete mode 100644 tests/auto/symbian/qfileopenevent/test/tst_qfileopenevent.pro diff --git a/tests/auto/symbian/qfileopenevent/test/test.pro b/tests/auto/symbian/qfileopenevent/test/test.pro new file mode 100644 index 0000000..3f16dcf --- /dev/null +++ b/tests/auto/symbian/qfileopenevent/test/test.pro @@ -0,0 +1,7 @@ +load(qttest_p4) +TARGET = tst_qfileopenevent +HEADERS += +SOURCES += tst_qfileopenevent.cpp +symbian { + LIBS+=-lefsrv -lapgrfx -lapmime +} diff --git a/tests/auto/symbian/qfileopenevent/test/tst_qfileopenevent.pro b/tests/auto/symbian/qfileopenevent/test/tst_qfileopenevent.pro deleted file mode 100644 index 3f16dcf..0000000 --- a/tests/auto/symbian/qfileopenevent/test/tst_qfileopenevent.pro +++ /dev/null @@ -1,7 +0,0 @@ -load(qttest_p4) -TARGET = tst_qfileopenevent -HEADERS += -SOURCES += tst_qfileopenevent.cpp -symbian { - LIBS+=-lefsrv -lapgrfx -lapmime -} -- cgit v0.12 From 8f34fc6776fbd30bdae482a3f6bb683435544215 Mon Sep 17 00:00:00 2001 From: mread Date: Tue, 11 Jan 2011 15:49:46 +0000 Subject: removed dodgy file header The comment block at the top of the file had tabs in it. Git didn't like that. It's now removed, it was just the default comment added by Carbide. Task-number: QTBUG-15015 Reviewed-by: Shane Kearns --- .../qfileopeneventexternal/qfileopeneventexternal.cpp | 9 --------- 1 file changed, 9 deletions(-) diff --git a/tests/auto/symbian/qfileopenevent/qfileopeneventexternal/qfileopeneventexternal.cpp b/tests/auto/symbian/qfileopenevent/qfileopeneventexternal/qfileopeneventexternal.cpp index 77e8563..45e7acc 100644 --- a/tests/auto/symbian/qfileopenevent/qfileopeneventexternal/qfileopeneventexternal.cpp +++ b/tests/auto/symbian/qfileopenevent/qfileopeneventexternal/qfileopeneventexternal.cpp @@ -1,12 +1,3 @@ -/* -============================================================================ - Name : QtFileOpeningApp.cpp - Author : - Copyright : Your copyright notice - Description : Main GUI Application -============================================================================ -*/ - #include #include #include -- cgit v0.12 From 2abcd8e2ec986a4862de669f2ddec30877d9a853 Mon Sep 17 00:00:00 2001 From: mread Date: Tue, 11 Jan 2011 15:55:42 +0000 Subject: added qfileopenevent test to the symbian tests Previously it had not been added to the symbian tests .pro file Task-number: QTBUG-15015 Reviewed-by: Shane Kearns --- tests/auto/symbian/qsymbiantests.pro | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/auto/symbian/qsymbiantests.pro b/tests/auto/symbian/qsymbiantests.pro index a752c86..dcace63 100644 --- a/tests/auto/symbian/qsymbiantests.pro +++ b/tests/auto/symbian/qsymbiantests.pro @@ -1,4 +1,4 @@ TEMPLATE = subdirs -SUBDIRS = qmainexceptions orientationchange +SUBDIRS = qmainexceptions orientationchange qfileopenevent requires(symbian) -- cgit v0.12 From 30f845abdad6dcff620f93122495aee8aac7452f Mon Sep 17 00:00:00 2001 From: mread Date: Mon, 17 Jan 2011 15:12:25 +0000 Subject: review improvements for QFileOpenEvent changes removed an unnecessary local QString Improved some comment wording Task-number: QTBUG-15015 Reviewed-by: Shane Kearns --- src/gui/kernel/qevent.cpp | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/gui/kernel/qevent.cpp b/src/gui/kernel/qevent.cpp index f6f2694..5027aa2 100644 --- a/src/gui/kernel/qevent.cpp +++ b/src/gui/kernel/qevent.cpp @@ -728,12 +728,12 @@ QWheelEvent::QWheelEvent(const QPoint &pos, const QPoint& globalPos, int delta, The \a type parameter must be QEvent::KeyPress, QEvent::KeyRelease, or QEvent::ShortcutOverride. - Int \a key is the code for the Qt::Key that the event loop should listen - for. If \a key is 0, the event is not a result of a known key; for + Int \a key is the code for the Qt::Key that the event loop should listen + for. If \a key is 0, the event is not a result of a known key; for example, it may be the result of a compose sequence or keyboard macro. - The \a modifiers holds the keyboard modifiers, and the given \a text - is the Unicode text that the key generated. If \a autorep is true, - isAutoRepeat() will be true. \a count is the number of keys involved + The \a modifiers holds the keyboard modifiers, and the given \a text + is the Unicode text that the key generated. If \a autorep is true, + isAutoRepeat() will be true. \a count is the number of keys involved in the event. */ QKeyEvent::QKeyEvent(Type type, int key, Qt::KeyboardModifiers modifiers, const QString& text, @@ -1662,7 +1662,7 @@ Qt::ButtonState QContextMenuEvent::state() const string is controlled by the widget only). The AttributeType enum describes the different attributes that can be set. - A class implementing QWidget::inputMethodEvent() or + A class implementing QWidget::inputMethodEvent() or QGraphicsItem::inputMethodEvent() should at least understand and honor the \l TextFormat and \l Cursor attributes. @@ -3061,9 +3061,8 @@ QFileOpenEvent::QFileOpenEvent(const RFile &fileHandle) { TFileName fullName; fileHandle.FullName(fullName); - QString file = qt_TDesC2QString(fullName); - f = file; - QScopedPointer priv(new QFileOpenEventPrivate(QUrl::fromLocalFile(file))); + f = qt_TDesC2QString(fullName); + QScopedPointer priv(new QFileOpenEventPrivate(QUrl::fromLocalFile(f))); qt_symbian_throwIfError(priv->file.Duplicate(fileHandle)); d = reinterpret_cast(priv.take()); } @@ -3104,10 +3103,10 @@ QUrl QFileOpenEvent::url() const Opens a QFile on the file referenced by this event. Returns true if successful; otherwise returns false. - This is necessary as some files cannot be opened with the filename alone, but require specific + This is necessary as some files cannot be opened by name, but require specific information stored in this event. For example, if this QFileOpenEvent contains a request to open a Symbian data caged file, - this function must be used to open a QFile on it. + the QFile could only be opened from the Symbian RFile used in the construction of this event. \since 4.8 */ @@ -3677,7 +3676,7 @@ QMenubarUpdatedEvent::QMenubarUpdatedEvent(QMenuBar * const menuBar) #endif -/*! +/*! \class QTouchEvent \brief The QTouchEvent class contains parameters that describe a touch event. \since 4.6 -- cgit v0.12 From d35e6856c4fb7e98dac5db3aaa94ac271375405e Mon Sep 17 00:00:00 2001 From: mread Date: Tue, 18 Jan 2011 16:50:09 +0000 Subject: Updates after review comments Tidied up QFileOpenEventPrivate destruction. Commented the Duplicates to explain their benefit. Remove the file exists check from ProcessCommandParametersL Task-number: QTBUG-15015 Reviewed-by: Shane Kearns --- src/gui/kernel/qevent.cpp | 16 +++++++++++----- src/gui/kernel/qevent_p.h | 1 + src/gui/s60framework/qs60mainappui.cpp | 3 ++- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/gui/kernel/qevent.cpp b/src/gui/kernel/qevent.cpp index 5027aa2..698c94b 100644 --- a/src/gui/kernel/qevent.cpp +++ b/src/gui/kernel/qevent.cpp @@ -3030,6 +3030,13 @@ QShowEvent::~QShowEvent() \note This class is currently supported for Mac OS X and Symbian only. */ +QFileOpenEventPrivate::~QFileOpenEventPrivate() +{ +#ifdef Q_OS_SYMBIAN + file.Close(); +#endif +} + /*! \internal @@ -3063,6 +3070,7 @@ QFileOpenEvent::QFileOpenEvent(const RFile &fileHandle) fileHandle.FullName(fullName); f = qt_TDesC2QString(fullName); QScopedPointer priv(new QFileOpenEventPrivate(QUrl::fromLocalFile(f))); + // Duplicate here allows the file handle to be valid after S60 app construction is complete. qt_symbian_throwIfError(priv->file.Duplicate(fileHandle)); d = reinterpret_cast(priv.take()); } @@ -3072,11 +3080,7 @@ QFileOpenEvent::QFileOpenEvent(const RFile &fileHandle) */ QFileOpenEvent::~QFileOpenEvent() { - QFileOpenEventPrivate *priv = reinterpret_cast(d); -#ifdef Q_OS_SYMBIAN - priv->file.Close(); -#endif - delete priv; + delete reinterpret_cast(d); } /*! @@ -3117,6 +3121,8 @@ bool QFileOpenEvent::openFile(QFile &file, QIODevice::OpenMode flags) const const QFileOpenEventPrivate *priv = reinterpret_cast(d); if (priv->file.SubSessionHandle()) { RFile dup; + // Duplicate here means that the opened QFile will continue to be valid beyond the lifetime of this QFileOpenEvent. + // It also allows openFile to be used in threads other than the thread in which the QFileOpenEvent was created. if (dup.Duplicate(priv->file) == KErrNone) { QScopedPointer > dupCloser(&dup); bool open = file.open(dup, flags, QFile::AutoCloseHandle); diff --git a/src/gui/kernel/qevent_p.h b/src/gui/kernel/qevent_p.h index 01af384..b79f372 100644 --- a/src/gui/kernel/qevent_p.h +++ b/src/gui/kernel/qevent_p.h @@ -178,6 +178,7 @@ public: : url(url) { } + ~QFileOpenEventPrivate(); QUrl url; #ifdef Q_OS_SYMBIAN diff --git a/src/gui/s60framework/qs60mainappui.cpp b/src/gui/s60framework/qs60mainappui.cpp index 454f90d..8ae43a5 100644 --- a/src/gui/s60framework/qs60mainappui.cpp +++ b/src/gui/s60framework/qs60mainappui.cpp @@ -408,7 +408,8 @@ void QS60MainAppUi::HandleForegroundEventL(TBool aForeground) TBool QS60MainAppUi::ProcessCommandParametersL(TApaCommand /*aCommand*/, TFileName &aDocumentName, const TDesC8 &/*aTail*/) { // bypass CEikAppUi::ProcessCommandParametersL(..) which modifies aDocumentName, preventing apparc document opening from working. - return ConeUtils::FileExists(aDocumentName); + // The return value is effectively unused in Qt apps (see QS60MainDocument::OpenFileL) + return EFalse; } #ifndef Q_WS_S60 -- cgit v0.12 From 707cc8bfb51af5a777001df0f445a79863850f3a Mon Sep 17 00:00:00 2001 From: mread Date: Tue, 18 Jan 2011 16:54:42 +0000 Subject: Started move of QFileOpenEvent autotest to generic The QFileOpenEvent autotest was written as Symbian specific. But it is going to be modified to be applicable to all platforms. So this is the file move to reflect that change. Task-number: QTBUG-15015 Reviewed-by: Shane Kearns --- tests/auto/gui.pro | 3 +- tests/auto/qfileopenevent/qfileopenevent.pro | 6 + .../qfileopeneventexternal.cpp | 31 +++ .../qfileopeneventexternal.pro | 12 + tests/auto/qfileopenevent/test/test.pro | 7 + .../qfileopenevent/test/tst_qfileopenevent.cpp | 304 +++++++++++++++++++++ .../auto/symbian/qfileopenevent/qfileopenevent.pro | 6 - .../qfileopeneventexternal.cpp | 31 --- .../qfileopeneventexternal.pro | 12 - tests/auto/symbian/qfileopenevent/test/test.pro | 7 - .../qfileopenevent/test/tst_qfileopenevent.cpp | 304 --------------------- tests/auto/symbian/qsymbiantests.pro | 2 +- 12 files changed, 363 insertions(+), 362 deletions(-) create mode 100644 tests/auto/qfileopenevent/qfileopenevent.pro create mode 100644 tests/auto/qfileopenevent/qfileopeneventexternal/qfileopeneventexternal.cpp create mode 100644 tests/auto/qfileopenevent/qfileopeneventexternal/qfileopeneventexternal.pro create mode 100644 tests/auto/qfileopenevent/test/test.pro create mode 100644 tests/auto/qfileopenevent/test/tst_qfileopenevent.cpp delete mode 100644 tests/auto/symbian/qfileopenevent/qfileopenevent.pro delete mode 100644 tests/auto/symbian/qfileopenevent/qfileopeneventexternal/qfileopeneventexternal.cpp delete mode 100644 tests/auto/symbian/qfileopenevent/qfileopeneventexternal/qfileopeneventexternal.pro delete mode 100644 tests/auto/symbian/qfileopenevent/test/test.pro delete mode 100644 tests/auto/symbian/qfileopenevent/test/tst_qfileopenevent.cpp diff --git a/tests/auto/gui.pro b/tests/auto/gui.pro index f74da54..30155ea 100644 --- a/tests/auto/gui.pro +++ b/tests/auto/gui.pro @@ -2,7 +2,7 @@ # (i.e. QT=core gui network). # The test system is allowed to run these tests before the rest of Qt has # been compiled. -# +# TEMPLATE=subdirs SUBDIRS=\ gestures \ @@ -49,6 +49,7 @@ SUBDIRS=\ qfiledialog \ qfiledialog2 \ qfileiconprovider \ + qfileopenevent \ qfilesystemmodel \ qfocusframe \ qfont \ diff --git a/tests/auto/qfileopenevent/qfileopenevent.pro b/tests/auto/qfileopenevent/qfileopenevent.pro new file mode 100644 index 0000000..e2bb6d8 --- /dev/null +++ b/tests/auto/qfileopenevent/qfileopenevent.pro @@ -0,0 +1,6 @@ +TEMPLATE = subdirs +symbian:{ + SUBDIRS = test qfileopeneventexternal +} else { + SUBDIRS = +} diff --git a/tests/auto/qfileopenevent/qfileopeneventexternal/qfileopeneventexternal.cpp b/tests/auto/qfileopenevent/qfileopeneventexternal/qfileopeneventexternal.cpp new file mode 100644 index 0000000..45e7acc --- /dev/null +++ b/tests/auto/qfileopenevent/qfileopeneventexternal/qfileopeneventexternal.cpp @@ -0,0 +1,31 @@ +#include +#include +#include + +struct MyApplication : public QApplication +{ + MyApplication(int& argc, char** argv) + : QApplication(argc, argv) + {} + + bool event(QEvent * event) + { + if (event->type() == QEvent::FileOpen) { + QFileOpenEvent* ev = static_cast(event); + QFile file; + bool ok = ev->openFile(file, QFile::Append | QFile::Unbuffered); + if (ok) + file.write(QByteArray("+external")); + return true; + } else { + return QApplication::event(event); + } + } +}; + +int main(int argc, char *argv[]) +{ + MyApplication a(argc, argv); + a.sendPostedEvents(&a, QEvent::FileOpen); + return 0; +} diff --git a/tests/auto/qfileopenevent/qfileopeneventexternal/qfileopeneventexternal.pro b/tests/auto/qfileopenevent/qfileopeneventexternal/qfileopeneventexternal.pro new file mode 100644 index 0000000..1b888b8 --- /dev/null +++ b/tests/auto/qfileopenevent/qfileopeneventexternal/qfileopeneventexternal.pro @@ -0,0 +1,12 @@ +TEMPLATE = app +TARGET = qfileopeneventexternal +QT += core gui +SOURCES += qfileopeneventexternal.cpp +symbian: { + TARGET.UID3 = 0xe9410b39 + MMP_RULES += DEBUGGABLE_UDEBONLY + RSS_RULES += "embeddability=KAppEmbeddable;" + RSS_RULES.datatype_list += "priority = EDataTypePriorityHigh; type = \"application/x-tst_qfileopenevent\";" + LIBS += -lapparc \ + -leikcore -lefsrv -lcone +} diff --git a/tests/auto/qfileopenevent/test/test.pro b/tests/auto/qfileopenevent/test/test.pro new file mode 100644 index 0000000..3f16dcf --- /dev/null +++ b/tests/auto/qfileopenevent/test/test.pro @@ -0,0 +1,7 @@ +load(qttest_p4) +TARGET = tst_qfileopenevent +HEADERS += +SOURCES += tst_qfileopenevent.cpp +symbian { + LIBS+=-lefsrv -lapgrfx -lapmime +} diff --git a/tests/auto/qfileopenevent/test/tst_qfileopenevent.cpp b/tests/auto/qfileopenevent/test/tst_qfileopenevent.cpp new file mode 100644 index 0000000..77d53aa --- /dev/null +++ b/tests/auto/qfileopenevent/test/tst_qfileopenevent.cpp @@ -0,0 +1,304 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include + +#ifdef Q_OS_SYMBIAN +#include +#include "private/qcore_symbian_p.h" + +class tst_qfileopenevent : public QObject +{ + Q_OBJECT +public: + tst_qfileopenevent(){} + ~tst_qfileopenevent(); + +public slots: + void initTestCase(); + +private slots: + void constructor(); + void fileOpen(); + void handleLifetime(); + void multiOpen(); + void sendAndReceive(); + void external_data(); + void external(); + +private: + RFile createRFile(const TDesC& filename, const TDesC8& content); + void checkReadAndWrite(QFileOpenEvent& event, const QString& readContent, const QString& writeContent, bool writeOk); + QString readFileContent(QFileOpenEvent& event); + bool appendFileContent(QFileOpenEvent& event, const QString& writeContent); + + bool event(QEvent *); + +private: + RFs fsSession; +}; + +tst_qfileopenevent::~tst_qfileopenevent() +{ + fsSession.Close(); +}; + +void tst_qfileopenevent::initTestCase() +{ + qt_symbian_throwIfError(fsSession.Connect()); + qt_symbian_throwIfError(fsSession.ShareProtected()); +} + +RFile tst_qfileopenevent::createRFile(const TDesC& filename, const TDesC8& content) +{ + RFile file; + qt_symbian_throwIfError(file.Replace(fsSession, filename, EFileWrite)); + qt_symbian_throwIfError(file.Write(content)); + return file; +} + +void tst_qfileopenevent::constructor() +{ + // check that filename get/set works + QFileOpenEvent nameTest(QLatin1String("fileNameTest")); + QCOMPARE(nameTest.file(), QLatin1String("fileNameTest")); + + // check that url get/set works + QFileOpenEvent urlTest(QUrl(QLatin1String("file:///urlNameTest"))); + QCOMPARE(urlTest.url().toString(), QLatin1String("file:///urlNameTest")); + + // check that RFile construction works + RFile rFile = createRFile(_L("testRFile"), _L8("test content")); + QFileOpenEvent rFileTest(rFile); + QString targetName(QLatin1String("testRFile")); + QCOMPARE(rFileTest.file().right(targetName.size()), targetName); + QCOMPARE(rFileTest.url().toString().right(targetName.size()), targetName); + rFile.Close(); +} + +QString tst_qfileopenevent::readFileContent(QFileOpenEvent& event) +{ + QFile file; + event.openFile(file, QFile::ReadOnly); + file.seek(0); + QByteArray data = file.readAll(); + return QString(data); +} + +bool tst_qfileopenevent::appendFileContent(QFileOpenEvent& event, const QString& writeContent) +{ + QFile file; + bool ok = event.openFile(file, QFile::Append | QFile::Unbuffered); + if (ok) + ok = file.write(writeContent.toUtf8()) == writeContent.size(); + return ok; +} + +void tst_qfileopenevent::checkReadAndWrite(QFileOpenEvent& event, const QString& readContent, const QString& writeContent, bool writeOk) +{ + QCOMPARE(readFileContent(event), readContent); + QCOMPARE(appendFileContent(event, writeContent), writeOk); + QCOMPARE(readFileContent(event), writeOk ? readContent+writeContent : readContent); +} + +void tst_qfileopenevent::fileOpen() +{ + // create writeable file + { + RFile rFile = createRFile(_L("testFileOpen"), _L8("test content")); + QFileOpenEvent rFileTest(rFile); + checkReadAndWrite(rFileTest, QLatin1String("test content"), QLatin1String("+RFileWrite"), true); + rFile.Close(); + } + + // open read-only RFile + { + RFile rFile; + int err = rFile.Open(fsSession, _L("testFileOpen"), EFileRead); + QFileOpenEvent rFileTest(rFile); + checkReadAndWrite(rFileTest, QLatin1String("test content+RFileWrite"), QLatin1String("+RFileRead"), false); + rFile.Close(); + } + + // filename event + QUrl fileUrl; // need to get the URL during the file test, for use in the URL test + { + QFileOpenEvent nameTest(QLatin1String("testFileOpen")); + fileUrl = nameTest.url(); + checkReadAndWrite(nameTest, QLatin1String("test content+RFileWrite"), QLatin1String("+nameWrite"), true); + } + + // url event + { + QFileOpenEvent urlTest(fileUrl); + checkReadAndWrite(urlTest, QLatin1String("test content+RFileWrite+nameWrite"), QLatin1String("+urlWrite"), true); + } +} + +void tst_qfileopenevent::handleLifetime() +{ + RFile rFile = createRFile(_L("testHandleLifetime"), _L8("test content")); + QScopedPointer event(new QFileOpenEvent(rFile)); + rFile.Close(); + + // open a QFile after the original RFile is closed + QFile qFile; + QCOMPARE(event->openFile(qFile, QFile::Append | QFile::Unbuffered), true); + event.reset(0); + + // write to the QFile after the event is closed + QString writeContent(QLatin1String("+closed original handles")); + QCOMPARE(int(qFile.write(writeContent.toUtf8())), writeContent.size()); + qFile.close(); + + // check the content + QFile check("testHandleLifetime"); + check.open(QFile::ReadOnly); + QString content(check.readAll()); + QCOMPARE(content, QLatin1String("test content+closed original handles")); +} + +void tst_qfileopenevent::multiOpen() +{ + RFile rFile = createRFile(_L("testMultiOpen"), _L8("itlum")); + QFileOpenEvent event(rFile); + rFile.Close(); + + QFile files[5]; + for (int i=0; i<5; i++) { + QCOMPARE(event.openFile(files[i], QFile::ReadOnly), true); + } + for (int i=0; i<5; i++) + files[i].seek(i); + QString str; + for (int i=4; i>=0; i--) { + char c; + files[i].getChar(&c); + str.append(c); + files[i].close(); + } + QCOMPARE(str, QLatin1String("multi")); +} + +bool tst_qfileopenevent::event(QEvent *event) +{ + if (event->type() != QEvent::FileOpen) + return QObject::event(event); + QFileOpenEvent* fileOpenEvent = static_cast(event); + appendFileContent(*fileOpenEvent, "+received"); + return true; +} + +void tst_qfileopenevent::sendAndReceive() +{ + RFile rFile = createRFile(_L("testSendAndReceive"), _L8("sending")); + QFileOpenEvent* event = new QFileOpenEvent(rFile); + rFile.Close(); + QCoreApplication::instance()->postEvent(this, event); + QCoreApplication::instance()->processEvents(); + + // check the content + QFile check("testSendAndReceive"); + QCOMPARE(check.open(QFile::ReadOnly), true); + QString content(check.readAll()); + QCOMPARE(content, QLatin1String("sending+received")); +} + +void tst_qfileopenevent::external_data() +{ + QTest::addColumn("filename"); + QTest::addColumn("targetContent"); + QTest::addColumn("sendHandle"); + + QString privateName(QLatin1String("tst_qfileopenevent_external")); + QString publicName(QLatin1String("C:\\Data\\tst_qfileopenevent_external")); + QByteArray writeSuccess("original+external"); + QByteArray writeFail("original"); + QTest::newRow("public name") << publicName << writeSuccess << false; + QTest::newRow("data caged name") << privateName << writeFail << false; + QTest::newRow("public handle") << publicName << writeSuccess << true; + QTest::newRow("data caged handle") << privateName << writeSuccess << true; +} + +void tst_qfileopenevent::external() +{ + QFETCH(QString, filename); + QFETCH(QByteArray, targetContent); + QFETCH(bool, sendHandle); + + RFile rFile = createRFile(qt_QString2TPtrC(filename), _L8("original")); + + // launch app with the file + RApaLsSession apa; + QCOMPARE(apa.Connect(), KErrNone); + TThreadId threadId; + TDataType type(_L8("application/x-tst_qfileopenevent")); + if (sendHandle) { + QCOMPARE(apa.StartDocument(rFile, type, threadId), KErrNone); + rFile.Close(); + } else { + TFileName fullName; + rFile.FullName(fullName); + rFile.Close(); + QCOMPARE(apa.StartDocument(fullName, type, threadId), KErrNone); + } + + // wait for app exit + RThread appThread; + if (appThread.Open(threadId) == KErrNone) { + TRequestStatus status; + appThread.Logon(status); + User::WaitForRequest(status); + } + + // check the contents + QFile check(filename); + QCOMPARE(check.open(QFile::ReadOnly), true); + QCOMPARE(check.readAll(), targetContent); + bool ok = check.remove(); +} + +QTEST_MAIN(tst_qfileopenevent) +#include "tst_qfileopenevent.moc" +#else +QTEST_NOOP_MAIN +#endif diff --git a/tests/auto/symbian/qfileopenevent/qfileopenevent.pro b/tests/auto/symbian/qfileopenevent/qfileopenevent.pro deleted file mode 100644 index e2bb6d8..0000000 --- a/tests/auto/symbian/qfileopenevent/qfileopenevent.pro +++ /dev/null @@ -1,6 +0,0 @@ -TEMPLATE = subdirs -symbian:{ - SUBDIRS = test qfileopeneventexternal -} else { - SUBDIRS = -} diff --git a/tests/auto/symbian/qfileopenevent/qfileopeneventexternal/qfileopeneventexternal.cpp b/tests/auto/symbian/qfileopenevent/qfileopeneventexternal/qfileopeneventexternal.cpp deleted file mode 100644 index 45e7acc..0000000 --- a/tests/auto/symbian/qfileopenevent/qfileopeneventexternal/qfileopeneventexternal.cpp +++ /dev/null @@ -1,31 +0,0 @@ -#include -#include -#include - -struct MyApplication : public QApplication -{ - MyApplication(int& argc, char** argv) - : QApplication(argc, argv) - {} - - bool event(QEvent * event) - { - if (event->type() == QEvent::FileOpen) { - QFileOpenEvent* ev = static_cast(event); - QFile file; - bool ok = ev->openFile(file, QFile::Append | QFile::Unbuffered); - if (ok) - file.write(QByteArray("+external")); - return true; - } else { - return QApplication::event(event); - } - } -}; - -int main(int argc, char *argv[]) -{ - MyApplication a(argc, argv); - a.sendPostedEvents(&a, QEvent::FileOpen); - return 0; -} diff --git a/tests/auto/symbian/qfileopenevent/qfileopeneventexternal/qfileopeneventexternal.pro b/tests/auto/symbian/qfileopenevent/qfileopeneventexternal/qfileopeneventexternal.pro deleted file mode 100644 index 1b888b8..0000000 --- a/tests/auto/symbian/qfileopenevent/qfileopeneventexternal/qfileopeneventexternal.pro +++ /dev/null @@ -1,12 +0,0 @@ -TEMPLATE = app -TARGET = qfileopeneventexternal -QT += core gui -SOURCES += qfileopeneventexternal.cpp -symbian: { - TARGET.UID3 = 0xe9410b39 - MMP_RULES += DEBUGGABLE_UDEBONLY - RSS_RULES += "embeddability=KAppEmbeddable;" - RSS_RULES.datatype_list += "priority = EDataTypePriorityHigh; type = \"application/x-tst_qfileopenevent\";" - LIBS += -lapparc \ - -leikcore -lefsrv -lcone -} diff --git a/tests/auto/symbian/qfileopenevent/test/test.pro b/tests/auto/symbian/qfileopenevent/test/test.pro deleted file mode 100644 index 3f16dcf..0000000 --- a/tests/auto/symbian/qfileopenevent/test/test.pro +++ /dev/null @@ -1,7 +0,0 @@ -load(qttest_p4) -TARGET = tst_qfileopenevent -HEADERS += -SOURCES += tst_qfileopenevent.cpp -symbian { - LIBS+=-lefsrv -lapgrfx -lapmime -} diff --git a/tests/auto/symbian/qfileopenevent/test/tst_qfileopenevent.cpp b/tests/auto/symbian/qfileopenevent/test/tst_qfileopenevent.cpp deleted file mode 100644 index 77d53aa..0000000 --- a/tests/auto/symbian/qfileopenevent/test/tst_qfileopenevent.cpp +++ /dev/null @@ -1,304 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include -#include - -#ifdef Q_OS_SYMBIAN -#include -#include "private/qcore_symbian_p.h" - -class tst_qfileopenevent : public QObject -{ - Q_OBJECT -public: - tst_qfileopenevent(){} - ~tst_qfileopenevent(); - -public slots: - void initTestCase(); - -private slots: - void constructor(); - void fileOpen(); - void handleLifetime(); - void multiOpen(); - void sendAndReceive(); - void external_data(); - void external(); - -private: - RFile createRFile(const TDesC& filename, const TDesC8& content); - void checkReadAndWrite(QFileOpenEvent& event, const QString& readContent, const QString& writeContent, bool writeOk); - QString readFileContent(QFileOpenEvent& event); - bool appendFileContent(QFileOpenEvent& event, const QString& writeContent); - - bool event(QEvent *); - -private: - RFs fsSession; -}; - -tst_qfileopenevent::~tst_qfileopenevent() -{ - fsSession.Close(); -}; - -void tst_qfileopenevent::initTestCase() -{ - qt_symbian_throwIfError(fsSession.Connect()); - qt_symbian_throwIfError(fsSession.ShareProtected()); -} - -RFile tst_qfileopenevent::createRFile(const TDesC& filename, const TDesC8& content) -{ - RFile file; - qt_symbian_throwIfError(file.Replace(fsSession, filename, EFileWrite)); - qt_symbian_throwIfError(file.Write(content)); - return file; -} - -void tst_qfileopenevent::constructor() -{ - // check that filename get/set works - QFileOpenEvent nameTest(QLatin1String("fileNameTest")); - QCOMPARE(nameTest.file(), QLatin1String("fileNameTest")); - - // check that url get/set works - QFileOpenEvent urlTest(QUrl(QLatin1String("file:///urlNameTest"))); - QCOMPARE(urlTest.url().toString(), QLatin1String("file:///urlNameTest")); - - // check that RFile construction works - RFile rFile = createRFile(_L("testRFile"), _L8("test content")); - QFileOpenEvent rFileTest(rFile); - QString targetName(QLatin1String("testRFile")); - QCOMPARE(rFileTest.file().right(targetName.size()), targetName); - QCOMPARE(rFileTest.url().toString().right(targetName.size()), targetName); - rFile.Close(); -} - -QString tst_qfileopenevent::readFileContent(QFileOpenEvent& event) -{ - QFile file; - event.openFile(file, QFile::ReadOnly); - file.seek(0); - QByteArray data = file.readAll(); - return QString(data); -} - -bool tst_qfileopenevent::appendFileContent(QFileOpenEvent& event, const QString& writeContent) -{ - QFile file; - bool ok = event.openFile(file, QFile::Append | QFile::Unbuffered); - if (ok) - ok = file.write(writeContent.toUtf8()) == writeContent.size(); - return ok; -} - -void tst_qfileopenevent::checkReadAndWrite(QFileOpenEvent& event, const QString& readContent, const QString& writeContent, bool writeOk) -{ - QCOMPARE(readFileContent(event), readContent); - QCOMPARE(appendFileContent(event, writeContent), writeOk); - QCOMPARE(readFileContent(event), writeOk ? readContent+writeContent : readContent); -} - -void tst_qfileopenevent::fileOpen() -{ - // create writeable file - { - RFile rFile = createRFile(_L("testFileOpen"), _L8("test content")); - QFileOpenEvent rFileTest(rFile); - checkReadAndWrite(rFileTest, QLatin1String("test content"), QLatin1String("+RFileWrite"), true); - rFile.Close(); - } - - // open read-only RFile - { - RFile rFile; - int err = rFile.Open(fsSession, _L("testFileOpen"), EFileRead); - QFileOpenEvent rFileTest(rFile); - checkReadAndWrite(rFileTest, QLatin1String("test content+RFileWrite"), QLatin1String("+RFileRead"), false); - rFile.Close(); - } - - // filename event - QUrl fileUrl; // need to get the URL during the file test, for use in the URL test - { - QFileOpenEvent nameTest(QLatin1String("testFileOpen")); - fileUrl = nameTest.url(); - checkReadAndWrite(nameTest, QLatin1String("test content+RFileWrite"), QLatin1String("+nameWrite"), true); - } - - // url event - { - QFileOpenEvent urlTest(fileUrl); - checkReadAndWrite(urlTest, QLatin1String("test content+RFileWrite+nameWrite"), QLatin1String("+urlWrite"), true); - } -} - -void tst_qfileopenevent::handleLifetime() -{ - RFile rFile = createRFile(_L("testHandleLifetime"), _L8("test content")); - QScopedPointer event(new QFileOpenEvent(rFile)); - rFile.Close(); - - // open a QFile after the original RFile is closed - QFile qFile; - QCOMPARE(event->openFile(qFile, QFile::Append | QFile::Unbuffered), true); - event.reset(0); - - // write to the QFile after the event is closed - QString writeContent(QLatin1String("+closed original handles")); - QCOMPARE(int(qFile.write(writeContent.toUtf8())), writeContent.size()); - qFile.close(); - - // check the content - QFile check("testHandleLifetime"); - check.open(QFile::ReadOnly); - QString content(check.readAll()); - QCOMPARE(content, QLatin1String("test content+closed original handles")); -} - -void tst_qfileopenevent::multiOpen() -{ - RFile rFile = createRFile(_L("testMultiOpen"), _L8("itlum")); - QFileOpenEvent event(rFile); - rFile.Close(); - - QFile files[5]; - for (int i=0; i<5; i++) { - QCOMPARE(event.openFile(files[i], QFile::ReadOnly), true); - } - for (int i=0; i<5; i++) - files[i].seek(i); - QString str; - for (int i=4; i>=0; i--) { - char c; - files[i].getChar(&c); - str.append(c); - files[i].close(); - } - QCOMPARE(str, QLatin1String("multi")); -} - -bool tst_qfileopenevent::event(QEvent *event) -{ - if (event->type() != QEvent::FileOpen) - return QObject::event(event); - QFileOpenEvent* fileOpenEvent = static_cast(event); - appendFileContent(*fileOpenEvent, "+received"); - return true; -} - -void tst_qfileopenevent::sendAndReceive() -{ - RFile rFile = createRFile(_L("testSendAndReceive"), _L8("sending")); - QFileOpenEvent* event = new QFileOpenEvent(rFile); - rFile.Close(); - QCoreApplication::instance()->postEvent(this, event); - QCoreApplication::instance()->processEvents(); - - // check the content - QFile check("testSendAndReceive"); - QCOMPARE(check.open(QFile::ReadOnly), true); - QString content(check.readAll()); - QCOMPARE(content, QLatin1String("sending+received")); -} - -void tst_qfileopenevent::external_data() -{ - QTest::addColumn("filename"); - QTest::addColumn("targetContent"); - QTest::addColumn("sendHandle"); - - QString privateName(QLatin1String("tst_qfileopenevent_external")); - QString publicName(QLatin1String("C:\\Data\\tst_qfileopenevent_external")); - QByteArray writeSuccess("original+external"); - QByteArray writeFail("original"); - QTest::newRow("public name") << publicName << writeSuccess << false; - QTest::newRow("data caged name") << privateName << writeFail << false; - QTest::newRow("public handle") << publicName << writeSuccess << true; - QTest::newRow("data caged handle") << privateName << writeSuccess << true; -} - -void tst_qfileopenevent::external() -{ - QFETCH(QString, filename); - QFETCH(QByteArray, targetContent); - QFETCH(bool, sendHandle); - - RFile rFile = createRFile(qt_QString2TPtrC(filename), _L8("original")); - - // launch app with the file - RApaLsSession apa; - QCOMPARE(apa.Connect(), KErrNone); - TThreadId threadId; - TDataType type(_L8("application/x-tst_qfileopenevent")); - if (sendHandle) { - QCOMPARE(apa.StartDocument(rFile, type, threadId), KErrNone); - rFile.Close(); - } else { - TFileName fullName; - rFile.FullName(fullName); - rFile.Close(); - QCOMPARE(apa.StartDocument(fullName, type, threadId), KErrNone); - } - - // wait for app exit - RThread appThread; - if (appThread.Open(threadId) == KErrNone) { - TRequestStatus status; - appThread.Logon(status); - User::WaitForRequest(status); - } - - // check the contents - QFile check(filename); - QCOMPARE(check.open(QFile::ReadOnly), true); - QCOMPARE(check.readAll(), targetContent); - bool ok = check.remove(); -} - -QTEST_MAIN(tst_qfileopenevent) -#include "tst_qfileopenevent.moc" -#else -QTEST_NOOP_MAIN -#endif diff --git a/tests/auto/symbian/qsymbiantests.pro b/tests/auto/symbian/qsymbiantests.pro index dcace63..a752c86 100644 --- a/tests/auto/symbian/qsymbiantests.pro +++ b/tests/auto/symbian/qsymbiantests.pro @@ -1,4 +1,4 @@ TEMPLATE = subdirs -SUBDIRS = qmainexceptions orientationchange qfileopenevent +SUBDIRS = qmainexceptions orientationchange requires(symbian) -- cgit v0.12 From 6cd0dfcecd3efff882d04bb8c6358c706383a3af Mon Sep 17 00:00:00 2001 From: mread Date: Wed, 19 Jan 2011 12:42:37 +0000 Subject: tst_qfileopenevent changed to run on all platforms The Symbian specific bits are hidden behind #ifdef, but most of this test is valid on all platforms now. Task-number: QTBUG-15015 Reviewed-by: Shane Kearns --- tests/auto/qfileopenevent/qfileopenevent.pro | 6 +- .../qfileopenevent/test/tst_qfileopenevent.cpp | 115 +++++++++++++++------ 2 files changed, 86 insertions(+), 35 deletions(-) diff --git a/tests/auto/qfileopenevent/qfileopenevent.pro b/tests/auto/qfileopenevent/qfileopenevent.pro index e2bb6d8..45978d7 100644 --- a/tests/auto/qfileopenevent/qfileopenevent.pro +++ b/tests/auto/qfileopenevent/qfileopenevent.pro @@ -1,6 +1,2 @@ TEMPLATE = subdirs -symbian:{ - SUBDIRS = test qfileopeneventexternal -} else { - SUBDIRS = -} +SUBDIRS = test qfileopeneventexternal diff --git a/tests/auto/qfileopenevent/test/tst_qfileopenevent.cpp b/tests/auto/qfileopenevent/test/tst_qfileopenevent.cpp index 77d53aa..4f10d31 100644 --- a/tests/auto/qfileopenevent/test/tst_qfileopenevent.cpp +++ b/tests/auto/qfileopenevent/test/tst_qfileopenevent.cpp @@ -45,6 +45,7 @@ #ifdef Q_OS_SYMBIAN #include #include "private/qcore_symbian_p.h" +#endif class tst_qfileopenevent : public QObject { @@ -66,28 +67,46 @@ private slots: void external(); private: +#ifdef Q_OS_SYMBIAN RFile createRFile(const TDesC& filename, const TDesC8& content); - void checkReadAndWrite(QFileOpenEvent& event, const QString& readContent, const QString& writeContent, bool writeOk); - QString readFileContent(QFileOpenEvent& event); - bool appendFileContent(QFileOpenEvent& event, const QString& writeContent); +#else + void createFile(const QString &filename, const QByteArray &content); +#endif + QFileOpenEvent * createFileAndEvent(const QString &filename, const QByteArray &content); + void checkReadAndWrite(QFileOpenEvent& event, const QByteArray& readContent, const QByteArray& writeContent, bool writeOk); + QByteArray readFileContent(QFileOpenEvent& event); + bool appendFileContent(QFileOpenEvent& event, const QByteArray& writeContent); bool event(QEvent *); private: - RFs fsSession; +#ifdef Q_OS_SYMBIAN + struct AutoRFs : public RFs + { + AutoRFs() + { + qt_symbian_throwIfError(Connect()); + qt_symbian_throwIfError(ShareProtected()); + } + + ~AutoRFs() + { + Close(); + } + }; + AutoRFs fsSession; +#endif }; tst_qfileopenevent::~tst_qfileopenevent() { - fsSession.Close(); }; void tst_qfileopenevent::initTestCase() { - qt_symbian_throwIfError(fsSession.Connect()); - qt_symbian_throwIfError(fsSession.ShareProtected()); } +#ifdef Q_OS_SYMBIAN RFile tst_qfileopenevent::createRFile(const TDesC& filename, const TDesC8& content) { RFile file; @@ -95,6 +114,27 @@ RFile tst_qfileopenevent::createRFile(const TDesC& filename, const TDesC8& conte qt_symbian_throwIfError(file.Write(content)); return file; } +#else +void tst_qfileopenevent::createFile(const QString &filename, const QByteArray &content) +{ + QFile file(filename); + file.open(QFile::WriteOnly); + file.write(content); + file.close(); +} +#endif + +QFileOpenEvent * tst_qfileopenevent::createFileAndEvent(const QString &filename, const QByteArray &content) +{ +#ifdef Q_OS_SYMBIAN + RFile rFile = createRFile(qt_QString2TPtrC(filename), TPtrC8((TText8*)content.constData(), content.size())); + QScopedPointer > closeRFile(&rFile); + return new QFileOpenEvent(rFile); +#else + createFile(filename, content); + return new QFileOpenEvent(filename); +#endif +} void tst_qfileopenevent::constructor() { @@ -106,6 +146,7 @@ void tst_qfileopenevent::constructor() QFileOpenEvent urlTest(QUrl(QLatin1String("file:///urlNameTest"))); QCOMPARE(urlTest.url().toString(), QLatin1String("file:///urlNameTest")); +#ifdef Q_OS_SYMBIAN // check that RFile construction works RFile rFile = createRFile(_L("testRFile"), _L8("test content")); QFileOpenEvent rFileTest(rFile); @@ -113,27 +154,28 @@ void tst_qfileopenevent::constructor() QCOMPARE(rFileTest.file().right(targetName.size()), targetName); QCOMPARE(rFileTest.url().toString().right(targetName.size()), targetName); rFile.Close(); +#endif } -QString tst_qfileopenevent::readFileContent(QFileOpenEvent& event) +QByteArray tst_qfileopenevent::readFileContent(QFileOpenEvent& event) { QFile file; event.openFile(file, QFile::ReadOnly); file.seek(0); QByteArray data = file.readAll(); - return QString(data); + return data; } -bool tst_qfileopenevent::appendFileContent(QFileOpenEvent& event, const QString& writeContent) +bool tst_qfileopenevent::appendFileContent(QFileOpenEvent& event, const QByteArray& writeContent) { QFile file; bool ok = event.openFile(file, QFile::Append | QFile::Unbuffered); if (ok) - ok = file.write(writeContent.toUtf8()) == writeContent.size(); + ok = file.write(writeContent) == writeContent.size(); return ok; } -void tst_qfileopenevent::checkReadAndWrite(QFileOpenEvent& event, const QString& readContent, const QString& writeContent, bool writeOk) +void tst_qfileopenevent::checkReadAndWrite(QFileOpenEvent& event, const QByteArray& readContent, const QByteArray& writeContent, bool writeOk) { QCOMPARE(readFileContent(event), readContent); QCOMPARE(appendFileContent(event, writeContent), writeOk); @@ -142,11 +184,12 @@ void tst_qfileopenevent::checkReadAndWrite(QFileOpenEvent& event, const QString& void tst_qfileopenevent::fileOpen() { +#ifdef Q_OS_SYMBIAN // create writeable file { RFile rFile = createRFile(_L("testFileOpen"), _L8("test content")); QFileOpenEvent rFileTest(rFile); - checkReadAndWrite(rFileTest, QLatin1String("test content"), QLatin1String("+RFileWrite"), true); + checkReadAndWrite(rFileTest, QByteArray("test content"), QByteArray("+RFileWrite"), true); rFile.Close(); } @@ -155,30 +198,33 @@ void tst_qfileopenevent::fileOpen() RFile rFile; int err = rFile.Open(fsSession, _L("testFileOpen"), EFileRead); QFileOpenEvent rFileTest(rFile); - checkReadAndWrite(rFileTest, QLatin1String("test content+RFileWrite"), QLatin1String("+RFileRead"), false); + checkReadAndWrite(rFileTest, QByteArray("test content+RFileWrite"), QByteArray("+RFileRead"), false); rFile.Close(); } +#else + createFile(QLatin1String("testFileOpen"), QByteArray("test content+RFileWrite")); +#endif // filename event QUrl fileUrl; // need to get the URL during the file test, for use in the URL test { QFileOpenEvent nameTest(QLatin1String("testFileOpen")); fileUrl = nameTest.url(); - checkReadAndWrite(nameTest, QLatin1String("test content+RFileWrite"), QLatin1String("+nameWrite"), true); + checkReadAndWrite(nameTest, QByteArray("test content+RFileWrite"), QByteArray("+nameWrite"), true); } // url event { QFileOpenEvent urlTest(fileUrl); - checkReadAndWrite(urlTest, QLatin1String("test content+RFileWrite+nameWrite"), QLatin1String("+urlWrite"), true); + checkReadAndWrite(urlTest, QByteArray("test content+RFileWrite+nameWrite"), QByteArray("+urlWrite"), true); } + + QFile::remove(QLatin1String("testFileOpen")); } void tst_qfileopenevent::handleLifetime() { - RFile rFile = createRFile(_L("testHandleLifetime"), _L8("test content")); - QScopedPointer event(new QFileOpenEvent(rFile)); - rFile.Close(); + QScopedPointer event(createFileAndEvent(QLatin1String("testHandleLifetime"), QByteArray("test content"))); // open a QFile after the original RFile is closed QFile qFile; @@ -195,17 +241,18 @@ void tst_qfileopenevent::handleLifetime() check.open(QFile::ReadOnly); QString content(check.readAll()); QCOMPARE(content, QLatin1String("test content+closed original handles")); + check.close(); + + QFile::remove(QLatin1String("testHandleLifetime")); } void tst_qfileopenevent::multiOpen() { - RFile rFile = createRFile(_L("testMultiOpen"), _L8("itlum")); - QFileOpenEvent event(rFile); - rFile.Close(); + QScopedPointer event(createFileAndEvent(QLatin1String("testMultiOpen"), QByteArray("itlum"))); QFile files[5]; for (int i=0; i<5; i++) { - QCOMPARE(event.openFile(files[i], QFile::ReadOnly), true); + QCOMPARE(event->openFile(files[i], QFile::ReadOnly), true); } for (int i=0; i<5; i++) files[i].seek(i); @@ -217,6 +264,8 @@ void tst_qfileopenevent::multiOpen() files[i].close(); } QCOMPARE(str, QLatin1String("multi")); + + QFile::remove(QLatin1String("testMultiOpen")); } bool tst_qfileopenevent::event(QEvent *event) @@ -230,10 +279,9 @@ bool tst_qfileopenevent::event(QEvent *event) void tst_qfileopenevent::sendAndReceive() { - RFile rFile = createRFile(_L("testSendAndReceive"), _L8("sending")); - QFileOpenEvent* event = new QFileOpenEvent(rFile); - rFile.Close(); - QCoreApplication::instance()->postEvent(this, event); + QScopedPointer event(createFileAndEvent(QLatin1String("testSendAndReceive"), QByteArray("sending"))); + + QCoreApplication::instance()->postEvent(this, event.take()); QCoreApplication::instance()->processEvents(); // check the content @@ -241,6 +289,9 @@ void tst_qfileopenevent::sendAndReceive() QCOMPARE(check.open(QFile::ReadOnly), true); QString content(check.readAll()); QCOMPARE(content, QLatin1String("sending+received")); + check.close(); + + QFile::remove(QLatin1String("testSendAndReceive")); } void tst_qfileopenevent::external_data() @@ -261,6 +312,10 @@ void tst_qfileopenevent::external_data() void tst_qfileopenevent::external() { +#ifndef Q_OS_SYMBIAN + QSKIP("external app file open test only valid in Symbian", SkipAll); +#else + QFETCH(QString, filename); QFETCH(QByteArray, targetContent); QFETCH(bool, sendHandle); @@ -295,10 +350,10 @@ void tst_qfileopenevent::external() QCOMPARE(check.open(QFile::ReadOnly), true); QCOMPARE(check.readAll(), targetContent); bool ok = check.remove(); + + QFile::remove(filename); +#endif } QTEST_MAIN(tst_qfileopenevent) #include "tst_qfileopenevent.moc" -#else -QTEST_NOOP_MAIN -#endif -- cgit v0.12 From 4a7d16cf81c0d66f18b228359dbad983d5057ea9 Mon Sep 17 00:00:00 2001 From: mread Date: Thu, 20 Jan 2011 15:44:02 +0000 Subject: Fixed qfilesystemmodel autotest The qfilesystemmodel autotest was failing on Symbian devices where there were bad drives. These do not appear in the file system model root list, but do appear in QDir::drives, giving different results. The test now filters the bad drives out of the drives list before comparing the counts. Task-number: QTBUG-15015 Reviewed-by: Shane Kearns --- tests/auto/qfilesystemmodel/tst_qfilesystemmodel.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/auto/qfilesystemmodel/tst_qfilesystemmodel.cpp b/tests/auto/qfilesystemmodel/tst_qfilesystemmodel.cpp index cf0406c..53781c9 100644 --- a/tests/auto/qfilesystemmodel/tst_qfilesystemmodel.cpp +++ b/tests/auto/qfilesystemmodel/tst_qfilesystemmodel.cpp @@ -980,8 +980,12 @@ void tst_QFileSystemModel::drives() model.setRootPath(path); model.fetchMore(QModelIndex()); QFileInfoList drives = QDir::drives(); + int driveCount = 0; + foreach(const QFileInfo& driveRoot, drives) + if (driveRoot.exists()) + driveCount++; QTest::qWait(5000); - QTRY_COMPARE(model.rowCount(), drives.count()); + QTRY_COMPARE(model.rowCount(), driveCount); } void tst_QFileSystemModel::dirsBeforeFiles() -- cgit v0.12 From 4aa2a69e82aa306735884c6c6b763eb2d5cb6c9e Mon Sep 17 00:00:00 2001 From: mread Date: Wed, 26 Jan 2011 14:29:50 +0000 Subject: commented out unused function argument Task-number: QTBUG-15015 Reviewed-by: Shane Kearns --- src/gui/s60framework/qs60mainappui.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/s60framework/qs60mainappui.cpp b/src/gui/s60framework/qs60mainappui.cpp index 8ae43a5..0c99f80 100644 --- a/src/gui/s60framework/qs60mainappui.cpp +++ b/src/gui/s60framework/qs60mainappui.cpp @@ -405,7 +405,7 @@ void QS60MainAppUi::HandleForegroundEventL(TBool aForeground) /*! \internal */ -TBool QS60MainAppUi::ProcessCommandParametersL(TApaCommand /*aCommand*/, TFileName &aDocumentName, const TDesC8 &/*aTail*/) +TBool QS60MainAppUi::ProcessCommandParametersL(TApaCommand /*aCommand*/, TFileName &/*aDocumentName*/, const TDesC8 &/*aTail*/) { // bypass CEikAppUi::ProcessCommandParametersL(..) which modifies aDocumentName, preventing apparc document opening from working. // The return value is effectively unused in Qt apps (see QS60MainDocument::OpenFileL) -- cgit v0.12 From 50472582da88bcbe2f32f7d0d31c0b74ea362404 Mon Sep 17 00:00:00 2001 From: mread Date: Thu, 27 Jan 2011 11:42:37 +0000 Subject: Removing unnecessary settings from test app .pro file From review, UID does not need to be specified and DEBUGGABLE_UDEBONLY is also unnecessary. Task-number: QTBUG-15015 Reviewed-by: Shane Kearns --- .../qfileopenevent/qfileopeneventexternal/qfileopeneventexternal.pro | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/auto/qfileopenevent/qfileopeneventexternal/qfileopeneventexternal.pro b/tests/auto/qfileopenevent/qfileopeneventexternal/qfileopeneventexternal.pro index 1b888b8..b95ed45 100644 --- a/tests/auto/qfileopenevent/qfileopeneventexternal/qfileopeneventexternal.pro +++ b/tests/auto/qfileopenevent/qfileopeneventexternal/qfileopeneventexternal.pro @@ -3,8 +3,6 @@ TARGET = qfileopeneventexternal QT += core gui SOURCES += qfileopeneventexternal.cpp symbian: { - TARGET.UID3 = 0xe9410b39 - MMP_RULES += DEBUGGABLE_UDEBONLY RSS_RULES += "embeddability=KAppEmbeddable;" RSS_RULES.datatype_list += "priority = EDataTypePriorityHigh; type = \"application/x-tst_qfileopenevent\";" LIBS += -lapparc \ -- cgit v0.12 From 6752786243d3aaa463ccf5055b209586aa4c6091 Mon Sep 17 00:00:00 2001 From: mread Date: Fri, 4 Feb 2011 13:04:41 +0000 Subject: Added file header autotest detected that qfileopeneventexternal.cpp was failing the licenseCheck (headers) test - so the right header was added Task-number: QTBUG-15015 Reviewed-by: joao --- .../qfileopeneventexternal.cpp | 41 ++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/tests/auto/qfileopenevent/qfileopeneventexternal/qfileopeneventexternal.cpp b/tests/auto/qfileopenevent/qfileopeneventexternal/qfileopeneventexternal.cpp index 45e7acc..0a5e032 100644 --- a/tests/auto/qfileopenevent/qfileopeneventexternal/qfileopeneventexternal.cpp +++ b/tests/auto/qfileopenevent/qfileopeneventexternal/qfileopeneventexternal.cpp @@ -1,3 +1,44 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + #include #include #include -- cgit v0.12 From 7ed338b87ae50388101176ee29e72df55208a12c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Abecasis?= Date: Fri, 4 Feb 2011 15:21:25 +0100 Subject: Add QDir/tree benchmark to "trusted" list --- tests/benchmarks/corelib/corelib.pro | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/benchmarks/corelib/corelib.pro b/tests/benchmarks/corelib/corelib.pro index 335280e..a2efe91 100644 --- a/tests/benchmarks/corelib/corelib.pro +++ b/tests/benchmarks/corelib/corelib.pro @@ -11,6 +11,7 @@ TRUSTED_BENCHMARKS += \ kernel/qmetaobject \ kernel/qmetatype \ kernel/qobject \ - thread/qthreadstorage + thread/qthreadstorage \ + io/qdir/tree include(../trusted-benchmarks.pri) \ No newline at end of file -- cgit v0.12 From b5e5f72faea7ae278572660f8fb6968d635e548f Mon Sep 17 00:00:00 2001 From: Harald Fernengel Date: Thu, 10 Feb 2011 16:17:58 +0100 Subject: fix crash when setting QPROCESS_DEBUG don't pass QStrings to printf, but use qPrintable instead. --- src/corelib/io/qprocess_unix.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/corelib/io/qprocess_unix.cpp b/src/corelib/io/qprocess_unix.cpp index f9f5362..ba61bda 100644 --- a/src/corelib/io/qprocess_unix.cpp +++ b/src/corelib/io/qprocess_unix.cpp @@ -645,7 +645,7 @@ void QProcessPrivate::startProcess() if (childPid < 0) { // Cleanup, report error and return #if defined (QPROCESS_DEBUG) - qDebug("qt_fork failed: %s", qt_error_string(lastForkErrno)); + qDebug("qt_fork failed: %s", qPrintable(qt_error_string(lastForkErrno))); #endif processManager()->unlock(); q->setProcessState(QProcess::NotRunning); @@ -849,7 +849,7 @@ qint64 QProcessPrivate::writeToStdin(const char *data, qint64 maxlen) qDebug("QProcessPrivate::writeToStdin(%p \"%s\", %lld) == %lld", data, qt_prettyDebug(data, maxlen, 16).constData(), maxlen, written); if (written == -1) - qDebug("QProcessPrivate::writeToStdin(), failed to write (%s)", qt_error_string(errno)); + qDebug("QProcessPrivate::writeToStdin(), failed to write (%s)", qPrintable(qt_error_string(errno))); #endif // If the O_NONBLOCK flag is set and If some data can be written without blocking // the process, write() will transfer what it can and return the number of bytes written. -- cgit v0.12 From 3f3a0f31b74774051021d969e008d7bd1536b010 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Abecasis?= Date: Tue, 15 Feb 2011 17:26:48 +0100 Subject: Workaround for QTBUG-17468 On Mac, processEvents doesn't always process posted events. Reviewed-by: Olivier Goffart --- tests/auto/qfileopenevent/test/tst_qfileopenevent.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/auto/qfileopenevent/test/tst_qfileopenevent.cpp b/tests/auto/qfileopenevent/test/tst_qfileopenevent.cpp index 4f10d31..1177131 100644 --- a/tests/auto/qfileopenevent/test/tst_qfileopenevent.cpp +++ b/tests/auto/qfileopenevent/test/tst_qfileopenevent.cpp @@ -284,6 +284,9 @@ void tst_qfileopenevent::sendAndReceive() QCoreApplication::instance()->postEvent(this, event.take()); QCoreApplication::instance()->processEvents(); + // QTBUG-17468: On Mac, processEvents doesn't always process posted events + QCoreApplication::instance()->sendPostedEvents(); + // check the content QFile check("testSendAndReceive"); QCOMPARE(check.open(QFile::ReadOnly), true); -- cgit v0.12