summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tests/auto/symbian/qfileopenevent/qfileopenevent.pro10
-rw-r--r--tests/auto/symbian/qfileopenevent/qfileopeneventexternal/qfileopeneventexternal.cpp40
-rw-r--r--tests/auto/symbian/qfileopenevent/qfileopeneventexternal/qfileopeneventexternal.pro12
-rw-r--r--tests/auto/symbian/qfileopenevent/test/tst_qfileopenevent.cpp (renamed from tests/auto/symbian/qfileopenevent/tst_qfileopenevent.cpp)138
-rw-r--r--tests/auto/symbian/qfileopenevent/test/tst_qfileopenevent.pro7
5 files changed, 191 insertions, 16 deletions
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 <QtGui>
+#include <QApplication>
+#include <QEvent>
+
+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<QFileOpenEvent *>(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/tst_qfileopenevent.cpp b/tests/auto/symbian/qfileopenevent/test/tst_qfileopenevent.cpp
index 85ec04d..77d53aa 100644
--- a/tests/auto/symbian/qfileopenevent/tst_qfileopenevent.cpp
+++ b/tests/auto/symbian/qfileopenevent/test/tst_qfileopenevent.cpp
@@ -43,6 +43,8 @@
#include <QEvent>
#ifdef Q_OS_SYMBIAN
+#include <apgcli.h>
+#include "private/qcore_symbian_p.h"
class tst_qfileopenevent : public QObject
{
@@ -60,8 +62,8 @@ private slots:
void handleLifetime();
void multiOpen();
void sendAndReceive();
- void viaApparc();
- void viasDocHandler();
+ void external_data();
+ void external();
private:
RFile createRFile(const TDesC& filename, const TDesC8& content);
@@ -69,6 +71,8 @@ private:
QString readFileContent(QFileOpenEvent& event);
bool appendFileContent(QFileOpenEvent& event, const QString& writeContent);
+ bool event(QEvent *);
+
private:
RFs fsSession;
};
@@ -81,6 +85,7 @@ tst_qfileopenevent::~tst_qfileopenevent()
void tst_qfileopenevent::initTestCase()
{
qt_symbian_throwIfError(fsSession.Connect());
+ qt_symbian_throwIfError(fsSession.ShareProtected());
}
RFile tst_qfileopenevent::createRFile(const TDesC& filename, const TDesC8& content)
@@ -144,41 +149,152 @@ void tst_qfileopenevent::fileOpen()
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);
+ QFileOpenEvent rFileTest(rFile);
+ checkReadAndWrite(rFileTest, QLatin1String("test content+RFileWrite"), QLatin1String("+RFileRead"), false);
rFile.Close();
}
-
- // test it with read and write
+
// filename event
- // test it with read and write
+ 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
- // test it with read and write
+ {
+ 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<QFileOpenEvent> 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<QFileOpenEvent *>(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::viaApparc()
+void tst_qfileopenevent::external_data()
{
+ QTest::addColumn<QString>("filename");
+ QTest::addColumn<QByteArray>("targetContent");
+ QTest::addColumn<bool>("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::viasDocHandler()
+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)
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
+}