From 7ca8482115ab159b6fdea9fbff6839700dd8ee6e Mon Sep 17 00:00:00 2001 From: kh1 Date: Tue, 16 Feb 2010 12:04:14 +0100 Subject: Fix broken image loading on windows. Make sure the url is valid and we could find the file in the compressed help, otherwise pass on an error message. We might have got garbage in the first patch, so the isEmpty() check was not sufficient. Do not integrate in master, since it was fixed already there. Task-number: QTBUG-8082, QTBUG-8248 Reviewed-by: ck --- tools/assistant/tools/assistant/helpviewer.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/assistant/tools/assistant/helpviewer.cpp b/tools/assistant/tools/assistant/helpviewer.cpp index be6245a..f22ab8a 100644 --- a/tools/assistant/tools/assistant/helpviewer.cpp +++ b/tools/assistant/tools/assistant/helpviewer.cpp @@ -151,8 +151,9 @@ QNetworkReply *HelpNetworkAccessManager::createRequest(Operation /*op*/, mimeType = QLatin1String("text/html"); } - const QByteArray &ba = helpEngine->fileData(url); - return new HelpNetworkReply(request, ba.isEmpty() ? " " : ba, mimeType); + const QByteArray &data = helpEngine->findFile(url).isValid() + ? helpEngine->fileData(url) : QByteArray("File not found!"); + return new HelpNetworkReply(request, data, mimeType); } class HelpPage : public QWebPage -- cgit v0.12 From fdd305d4186919c9f75330b1dfd8aaed520d8430 Mon Sep 17 00:00:00 2001 From: Miikka Heikkinen Date: Tue, 16 Feb 2010 15:58:10 +0200 Subject: Only use unix-like tools when not building for Symbian in Windows. Having sh.exe but not the other unix-like basic tools in the path made distclean break in Windows. Task-number: QTBUG-7883 Reviewed-by: axis --- mkspecs/common/symbian/symbian.conf | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/mkspecs/common/symbian/symbian.conf b/mkspecs/common/symbian/symbian.conf index 6113746..7b2ee91 100644 --- a/mkspecs/common/symbian/symbian.conf +++ b/mkspecs/common/symbian/symbian.conf @@ -75,15 +75,7 @@ QMAKE_LIBS_COMPAT = QMAKE_LIBS_QT_ENTRY = -llibcrt0.lib QMAKE_LIBS_S60 = -lavkon -!isEmpty(QMAKE_SH) { - QMAKE_COPY = cp - QMAKE_COPY_DIR = cp -r - QMAKE_MOVE = mv - QMAKE_DEL_FILE = rm -f - QMAKE_MKDIR = mkdir - QMAKE_DEL_DIR = rmdir - QMAKE_CHK_DIR_EXISTS = test -d -} else { +contains(QMAKE_HOST.os,Windows) { QMAKE_COPY = copy /y QMAKE_COPY_DIR = xcopy /s /q /y /i QMAKE_MOVE = move @@ -91,6 +83,14 @@ QMAKE_LIBS_S60 = -lavkon QMAKE_MKDIR = mkdir QMAKE_DEL_DIR = rmdir QMAKE_CHK_DIR_EXISTS = if not exist +} else { + QMAKE_COPY = cp + QMAKE_COPY_DIR = cp -r + QMAKE_MOVE = mv + QMAKE_DEL_FILE = rm -f + QMAKE_MKDIR = mkdir + QMAKE_DEL_DIR = rmdir + QMAKE_CHK_DIR_EXISTS = test -d } QMAKE_MOC = $$[QT_INSTALL_BINS]$${DIR_SEPARATOR}moc.exe -- cgit v0.12 From 6c67fef3218ec5361b3f9a30fc53c529295da9e4 Mon Sep 17 00:00:00 2001 From: Gareth Stockwell Date: Tue, 16 Feb 2010 11:25:41 +0000 Subject: Added missing override in audio output example Because the QIODevice-derived class Generator owns its own internal buffer, it must override bytesAvailable(). Reviewed-by: trustme --- examples/multimedia/audiooutput/audiooutput.cpp | 5 +++++ examples/multimedia/audiooutput/audiooutput.h | 1 + 2 files changed, 6 insertions(+) diff --git a/examples/multimedia/audiooutput/audiooutput.cpp b/examples/multimedia/audiooutput/audiooutput.cpp index b44accd..9a9af86 100644 --- a/examples/multimedia/audiooutput/audiooutput.cpp +++ b/examples/multimedia/audiooutput/audiooutput.cpp @@ -75,6 +75,11 @@ void Generator::start() open(QIODevice::ReadOnly); } +qint64 Generator::bytesAvailable() const +{ + return (SECONDS*SYSTEM_FREQ*2)-pos + QIODevice::bytesAvailable(); +} + void Generator::stop() { close(); diff --git a/examples/multimedia/audiooutput/audiooutput.h b/examples/multimedia/audiooutput/audiooutput.h index 372cf78..eba6446 100644 --- a/examples/multimedia/audiooutput/audiooutput.h +++ b/examples/multimedia/audiooutput/audiooutput.h @@ -72,6 +72,7 @@ public: qint64 readData(char *data, qint64 maxlen); qint64 writeData(const char *data, qint64 len); + qint64 bytesAvailable() const; private: int putShort(char *t, unsigned int value); -- cgit v0.12 From b03306503cc7de9513aa282b55bda40cea00e128 Mon Sep 17 00:00:00 2001 From: Gareth Stockwell Date: Tue, 16 Feb 2010 11:26:49 +0000 Subject: Update suspend/resume button label in audio output example When the mode is toggled, playback is always started, even if the audio output device was previously suspended. The label on the suspend/resume button must therefore be updated. Reviewed-by: trustme --- examples/multimedia/audiooutput/audiooutput.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/examples/multimedia/audiooutput/audiooutput.cpp b/examples/multimedia/audiooutput/audiooutput.cpp index 9a9af86..d4bb294 100644 --- a/examples/multimedia/audiooutput/audiooutput.cpp +++ b/examples/multimedia/audiooutput/audiooutput.cpp @@ -262,6 +262,8 @@ void AudioTest::toggle() pullMode = true; audioOutput->start(gen); } + + button2->setText("Click To Suspend"); } void AudioTest::togglePlay() -- cgit v0.12 From 53dc6607cf669b977ff40de995bd9b1b8e395b78 Mon Sep 17 00:00:00 2001 From: Gareth Stockwell Date: Tue, 16 Feb 2010 12:55:23 +0000 Subject: Made data generation in audio output example work for all formats The previous code only worked correctly for mono PCM16 formats. This meant that: a) If the device did not support mono, but did support stereo PCM16, the tone would be played at the wrong pitch. b) If the device did not support little-endian PCM16 at all (admittedly unlikely), the example would not run. Reviewed-by: trustme --- examples/multimedia/audiooutput/audiooutput.cpp | 128 +++++++++++++----------- examples/multimedia/audiooutput/audiooutput.h | 19 ++-- 2 files changed, 75 insertions(+), 72 deletions(-) diff --git a/examples/multimedia/audiooutput/audiooutput.cpp b/examples/multimedia/audiooutput/audiooutput.cpp index d4bb294..d459e50e 100644 --- a/examples/multimedia/audiooutput/audiooutput.cpp +++ b/examples/multimedia/audiooutput/audiooutput.cpp @@ -44,30 +44,27 @@ #include #include +#include +#include #include "audiooutput.h" -#ifndef M_PI -#define M_PI 3.14159265358979323846 -#endif - #define SECONDS 1 #define FREQ 600 #define SYSTEM_FREQ 44100 -Generator::Generator(QObject *parent) - :QIODevice( parent ) +Generator::Generator(const QAudioFormat &format, + qint64 durationUs, + int frequency, + QObject *parent) + : QIODevice(parent) + , pos(0) { - finished = false; - buffer = new char[SECONDS*SYSTEM_FREQ*4+1000]; - t=buffer; - len=fillData(t,FREQ,SECONDS); /* mono FREQHz sine */ - pos = 0; - total = len; + generateData(format, durationUs, frequency); } Generator::~Generator() { - delete [] buffer; + } void Generator::start() @@ -75,54 +72,67 @@ void Generator::start() open(QIODevice::ReadOnly); } -qint64 Generator::bytesAvailable() const -{ - return (SECONDS*SYSTEM_FREQ*2)-pos + QIODevice::bytesAvailable(); -} - void Generator::stop() { + pos = 0; close(); } -int Generator::putShort(char *t, unsigned int value) +void Generator::generateData(const QAudioFormat &format, qint64 durationUs, int frequency) { - *(unsigned char *)(t++)=value&255; - *(unsigned char *)(t)=(value/256)&255; - return 2; -} - -int Generator::fillData(char *start, int frequency, int seconds) -{ - int i, len=0; - int value; - for(i=0; i(buffer.data()); + int sampleIndex = 0; + + while (length) { + const qreal x = qSin(2 * M_PI * frequency * qreal(sampleIndex % format.frequency()) / format.frequency()); + for (int i=0; i((1.0 + x) / 2 * 255); + *reinterpret_cast(ptr) = value; + } else if (format.sampleSize() == 8 && format.sampleType() == QAudioFormat::SignedInt) { + const qint8 value = static_cast(x * 127); + *reinterpret_cast(ptr) = value; + } else if (format.sampleSize() == 16 && format.sampleType() == QAudioFormat::UnSignedInt) { + quint16 value = static_cast((1.0 + x) / 2 * 65535); + if (format.byteOrder() == QAudioFormat::LittleEndian) + qToLittleEndian(value, ptr); + else + qToBigEndian(value, ptr); + } else if (format.sampleSize() == 16 && format.sampleType() == QAudioFormat::SignedInt) { + qint16 value = static_cast(x * 32767); + if (format.byteOrder() == QAudioFormat::LittleEndian) + qToLittleEndian(value, ptr); + else + qToBigEndian(value, ptr); + } + + ptr += channelBytes; + length -= channelBytes; + } + ++sampleIndex; } - return len; } -qint64 Generator::readData(char *data, qint64 maxlen) +qint64 Generator::readData(char *data, qint64 len) { - int len = maxlen; - if (len > 16384) - len = 16384; - - if (len < (SECONDS*SYSTEM_FREQ*2)-pos) { - // Normal - memcpy(data,t+pos,len); - pos+=len; - return len; - } else { - // Whats left and reset to start - qint64 left = (SECONDS*SYSTEM_FREQ*2)-pos; - memcpy(data,t+pos,left); - pos=0; - return left; + qint64 total = 0; + while (len - total) { + const qint64 chunk = qMin((buffer.size() - pos), len - total); + memcpy(data, buffer.constData() + pos, chunk); + pos = (pos + chunk) % buffer.size(); + total += chunk; } + return total; } qint64 Generator::writeData(const char *data, qint64 len) @@ -133,6 +143,11 @@ qint64 Generator::writeData(const char *data, qint64 len) return 0; } +qint64 Generator::bytesAvailable() const +{ + return buffer.size() + QIODevice::bytesAvailable(); +} + AudioTest::AudioTest() { QWidget *window = new QWidget; @@ -160,15 +175,11 @@ AudioTest::AudioTest() buffer = new char[BUFFER_SIZE]; - gen = new Generator(this); - pullMode = true; timer = new QTimer(this); connect(timer,SIGNAL(timeout()),SLOT(writeMore())); - gen->start(); - settings.setFrequency(SYSTEM_FREQ); settings.setChannels(1); settings.setSampleSize(16); @@ -182,13 +193,8 @@ AudioTest::AudioTest() settings = info.nearestFormat(settings); } - if(settings.sampleSize() != 16) { - qWarning()<<"audio device doesn't support 16 bit samples, example cannot run"; - button->setDisabled(true); - button2->setDisabled(true); - audioOutput = 0; - return; - } + gen = new Generator(settings, SECONDS*1000000, FREQ, this); + gen->start(); audioOutput = new QAudioOutput(settings,this); connect(audioOutput,SIGNAL(notify()),SLOT(status())); diff --git a/examples/multimedia/audiooutput/audiooutput.h b/examples/multimedia/audiooutput/audiooutput.h index eba6446..2c62d84 100644 --- a/examples/multimedia/audiooutput/audiooutput.h +++ b/examples/multimedia/audiooutput/audiooutput.h @@ -49,6 +49,7 @@ #include #include #include +#include #include @@ -56,27 +57,22 @@ class Generator : public QIODevice { Q_OBJECT public: - Generator(QObject *parent); + Generator(const QAudioFormat &format, qint64 durationUs, int frequency, QObject *parent); ~Generator(); void start(); void stop(); - char *t; - int len; - int pos; - int total; - char *buffer; - bool finished; - int chunk_size; - qint64 readData(char *data, qint64 maxlen); qint64 writeData(const char *data, qint64 len); qint64 bytesAvailable() const; private: - int putShort(char *t, unsigned int value); - int fillData(char *start, int frequency, int seconds); + void generateData(const QAudioFormat &format, qint64 durationUs, int frequency); + +private: + qint64 pos; + QByteArray buffer; }; class AudioTest : public QMainWindow @@ -86,6 +82,7 @@ public: AudioTest(); ~AudioTest(); +private: QAudioDeviceInfo device; Generator* gen; QAudioOutput* audioOutput; -- cgit v0.12 From d67acf30db19288928e31b569c373c0d4a369628 Mon Sep 17 00:00:00 2001 From: Gareth Stockwell Date: Tue, 16 Feb 2010 13:03:46 +0000 Subject: Changed variable names in audio output example to match Qt code style Also changed some names to better convey their meanings, e.g. button -> m_modeButton button2 -> m_suspendResumeButton Reviewed-by: trustme --- examples/multimedia/audiooutput/audiooutput.cpp | 158 ++++++++++++------------ examples/multimedia/audiooutput/audiooutput.h | 26 ++-- 2 files changed, 92 insertions(+), 92 deletions(-) diff --git a/examples/multimedia/audiooutput/audiooutput.cpp b/examples/multimedia/audiooutput/audiooutput.cpp index d459e50e..ce26664 100644 --- a/examples/multimedia/audiooutput/audiooutput.cpp +++ b/examples/multimedia/audiooutput/audiooutput.cpp @@ -57,7 +57,7 @@ Generator::Generator(const QAudioFormat &format, int frequency, QObject *parent) : QIODevice(parent) - , pos(0) + , m_pos(0) { generateData(format, durationUs, frequency); } @@ -74,7 +74,7 @@ void Generator::start() void Generator::stop() { - pos = 0; + m_pos = 0; close(); } @@ -89,8 +89,8 @@ void Generator::generateData(const QAudioFormat &format, qint64 durationUs, int Q_ASSERT(length % sampleBytes == 0); Q_UNUSED(sampleBytes) // suppress warning in release builds - buffer.resize(length); - unsigned char *ptr = reinterpret_cast(buffer.data()); + m_buffer.resize(length); + unsigned char *ptr = reinterpret_cast(m_buffer.data()); int sampleIndex = 0; while (length) { @@ -127,9 +127,9 @@ qint64 Generator::readData(char *data, qint64 len) { qint64 total = 0; while (len - total) { - const qint64 chunk = qMin((buffer.size() - pos), len - total); - memcpy(data, buffer.constData() + pos, chunk); - pos = (pos + chunk) % buffer.size(); + const qint64 chunk = qMin((m_buffer.size() - m_pos), len - total); + memcpy(data, m_buffer.constData() + m_pos, chunk); + m_pos = (m_pos + chunk) % m_buffer.size(); total += chunk; } return total; @@ -145,7 +145,7 @@ qint64 Generator::writeData(const char *data, qint64 len) qint64 Generator::bytesAvailable() const { - return buffer.size() + QIODevice::bytesAvailable(); + return m_buffer.size() + QIODevice::bytesAvailable(); } AudioTest::AudioTest() @@ -153,99 +153,99 @@ AudioTest::AudioTest() QWidget *window = new QWidget; QVBoxLayout* layout = new QVBoxLayout; - deviceBox = new QComboBox(this); + m_deviceBox = new QComboBox(this); foreach (const QAudioDeviceInfo &deviceInfo, QAudioDeviceInfo::availableDevices(QAudio::AudioOutput)) - deviceBox->addItem(deviceInfo.deviceName(), qVariantFromValue(deviceInfo)); - connect(deviceBox,SIGNAL(activated(int)),SLOT(deviceChanged(int))); - layout->addWidget(deviceBox); + m_deviceBox->addItem(deviceInfo.deviceName(), qVariantFromValue(deviceInfo)); + connect(m_deviceBox,SIGNAL(activated(int)),SLOT(deviceChanged(int))); + layout->addWidget(m_deviceBox); - button = new QPushButton(this); - button->setText(tr("Click for Push Mode")); - connect(button,SIGNAL(clicked()),SLOT(toggle())); - layout->addWidget(button); + m_modeButton = new QPushButton(this); + m_modeButton->setText(tr("Click for Push Mode")); + connect(m_modeButton,SIGNAL(clicked()),SLOT(toggle())); + layout->addWidget(m_modeButton); - button2 = new QPushButton(this); - button2->setText(tr("Click To Suspend")); - connect(button2,SIGNAL(clicked()),SLOT(togglePlay())); - layout->addWidget(button2); + m_suspendResumeButton = new QPushButton(this); + m_suspendResumeButton->setText(tr("Click To Suspend")); + connect(m_suspendResumeButton,SIGNAL(clicked()),SLOT(togglePlay())); + layout->addWidget(m_suspendResumeButton); window->setLayout(layout); setCentralWidget(window); window->show(); - buffer = new char[BUFFER_SIZE]; + m_buffer = new char[BUFFER_SIZE]; - pullMode = true; + m_pullMode = true; - timer = new QTimer(this); - connect(timer,SIGNAL(timeout()),SLOT(writeMore())); + m_timer = new QTimer(this); + connect(m_timer,SIGNAL(timeout()),SLOT(writeMore())); - settings.setFrequency(SYSTEM_FREQ); - settings.setChannels(1); - settings.setSampleSize(16); - settings.setCodec("audio/pcm"); - settings.setByteOrder(QAudioFormat::LittleEndian); - settings.setSampleType(QAudioFormat::SignedInt); + m_format.setFrequency(SYSTEM_FREQ); + m_format.setChannels(1); + m_format.setSampleSize(16); + m_format.setCodec("audio/pcm"); + m_format.setByteOrder(QAudioFormat::LittleEndian); + m_format.setSampleType(QAudioFormat::SignedInt); QAudioDeviceInfo info(QAudioDeviceInfo::defaultOutputDevice()); - if (!info.isFormatSupported(settings)) { + if (!info.isFormatSupported(m_format)) { qWarning()<<"default format not supported try to use nearest"; - settings = info.nearestFormat(settings); + m_format = info.nearestFormat(m_format); } - gen = new Generator(settings, SECONDS*1000000, FREQ, this); - gen->start(); + m_generator = new Generator(m_format, SECONDS*1000000, FREQ, this); + m_generator->start(); - audioOutput = new QAudioOutput(settings,this); - connect(audioOutput,SIGNAL(notify()),SLOT(status())); - connect(audioOutput,SIGNAL(stateChanged(QAudio::State)),SLOT(state(QAudio::State))); + m_audioOutput = new QAudioOutput(m_format,this); + connect(m_audioOutput,SIGNAL(notify()),SLOT(status())); + connect(m_audioOutput,SIGNAL(stateChanged(QAudio::State)),SLOT(state(QAudio::State))); - audioOutput->start(gen); + m_audioOutput->start(m_generator); } AudioTest::~AudioTest() { - delete [] buffer; + delete [] m_buffer; } void AudioTest::deviceChanged(int idx) { - timer->stop(); - gen->stop(); - audioOutput->stop(); - audioOutput->disconnect(this); - delete audioOutput; - - device = deviceBox->itemData(idx).value(); - audioOutput = new QAudioOutput(device,settings,this); - connect(audioOutput,SIGNAL(notify()),SLOT(status())); - connect(audioOutput,SIGNAL(stateChanged(QAudio::State)),SLOT(state(QAudio::State))); - gen->start(); - audioOutput->start(gen); + m_timer->stop(); + m_generator->stop(); + m_audioOutput->stop(); + m_audioOutput->disconnect(this); + delete m_audioOutput; + + m_device = m_deviceBox->itemData(idx).value(); + m_audioOutput = new QAudioOutput(m_device,m_format,this); + connect(m_audioOutput,SIGNAL(notify()),SLOT(status())); + connect(m_audioOutput,SIGNAL(stateChanged(QAudio::State)),SLOT(state(QAudio::State))); + m_generator->start(); + m_audioOutput->start(m_generator); } void AudioTest::status() { - qWarning() << "byteFree = " << audioOutput->bytesFree() << " bytes, elapsedUSecs = " << audioOutput->elapsedUSecs() << ", processedUSecs = " << audioOutput->processedUSecs(); + qWarning() << "byteFree = " << m_audioOutput->bytesFree() << " bytes, elapsedUSecs = " << m_audioOutput->elapsedUSecs() << ", processedUSecs = " << m_audioOutput->processedUSecs(); } void AudioTest::writeMore() { - if (!audioOutput) + if (!m_audioOutput) return; - if (audioOutput->state() == QAudio::StoppedState) + if (m_audioOutput->state() == QAudio::StoppedState) return; int l; int out; - int chunks = audioOutput->bytesFree()/audioOutput->periodSize(); + int chunks = m_audioOutput->bytesFree()/m_audioOutput->periodSize(); while(chunks) { - l = gen->read(buffer,audioOutput->periodSize()); + l = m_generator->read(m_buffer,m_audioOutput->periodSize()); if (l > 0) - out = output->write(buffer,l); - if (l != audioOutput->periodSize()) + out = m_output->write(m_buffer,l); + if (l != m_audioOutput->periodSize()) break; chunks--; } @@ -255,39 +255,39 @@ void AudioTest::toggle() { // Change between pull and push modes - timer->stop(); - audioOutput->stop(); + m_timer->stop(); + m_audioOutput->stop(); - if (pullMode) { - button->setText("Click for Pull Mode"); - output = audioOutput->start(); - pullMode = false; - timer->start(20); + if (m_pullMode) { + m_modeButton->setText("Click for Pull Mode"); + m_output = m_audioOutput->start(); + m_pullMode = false; + m_timer->start(20); } else { - button->setText("Click for Push Mode"); - pullMode = true; - audioOutput->start(gen); + m_modeButton->setText("Click for Push Mode"); + m_pullMode = true; + m_audioOutput->start(m_generator); } - button2->setText("Click To Suspend"); + m_suspendResumeButton->setText("Click To Suspend"); } void AudioTest::togglePlay() { // toggle suspend/resume - if (audioOutput->state() == QAudio::SuspendedState) { + if (m_audioOutput->state() == QAudio::SuspendedState) { qWarning() << "status: Suspended, resume()"; - audioOutput->resume(); - button2->setText("Click To Suspend"); - } else if (audioOutput->state() == QAudio::ActiveState) { + m_audioOutput->resume(); + m_suspendResumeButton->setText("Click To Suspend"); + } else if (m_audioOutput->state() == QAudio::ActiveState) { qWarning() << "status: Active, suspend()"; - audioOutput->suspend(); - button2->setText("Click To Resume"); - } else if (audioOutput->state() == QAudio::StoppedState) { + m_audioOutput->suspend(); + m_suspendResumeButton->setText("Click To Resume"); + } else if (m_audioOutput->state() == QAudio::StoppedState) { qWarning() << "status: Stopped, resume()"; - audioOutput->resume(); - button2->setText("Click To Suspend"); - } else if (audioOutput->state() == QAudio::IdleState) { + m_audioOutput->resume(); + m_suspendResumeButton->setText("Click To Suspend"); + } else if (m_audioOutput->state() == QAudio::IdleState) { qWarning() << "status: IdleState"; } } diff --git a/examples/multimedia/audiooutput/audiooutput.h b/examples/multimedia/audiooutput/audiooutput.h index 2c62d84..ac24a61 100644 --- a/examples/multimedia/audiooutput/audiooutput.h +++ b/examples/multimedia/audiooutput/audiooutput.h @@ -71,8 +71,8 @@ private: void generateData(const QAudioFormat &format, qint64 durationUs, int frequency); private: - qint64 pos; - QByteArray buffer; + qint64 m_pos; + QByteArray m_buffer; }; class AudioTest : public QMainWindow @@ -83,19 +83,19 @@ public: ~AudioTest(); private: - QAudioDeviceInfo device; - Generator* gen; - QAudioOutput* audioOutput; - QIODevice* output; - QTimer* timer; - QAudioFormat settings; + QAudioDeviceInfo m_device; + Generator* m_generator; + QAudioOutput* m_audioOutput; + QIODevice* m_output; + QTimer* m_timer; + QAudioFormat m_format; - bool pullMode; - char* buffer; + bool m_pullMode; + char* m_buffer; - QPushButton* button; - QPushButton* button2; - QComboBox* deviceBox; + QPushButton* m_modeButton; + QPushButton* m_suspendResumeButton; + QComboBox* m_deviceBox; private slots: void status(); -- cgit v0.12 From 84f129eb53532c85f4803e97837e61cea20469d1 Mon Sep 17 00:00:00 2001 From: Gareth Stockwell Date: Tue, 16 Feb 2010 13:17:34 +0000 Subject: Cleaned up memory management in audio output example Reviewed-by: trustme --- examples/multimedia/audiooutput/audiooutput.cpp | 64 ++++++++++++++++--------- examples/multimedia/audiooutput/audiooutput.h | 35 ++++++++------ 2 files changed, 61 insertions(+), 38 deletions(-) diff --git a/examples/multimedia/audiooutput/audiooutput.cpp b/examples/multimedia/audiooutput/audiooutput.cpp index ce26664..5e90b41 100644 --- a/examples/multimedia/audiooutput/audiooutput.cpp +++ b/examples/multimedia/audiooutput/audiooutput.cpp @@ -51,6 +51,7 @@ #define SECONDS 1 #define FREQ 600 #define SYSTEM_FREQ 44100 +const int BufferSize = 32768; Generator::Generator(const QAudioFormat &format, qint64 durationUs, @@ -149,9 +150,23 @@ qint64 Generator::bytesAvailable() const } AudioTest::AudioTest() + : m_timer(new QTimer(this)) + , m_modeButton(0) + , m_suspendResumeButton(0) + , m_deviceBox(0) + , m_generator(0) + , m_audioOutput(0) + , m_output(0) + , m_buffer(BufferSize, 0) { - QWidget *window = new QWidget; - QVBoxLayout* layout = new QVBoxLayout; + initializeWindow(); + initializeAudio(); +} + +void AudioTest::initializeWindow() +{ + QScopedPointer window(new QWidget); + QScopedPointer layout(new QVBoxLayout); m_deviceBox = new QComboBox(this); foreach (const QAudioDeviceInfo &deviceInfo, QAudioDeviceInfo::availableDevices(QAudio::AudioOutput)) @@ -169,16 +184,19 @@ AudioTest::AudioTest() connect(m_suspendResumeButton,SIGNAL(clicked()),SLOT(togglePlay())); layout->addWidget(m_suspendResumeButton); - window->setLayout(layout); - setCentralWidget(window); - window->show(); + window->setLayout(layout.data()); + layout.take(); // ownership transferred - m_buffer = new char[BUFFER_SIZE]; + setCentralWidget(window.data()); + QWidget *const windowPtr = window.take(); // ownership transferred + windowPtr->show(); +} - m_pullMode = true; +void AudioTest::initializeAudio() +{ + connect(m_timer, SIGNAL(timeout()), SLOT(writeMore())); - m_timer = new QTimer(this); - connect(m_timer,SIGNAL(timeout()),SLOT(writeMore())); + m_pullMode = true; m_format.setFrequency(SYSTEM_FREQ); m_format.setChannels(1); @@ -194,18 +212,24 @@ AudioTest::AudioTest() } m_generator = new Generator(m_format, SECONDS*1000000, FREQ, this); - m_generator->start(); - m_audioOutput = new QAudioOutput(m_format,this); - connect(m_audioOutput,SIGNAL(notify()),SLOT(status())); - connect(m_audioOutput,SIGNAL(stateChanged(QAudio::State)),SLOT(state(QAudio::State))); + createAudioOutput(); +} +void AudioTest::createAudioOutput() +{ + delete m_audioOutput; + m_audioOutput = 0; + m_audioOutput = new QAudioOutput(m_format, this); + connect(m_audioOutput, SIGNAL(notify()), SLOT(status())); + connect(m_audioOutput, SIGNAL(stateChanged(QAudio::State)), SLOT(state(QAudio::State))); + m_generator->start(); m_audioOutput->start(m_generator); } AudioTest::~AudioTest() { - delete [] m_buffer; + } void AudioTest::deviceChanged(int idx) @@ -214,14 +238,8 @@ void AudioTest::deviceChanged(int idx) m_generator->stop(); m_audioOutput->stop(); m_audioOutput->disconnect(this); - delete m_audioOutput; - m_device = m_deviceBox->itemData(idx).value(); - m_audioOutput = new QAudioOutput(m_device,m_format,this); - connect(m_audioOutput,SIGNAL(notify()),SLOT(status())); - connect(m_audioOutput,SIGNAL(stateChanged(QAudio::State)),SLOT(state(QAudio::State))); - m_generator->start(); - m_audioOutput->start(m_generator); + createAudioOutput(); } void AudioTest::status() @@ -242,9 +260,9 @@ void AudioTest::writeMore() int chunks = m_audioOutput->bytesFree()/m_audioOutput->periodSize(); while(chunks) { - l = m_generator->read(m_buffer,m_audioOutput->periodSize()); + l = m_generator->read(m_buffer.data(), m_audioOutput->periodSize()); if (l > 0) - out = m_output->write(m_buffer,l); + out = m_output->write(m_buffer.data(), l); if (l != m_audioOutput->periodSize()) break; chunks--; diff --git a/examples/multimedia/audiooutput/audiooutput.h b/examples/multimedia/audiooutput/audiooutput.h index ac24a61..5bf8091 100644 --- a/examples/multimedia/audiooutput/audiooutput.h +++ b/examples/multimedia/audiooutput/audiooutput.h @@ -41,8 +41,6 @@ #include -#define BUFFER_SIZE 32768 - #include #include #include @@ -83,19 +81,26 @@ public: ~AudioTest(); private: - QAudioDeviceInfo m_device; - Generator* m_generator; - QAudioOutput* m_audioOutput; - QIODevice* m_output; - QTimer* m_timer; - QAudioFormat m_format; - - bool m_pullMode; - char* m_buffer; - - QPushButton* m_modeButton; - QPushButton* m_suspendResumeButton; - QComboBox* m_deviceBox; + void initializeWindow(); + void initializeAudio(); + void createAudioOutput(); + +private: + QTimer* m_timer; + + // Owned by layout + QPushButton* m_modeButton; + QPushButton* m_suspendResumeButton; + QComboBox* m_deviceBox; + + QAudioDeviceInfo m_device; + Generator* m_generator; + QAudioOutput* m_audioOutput; + QIODevice* m_output; // not owned + QAudioFormat m_format; + + bool m_pullMode; + QByteArray m_buffer; private slots: void status(); -- cgit v0.12 From 658a559c918bd16b4e3f5af3e25242086a781220 Mon Sep 17 00:00:00 2001 From: Gareth Stockwell Date: Tue, 16 Feb 2010 13:24:14 +0000 Subject: Removed redundant strings from audio output example Reviewed-by: trustme --- examples/multimedia/audiooutput/audiooutput.cpp | 32 +++++++++++++++---------- examples/multimedia/audiooutput/audiooutput.h | 5 ++++ 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/examples/multimedia/audiooutput/audiooutput.cpp b/examples/multimedia/audiooutput/audiooutput.cpp index 5e90b41..f60d7b6 100644 --- a/examples/multimedia/audiooutput/audiooutput.cpp +++ b/examples/multimedia/audiooutput/audiooutput.cpp @@ -48,11 +48,17 @@ #include #include "audiooutput.h" -#define SECONDS 1 -#define FREQ 600 -#define SYSTEM_FREQ 44100 +const QString AudioTest::PushModeLabel(tr("Enable push mode")); +const QString AudioTest::PullModeLabel(tr("Enable pull mode")); +const QString AudioTest::SuspendLabel(tr("Suspend playback")); +const QString AudioTest::ResumeLabel(tr("Resume playback")); + +const int DurationSeconds = 1; +const int ToneFrequencyHz = 600; +const int DataFrequencyHz = 44100; const int BufferSize = 32768; + Generator::Generator(const QAudioFormat &format, qint64 durationUs, int frequency, @@ -175,12 +181,12 @@ void AudioTest::initializeWindow() layout->addWidget(m_deviceBox); m_modeButton = new QPushButton(this); - m_modeButton->setText(tr("Click for Push Mode")); + m_modeButton->setText(PushModeLabel); connect(m_modeButton,SIGNAL(clicked()),SLOT(toggle())); layout->addWidget(m_modeButton); m_suspendResumeButton = new QPushButton(this); - m_suspendResumeButton->setText(tr("Click To Suspend")); + m_suspendResumeButton->setText(SuspendLabel); connect(m_suspendResumeButton,SIGNAL(clicked()),SLOT(togglePlay())); layout->addWidget(m_suspendResumeButton); @@ -198,7 +204,7 @@ void AudioTest::initializeAudio() m_pullMode = true; - m_format.setFrequency(SYSTEM_FREQ); + m_format.setFrequency(DataFrequencyHz); m_format.setChannels(1); m_format.setSampleSize(16); m_format.setCodec("audio/pcm"); @@ -211,7 +217,7 @@ void AudioTest::initializeAudio() m_format = info.nearestFormat(m_format); } - m_generator = new Generator(m_format, SECONDS*1000000, FREQ, this); + m_generator = new Generator(m_format, DurationSeconds*1000000, ToneFrequencyHz, this); createAudioOutput(); } @@ -277,17 +283,17 @@ void AudioTest::toggle() m_audioOutput->stop(); if (m_pullMode) { - m_modeButton->setText("Click for Pull Mode"); + m_modeButton->setText(PullModeLabel); m_output = m_audioOutput->start(); m_pullMode = false; m_timer->start(20); } else { - m_modeButton->setText("Click for Push Mode"); + m_modeButton->setText(PushModeLabel); m_pullMode = true; m_audioOutput->start(m_generator); } - m_suspendResumeButton->setText("Click To Suspend"); + m_suspendResumeButton->setText(SuspendLabel); } void AudioTest::togglePlay() @@ -296,15 +302,15 @@ void AudioTest::togglePlay() if (m_audioOutput->state() == QAudio::SuspendedState) { qWarning() << "status: Suspended, resume()"; m_audioOutput->resume(); - m_suspendResumeButton->setText("Click To Suspend"); + m_suspendResumeButton->setText(SuspendLabel); } else if (m_audioOutput->state() == QAudio::ActiveState) { qWarning() << "status: Active, suspend()"; m_audioOutput->suspend(); - m_suspendResumeButton->setText("Click To Resume"); + m_suspendResumeButton->setText(ResumeLabel); } else if (m_audioOutput->state() == QAudio::StoppedState) { qWarning() << "status: Stopped, resume()"; m_audioOutput->resume(); - m_suspendResumeButton->setText("Click To Suspend"); + m_suspendResumeButton->setText(SuspendLabel); } else if (m_audioOutput->state() == QAudio::IdleState) { qWarning() << "status: IdleState"; } diff --git a/examples/multimedia/audiooutput/audiooutput.h b/examples/multimedia/audiooutput/audiooutput.h index 5bf8091..ea47e8b 100644 --- a/examples/multimedia/audiooutput/audiooutput.h +++ b/examples/multimedia/audiooutput/audiooutput.h @@ -102,6 +102,11 @@ private: bool m_pullMode; QByteArray m_buffer; + static const QString PushModeLabel; + static const QString PullModeLabel; + static const QString SuspendLabel; + static const QString ResumeLabel; + private slots: void status(); void writeMore(); -- cgit v0.12 From 0ce346691dbf620db04a99699194d490f324b1be Mon Sep 17 00:00:00 2001 From: Gareth Stockwell Date: Tue, 16 Feb 2010 13:38:50 +0000 Subject: Tidied up debug output in audio output example Reviewed-by: trustme --- examples/multimedia/audiooutput/audiooutput.cpp | 12 +++++++----- examples/multimedia/audiooutput/audiooutput.h | 4 ++-- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/examples/multimedia/audiooutput/audiooutput.cpp b/examples/multimedia/audiooutput/audiooutput.cpp index f60d7b6..04e1923 100644 --- a/examples/multimedia/audiooutput/audiooutput.cpp +++ b/examples/multimedia/audiooutput/audiooutput.cpp @@ -213,7 +213,7 @@ void AudioTest::initializeAudio() QAudioDeviceInfo info(QAudioDeviceInfo::defaultOutputDevice()); if (!info.isFormatSupported(m_format)) { - qWarning()<<"default format not supported try to use nearest"; + qWarning() << "Default format not supported - trying to use nearest"; m_format = info.nearestFormat(m_format); } @@ -238,19 +238,21 @@ AudioTest::~AudioTest() } -void AudioTest::deviceChanged(int idx) +void AudioTest::deviceChanged(int index) { m_timer->stop(); m_generator->stop(); m_audioOutput->stop(); m_audioOutput->disconnect(this); - m_device = m_deviceBox->itemData(idx).value(); + m_device = m_deviceBox->itemData(index).value(); createAudioOutput(); } void AudioTest::status() { - qWarning() << "byteFree = " << m_audioOutput->bytesFree() << " bytes, elapsedUSecs = " << m_audioOutput->elapsedUSecs() << ", processedUSecs = " << m_audioOutput->processedUSecs(); + qWarning() << "bytesFree = " << m_audioOutput->bytesFree() + << ", " << "elapsedUSecs = " << m_audioOutput->elapsedUSecs() + << ", " << "processedUSecs = " << m_audioOutput->processedUSecs(); } void AudioTest::writeMore() @@ -318,5 +320,5 @@ void AudioTest::togglePlay() void AudioTest::state(QAudio::State state) { - qWarning() << " state=" << state; + qWarning() << "state = " << state; } diff --git a/examples/multimedia/audiooutput/audiooutput.h b/examples/multimedia/audiooutput/audiooutput.h index ea47e8b..1880d8d 100644 --- a/examples/multimedia/audiooutput/audiooutput.h +++ b/examples/multimedia/audiooutput/audiooutput.h @@ -112,7 +112,7 @@ private slots: void writeMore(); void toggle(); void togglePlay(); - void state(QAudio::State s); - void deviceChanged(int idx); + void state(QAudio::State state); + void deviceChanged(int index); }; -- cgit v0.12 From 3b2d9d0644a57ac377a7bcbfd40f8bd6da32cd1f Mon Sep 17 00:00:00 2001 From: Gareth Stockwell Date: Tue, 16 Feb 2010 13:41:18 +0000 Subject: Cleaned up implementation of audio output example Reviewed-by: trustme --- examples/multimedia/audiooutput/audiooutput.cpp | 27 +++++++++---------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/examples/multimedia/audiooutput/audiooutput.cpp b/examples/multimedia/audiooutput/audiooutput.cpp index 04e1923..0c44b4f 100644 --- a/examples/multimedia/audiooutput/audiooutput.cpp +++ b/examples/multimedia/audiooutput/audiooutput.cpp @@ -257,23 +257,16 @@ void AudioTest::status() void AudioTest::writeMore() { - if (!m_audioOutput) - return; - - if (m_audioOutput->state() == QAudio::StoppedState) - return; - - int l; - int out; - - int chunks = m_audioOutput->bytesFree()/m_audioOutput->periodSize(); - while(chunks) { - l = m_generator->read(m_buffer.data(), m_audioOutput->periodSize()); - if (l > 0) - out = m_output->write(m_buffer.data(), l); - if (l != m_audioOutput->periodSize()) - break; - chunks--; + if (m_audioOutput && m_audioOutput->state() != QAudio::StoppedState) { + int chunks = m_audioOutput->bytesFree()/m_audioOutput->periodSize(); + while (chunks) { + const qint64 len = m_generator->read(m_buffer.data(), m_audioOutput->periodSize()); + if (len) + m_output->write(m_buffer.data(), len); + if (len != m_audioOutput->periodSize()) + break; + --chunks; + } } } -- cgit v0.12 From 14c280f706c5612f6e01f5d6677cc85c88df7eb7 Mon Sep 17 00:00:00 2001 From: Gareth Stockwell Date: Tue, 16 Feb 2010 13:45:40 +0000 Subject: Changed function names in audio output example to clarify meaning Reviewed-by: trustme --- examples/multimedia/audiooutput/audiooutput.cpp | 31 +++++++++++-------------- examples/multimedia/audiooutput/audiooutput.h | 12 +++++----- 2 files changed, 20 insertions(+), 23 deletions(-) diff --git a/examples/multimedia/audiooutput/audiooutput.cpp b/examples/multimedia/audiooutput/audiooutput.cpp index 0c44b4f..4866d36 100644 --- a/examples/multimedia/audiooutput/audiooutput.cpp +++ b/examples/multimedia/audiooutput/audiooutput.cpp @@ -156,7 +156,7 @@ qint64 Generator::bytesAvailable() const } AudioTest::AudioTest() - : m_timer(new QTimer(this)) + : m_pullTimer(new QTimer(this)) , m_modeButton(0) , m_suspendResumeButton(0) , m_deviceBox(0) @@ -182,12 +182,12 @@ void AudioTest::initializeWindow() m_modeButton = new QPushButton(this); m_modeButton->setText(PushModeLabel); - connect(m_modeButton,SIGNAL(clicked()),SLOT(toggle())); + connect(m_modeButton, SIGNAL(clicked()), SLOT(toggleMode())); layout->addWidget(m_modeButton); m_suspendResumeButton = new QPushButton(this); m_suspendResumeButton->setText(SuspendLabel); - connect(m_suspendResumeButton,SIGNAL(clicked()),SLOT(togglePlay())); + connect(m_suspendResumeButton, SIGNAL(clicked()), SLOT(toggleSuspendResume())); layout->addWidget(m_suspendResumeButton); window->setLayout(layout.data()); @@ -200,7 +200,7 @@ void AudioTest::initializeWindow() void AudioTest::initializeAudio() { - connect(m_timer, SIGNAL(timeout()), SLOT(writeMore())); + connect(m_pullTimer, SIGNAL(timeout()), SLOT(pullTimerExpired())); m_pullMode = true; @@ -227,8 +227,8 @@ void AudioTest::createAudioOutput() delete m_audioOutput; m_audioOutput = 0; m_audioOutput = new QAudioOutput(m_format, this); - connect(m_audioOutput, SIGNAL(notify()), SLOT(status())); - connect(m_audioOutput, SIGNAL(stateChanged(QAudio::State)), SLOT(state(QAudio::State))); + connect(m_audioOutput, SIGNAL(notify()), SLOT(notified())); + connect(m_audioOutput, SIGNAL(stateChanged(QAudio::State)), SLOT(stateChanged(QAudio::State))); m_generator->start(); m_audioOutput->start(m_generator); } @@ -240,7 +240,7 @@ AudioTest::~AudioTest() void AudioTest::deviceChanged(int index) { - m_timer->stop(); + m_pullTimer->stop(); m_generator->stop(); m_audioOutput->stop(); m_audioOutput->disconnect(this); @@ -248,14 +248,14 @@ void AudioTest::deviceChanged(int index) createAudioOutput(); } -void AudioTest::status() +void AudioTest::notified() { qWarning() << "bytesFree = " << m_audioOutput->bytesFree() << ", " << "elapsedUSecs = " << m_audioOutput->elapsedUSecs() << ", " << "processedUSecs = " << m_audioOutput->processedUSecs(); } -void AudioTest::writeMore() +void AudioTest::pullTimerExpired() { if (m_audioOutput && m_audioOutput->state() != QAudio::StoppedState) { int chunks = m_audioOutput->bytesFree()/m_audioOutput->periodSize(); @@ -270,18 +270,16 @@ void AudioTest::writeMore() } } -void AudioTest::toggle() +void AudioTest::toggleMode() { - // Change between pull and push modes - - m_timer->stop(); + m_pullTimer->stop(); m_audioOutput->stop(); if (m_pullMode) { m_modeButton->setText(PullModeLabel); m_output = m_audioOutput->start(); m_pullMode = false; - m_timer->start(20); + m_pullTimer->start(20); } else { m_modeButton->setText(PushModeLabel); m_pullMode = true; @@ -291,9 +289,8 @@ void AudioTest::toggle() m_suspendResumeButton->setText(SuspendLabel); } -void AudioTest::togglePlay() +void AudioTest::toggleSuspendResume() { - // toggle suspend/resume if (m_audioOutput->state() == QAudio::SuspendedState) { qWarning() << "status: Suspended, resume()"; m_audioOutput->resume(); @@ -311,7 +308,7 @@ void AudioTest::togglePlay() } } -void AudioTest::state(QAudio::State state) +void AudioTest::stateChanged(QAudio::State state) { qWarning() << "state = " << state; } diff --git a/examples/multimedia/audiooutput/audiooutput.h b/examples/multimedia/audiooutput/audiooutput.h index 1880d8d..889482b 100644 --- a/examples/multimedia/audiooutput/audiooutput.h +++ b/examples/multimedia/audiooutput/audiooutput.h @@ -86,7 +86,7 @@ private: void createAudioOutput(); private: - QTimer* m_timer; + QTimer* m_pullTimer; // Owned by layout QPushButton* m_modeButton; @@ -108,11 +108,11 @@ private: static const QString ResumeLabel; private slots: - void status(); - void writeMore(); - void toggle(); - void togglePlay(); - void state(QAudio::State state); + void notified(); + void pullTimerExpired(); + void toggleMode(); + void toggleSuspendResume(); + void stateChanged(QAudio::State state); void deviceChanged(int index); }; -- cgit v0.12 From 34236413600c8142d626c460fd4af97072054fa4 Mon Sep 17 00:00:00 2001 From: Gareth Stockwell Date: Tue, 16 Feb 2010 15:37:50 +0000 Subject: Update suspend/resume button label in audio input example When the mode is toggled, playback is always started, even if the audio input device was previously suspended. The label on the suspend/resume button must therefore be updated. Reviewed-by: trustme --- examples/multimedia/audioinput/audioinput.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/examples/multimedia/audioinput/audioinput.cpp b/examples/multimedia/audioinput/audioinput.cpp index fbf4dc4..18b5ba1 100644 --- a/examples/multimedia/audioinput/audioinput.cpp +++ b/examples/multimedia/audioinput/audioinput.cpp @@ -263,6 +263,8 @@ void InputTest::toggleMode() pullMode = true; audioInput->start(audioinfo); } + + button2->setText("Click To Suspend"); } void InputTest::toggleSuspend() -- cgit v0.12 From d17060663236c0cf4d3eec79f8f76e30edfca636 Mon Sep 17 00:00:00 2001 From: Gareth Stockwell Date: Tue, 16 Feb 2010 15:42:55 +0000 Subject: Removed unused variable from audio input example Reviewed-by: trustme --- examples/multimedia/audioinput/audioinput.cpp | 6 ++---- examples/multimedia/audioinput/audioinput.h | 4 +--- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/examples/multimedia/audioinput/audioinput.cpp b/examples/multimedia/audioinput/audioinput.cpp index 18b5ba1..d00dd02 100644 --- a/examples/multimedia/audioinput/audioinput.cpp +++ b/examples/multimedia/audioinput/audioinput.cpp @@ -52,11 +52,9 @@ #define BUFFER_SIZE 4096 -AudioInfo::AudioInfo(QObject *parent, QAudioInput *device) +AudioInfo::AudioInfo(QObject *parent) :QIODevice(parent) { - input = device; - m_maxValue = 0; } @@ -222,7 +220,7 @@ InputTest::InputTest() audioInput = new QAudioInput(format,this); connect(audioInput, SIGNAL(notify()), SLOT(status())); connect(audioInput, SIGNAL(stateChanged(QAudio::State)), SLOT(state(QAudio::State))); - audioinfo = new AudioInfo(this,audioInput); + audioinfo = new AudioInfo(this); connect(audioinfo, SIGNAL(update()), SLOT(refreshDisplay())); audioinfo->start(); audioInput->start(audioinfo); diff --git a/examples/multimedia/audioinput/audioinput.h b/examples/multimedia/audioinput/audioinput.h index abe2be1..6f6c8eb 100644 --- a/examples/multimedia/audioinput/audioinput.h +++ b/examples/multimedia/audioinput/audioinput.h @@ -52,7 +52,7 @@ class AudioInfo : public QIODevice { Q_OBJECT public: - AudioInfo(QObject *parent, QAudioInput *device); + AudioInfo(QObject *parent); ~AudioInfo(); void start(); @@ -63,8 +63,6 @@ public: qint64 readData(char *data, qint64 maxlen); qint64 writeData(const char *data, qint64 len); - QAudioInput *input; - private: int m_maxValue; -- cgit v0.12 From 479e26ab077a9d43e37b0706db4f5cb61964b327 Mon Sep 17 00:00:00 2001 From: Gareth Stockwell Date: Tue, 16 Feb 2010 16:43:20 +0000 Subject: Made level calculation in audio input example work for all formats The previous code only worked correctly for little-endian PCM16 formats. If the audio input device does not support such a format, the example previously would not run. Reviewed-by: trustme --- examples/multimedia/audioinput/audioinput.cpp | 110 +++++++++++++++++--------- examples/multimedia/audioinput/audioinput.h | 12 +-- 2 files changed, 80 insertions(+), 42 deletions(-) diff --git a/examples/multimedia/audioinput/audioinput.cpp b/examples/multimedia/audioinput/audioinput.cpp index d00dd02..36fc5ac 100644 --- a/examples/multimedia/audioinput/audioinput.cpp +++ b/examples/multimedia/audioinput/audioinput.cpp @@ -48,14 +48,42 @@ #include #include + +#include + #include "audioinput.h" #define BUFFER_SIZE 4096 -AudioInfo::AudioInfo(QObject *parent) - :QIODevice(parent) +AudioInfo::AudioInfo(const QAudioFormat &format, QObject *parent) + : QIODevice(parent) + , m_format(format) + , m_maxAmplitude(0) + , m_level(0.0) + { - m_maxValue = 0; + switch (m_format.sampleSize()) { + case 8: + switch (m_format.sampleType()) { + case QAudioFormat::UnSignedInt: + m_maxAmplitude = 255; + break; + case QAudioFormat::SignedInt: + m_maxAmplitude = 127; + break; + } + break; + case 16: + switch (m_format.sampleType()) { + case QAudioFormat::UnSignedInt: + m_maxAmplitude = 65535; + break; + case QAudioFormat::SignedInt: + m_maxAmplitude = 32767; + break; + } + break; + } } AudioInfo::~AudioInfo() @@ -82,41 +110,49 @@ qint64 AudioInfo::readData(char *data, qint64 maxlen) qint64 AudioInfo::writeData(const char *data, qint64 len) { - int samples = len/2; // 2 bytes per sample - int maxAmp = 32768; // max for S16 samples - bool clipping = false; - - m_maxValue = 0; - - qint16 *s = (qint16*)data; - - // sample format is S16LE, only! - - for (int i = 0; i < samples; ++i) { - qint16 sample = *s; - s++; - if (abs(sample) > m_maxValue) m_maxValue = abs(sample); + if (m_maxAmplitude) { + Q_ASSERT(m_format.sampleSize() % 8 == 0); + const int channelBytes = m_format.sampleSize() / 8; + const int sampleBytes = m_format.channels() * channelBytes; + Q_ASSERT(len % sampleBytes == 0); + const int numSamples = len / sampleBytes; + + quint16 maxValue = 0; + const unsigned char *ptr = reinterpret_cast(data); + + for (int i = 0; i < numSamples; ++i) { + for(int j = 0; j < m_format.channels(); ++j) { + quint16 value = 0; + + if (m_format.sampleSize() == 8 && m_format.sampleType() == QAudioFormat::UnSignedInt) { + value = *reinterpret_cast(ptr); + } else if (m_format.sampleSize() == 8 && m_format.sampleType() == QAudioFormat::SignedInt) { + value = qAbs(*reinterpret_cast(ptr)); + } else if (m_format.sampleSize() == 16 && m_format.sampleType() == QAudioFormat::UnSignedInt) { + if (m_format.byteOrder() == QAudioFormat::LittleEndian) + value = qFromLittleEndian(ptr); + else + value = qFromBigEndian(ptr); + } else if (m_format.sampleSize() == 16 && m_format.sampleType() == QAudioFormat::SignedInt) { + if (m_format.byteOrder() == QAudioFormat::LittleEndian) + value = qAbs(qFromLittleEndian(ptr)); + else + value = qAbs(qFromBigEndian(ptr)); + } + + maxValue = qMax(value, maxValue); + ptr += channelBytes; + } + } + + maxValue = qMin(maxValue, m_maxAmplitude); + m_level = qreal(maxValue) / m_maxAmplitude; } - // check for clipping - if (m_maxValue >= (maxAmp - 1)) - clipping = true; - - float value = ((float)m_maxValue/(float)maxAmp); - if (clipping) - m_maxValue = 100; - else - m_maxValue = (int)(value*100); emit update(); - return len; } -int AudioInfo::LinearMax() -{ - return m_maxValue; -} - RenderArea::RenderArea(QWidget *parent) : QWidget(parent) { @@ -137,12 +173,12 @@ void RenderArea::paintEvent(QPaintEvent * /* event */) painter.viewport().top()+10, painter.viewport().right()-20, painter.viewport().bottom()-20)); - if (level == 0) + if (level == 0.0) return; painter.setPen(Qt::red); - int pos = ((painter.viewport().right()-20)-(painter.viewport().left()+11))*level/100; + int pos = ((painter.viewport().right()-20)-(painter.viewport().left()+11))*level; for (int i = 0; i < 10; ++i) { int x1 = painter.viewport().left()+11; int y1 = painter.viewport().top()+10+i; @@ -155,7 +191,7 @@ void RenderArea::paintEvent(QPaintEvent * /* event */) } } -void RenderArea::setLevel(int value) +void RenderArea::setLevel(qreal value) { level = value; repaint(); @@ -220,7 +256,7 @@ InputTest::InputTest() audioInput = new QAudioInput(format,this); connect(audioInput, SIGNAL(notify()), SLOT(status())); connect(audioInput, SIGNAL(stateChanged(QAudio::State)), SLOT(state(QAudio::State))); - audioinfo = new AudioInfo(this); + audioinfo = new AudioInfo(format, this); connect(audioinfo, SIGNAL(update()), SLOT(refreshDisplay())); audioinfo->start(); audioInput->start(audioinfo); @@ -292,7 +328,7 @@ void InputTest::state(QAudio::State state) void InputTest::refreshDisplay() { - canvas->setLevel(audioinfo->LinearMax()); + canvas->setLevel(audioinfo->level()); canvas->repaint(); } diff --git a/examples/multimedia/audioinput/audioinput.h b/examples/multimedia/audioinput/audioinput.h index 6f6c8eb..33b9ac6 100644 --- a/examples/multimedia/audioinput/audioinput.h +++ b/examples/multimedia/audioinput/audioinput.h @@ -52,19 +52,21 @@ class AudioInfo : public QIODevice { Q_OBJECT public: - AudioInfo(QObject *parent); + AudioInfo(const QAudioFormat &format, QObject *parent); ~AudioInfo(); void start(); void stop(); - int LinearMax(); + qreal level() const { return m_level; } qint64 readData(char *data, qint64 maxlen); qint64 writeData(const char *data, qint64 len); private: - int m_maxValue; + const QAudioFormat m_format; + quint16 m_maxAmplitude; + qreal m_level; // 0.0 <= m_level <= 1.0 signals: void update(); @@ -78,13 +80,13 @@ class RenderArea : public QWidget public: RenderArea(QWidget *parent = 0); - void setLevel(int value); + void setLevel(qreal value); protected: void paintEvent(QPaintEvent *event); private: - int level; + qreal level; QPixmap pixmap; }; -- cgit v0.12 From fb829969ce3f406fcb927d8d31a84c5fb8f56d59 Mon Sep 17 00:00:00 2001 From: Gareth Stockwell Date: Tue, 16 Feb 2010 16:47:42 +0000 Subject: Changed variable names in audio input example to match Qt code style Also changed some names to better convey their meanings, e.g. button -> m_modeButton button2 -> m_suspendResumeButton Reviewed-by: trustme --- examples/multimedia/audioinput/audioinput.cpp | 156 +++++++++++++------------- examples/multimedia/audioinput/audioinput.h | 30 ++--- 2 files changed, 93 insertions(+), 93 deletions(-) diff --git a/examples/multimedia/audioinput/audioinput.cpp b/examples/multimedia/audioinput/audioinput.cpp index 36fc5ac..e18e3a7 100644 --- a/examples/multimedia/audioinput/audioinput.cpp +++ b/examples/multimedia/audioinput/audioinput.cpp @@ -159,7 +159,7 @@ RenderArea::RenderArea(QWidget *parent) setBackgroundRole(QPalette::Base); setAutoFillBackground(true); - level = 0; + m_level = 0; setMinimumHeight(30); setMinimumWidth(200); } @@ -173,12 +173,12 @@ void RenderArea::paintEvent(QPaintEvent * /* event */) painter.viewport().top()+10, painter.viewport().right()-20, painter.viewport().bottom()-20)); - if (level == 0.0) + if (m_level == 0.0) return; painter.setPen(Qt::red); - int pos = ((painter.viewport().right()-20)-(painter.viewport().left()+11))*level; + int pos = ((painter.viewport().right()-20)-(painter.viewport().left()+11))*m_level; for (int i = 0; i < 10; ++i) { int x1 = painter.viewport().left()+11; int y1 = painter.viewport().top()+10+i; @@ -193,7 +193,7 @@ void RenderArea::paintEvent(QPaintEvent * /* event */) void RenderArea::setLevel(qreal value) { - level = value; + m_level = value; repaint(); } @@ -203,120 +203,120 @@ InputTest::InputTest() QWidget *window = new QWidget; QVBoxLayout* layout = new QVBoxLayout; - canvas = new RenderArea; - layout->addWidget(canvas); + m_canvas = new RenderArea; + layout->addWidget(m_canvas); - deviceBox = new QComboBox(this); + m_deviceBox = new QComboBox(this); QList devices = QAudioDeviceInfo::availableDevices(QAudio::AudioInput); for(int i = 0; i < devices.size(); ++i) - deviceBox->addItem(devices.at(i).deviceName(), qVariantFromValue(devices.at(i))); + m_deviceBox->addItem(devices.at(i).deviceName(), qVariantFromValue(devices.at(i))); - connect(deviceBox, SIGNAL(activated(int)), SLOT(deviceChanged(int))); - layout->addWidget(deviceBox); + connect(m_deviceBox, SIGNAL(activated(int)), SLOT(deviceChanged(int))); + layout->addWidget(m_deviceBox); - button = new QPushButton(this); - button->setText(tr("Click for Push Mode")); - connect(button, SIGNAL(clicked()), SLOT(toggleMode())); - layout->addWidget(button); + m_modeButton = new QPushButton(this); + m_modeButton->setText(tr("Click for Push Mode")); + connect(m_modeButton, SIGNAL(clicked()), SLOT(toggleMode())); + layout->addWidget(m_modeButton); - button2 = new QPushButton(this); - button2->setText(tr("Click To Suspend")); - connect(button2, SIGNAL(clicked()), SLOT(toggleSuspend())); - layout->addWidget(button2); + m_suspendResumeButton = new QPushButton(this); + m_suspendResumeButton->setText(tr("Click To Suspend")); + connect(m_suspendResumeButton, SIGNAL(clicked()), SLOT(toggleSuspend())); + layout->addWidget(m_suspendResumeButton); window->setLayout(layout); setCentralWidget(window); window->show(); - buffer = new char[BUFFER_SIZE]; + m_buffer = new char[BUFFER_SIZE]; - pullMode = true; + m_pullMode = true; - format.setFrequency(8000); - format.setChannels(1); - format.setSampleSize(16); - format.setSampleType(QAudioFormat::SignedInt); - format.setByteOrder(QAudioFormat::LittleEndian); - format.setCodec("audio/pcm"); + m_format.setFrequency(8000); + m_format.setChannels(1); + m_format.setSampleSize(16); + m_format.setSampleType(QAudioFormat::SignedInt); + m_format.setByteOrder(QAudioFormat::LittleEndian); + m_format.setCodec("audio/pcm"); QAudioDeviceInfo info(QAudioDeviceInfo::defaultInputDevice()); - if (!info.isFormatSupported(format)) { + if (!info.isFormatSupported(m_format)) { qWarning()<<"default format not supported try to use nearest"; - format = info.nearestFormat(format); + m_format = info.nearestFormat(m_format); } - if(format.sampleSize() != 16) { + if(m_format.sampleSize() != 16) { qWarning()<<"audio device doesn't support 16 bit samples, example cannot run"; - audioInput = 0; - button->setDisabled(true); - button2->setDisabled(true); + m_audioInput = 0; + m_modeButton->setDisabled(true); + m_suspendResumeButton->setDisabled(true); return; } - audioInput = new QAudioInput(format,this); - connect(audioInput, SIGNAL(notify()), SLOT(status())); - connect(audioInput, SIGNAL(stateChanged(QAudio::State)), SLOT(state(QAudio::State))); - audioinfo = new AudioInfo(format, this); - connect(audioinfo, SIGNAL(update()), SLOT(refreshDisplay())); - audioinfo->start(); - audioInput->start(audioinfo); + m_audioInput = new QAudioInput(m_format,this); + connect(m_audioInput, SIGNAL(notify()), SLOT(status())); + connect(m_audioInput, SIGNAL(stateChanged(QAudio::State)), SLOT(state(QAudio::State))); + m_audioInfo = new AudioInfo(m_format, this); + connect(m_audioInfo, SIGNAL(update()), SLOT(refreshDisplay())); + m_audioInfo->start(); + m_audioInput->start(m_audioInfo); } InputTest::~InputTest() {} void InputTest::status() { - qWarning()<<"bytesReady = "<bytesReady()<<" bytes, elapsedUSecs = "<elapsedUSecs()<<", processedUSecs = "<processedUSecs(); + qWarning()<<"bytesReady = "<bytesReady()<<" bytes, elapsedUSecs = "<elapsedUSecs()<<", processedUSecs = "<processedUSecs(); } void InputTest::readMore() { - if(!audioInput) + if(!m_audioInput) return; - qint64 len = audioInput->bytesReady(); + qint64 len = m_audioInput->bytesReady(); if(len > 4096) len = 4096; - qint64 l = input->read(buffer,len); + qint64 l = m_input->read(m_buffer,len); if(l > 0) { - audioinfo->write(buffer,l); + m_audioInfo->write(m_buffer,l); } } void InputTest::toggleMode() { // Change bewteen pull and push modes - audioInput->stop(); + m_audioInput->stop(); - if (pullMode) { - button->setText(tr("Click for Pull Mode")); - input = audioInput->start(); - connect(input, SIGNAL(readyRead()), SLOT(readMore())); - pullMode = false; + if (m_pullMode) { + m_modeButton->setText(tr("Click for Pull Mode")); + m_input = m_audioInput->start(); + connect(m_input, SIGNAL(readyRead()), SLOT(readMore())); + m_pullMode = false; } else { - button->setText(tr("Click for Push Mode")); - pullMode = true; - audioInput->start(audioinfo); + m_modeButton->setText(tr("Click for Push Mode")); + m_pullMode = true; + m_audioInput->start(m_audioInfo); } - button2->setText("Click To Suspend"); + m_suspendResumeButton->setText("Click To Suspend"); } void InputTest::toggleSuspend() { // toggle suspend/resume - if(audioInput->state() == QAudio::SuspendedState) { + if(m_audioInput->state() == QAudio::SuspendedState) { qWarning() << "status: Suspended, resume()"; - audioInput->resume(); - button2->setText("Click To Suspend"); - } else if (audioInput->state() == QAudio::ActiveState) { + m_audioInput->resume(); + m_suspendResumeButton->setText("Click To Suspend"); + } else if (m_audioInput->state() == QAudio::ActiveState) { qWarning() << "status: Active, suspend()"; - audioInput->suspend(); - button2->setText("Click To Resume"); - } else if (audioInput->state() == QAudio::StoppedState) { + m_audioInput->suspend(); + m_suspendResumeButton->setText("Click To Resume"); + } else if (m_audioInput->state() == QAudio::StoppedState) { qWarning() << "status: Stopped, resume()"; - audioInput->resume(); - button2->setText("Click To Suspend"); - } else if (audioInput->state() == QAudio::IdleState) { + m_audioInput->resume(); + m_suspendResumeButton->setText("Click To Suspend"); + } else if (m_audioInput->state() == QAudio::IdleState) { qWarning() << "status: IdleState"; } } @@ -328,21 +328,21 @@ void InputTest::state(QAudio::State state) void InputTest::refreshDisplay() { - canvas->setLevel(audioinfo->level()); - canvas->repaint(); + m_canvas->setLevel(m_audioInfo->level()); + m_canvas->repaint(); } -void InputTest::deviceChanged(int idx) +void InputTest::deviceChanged(int index) { - audioinfo->stop(); - audioInput->stop(); - audioInput->disconnect(this); - delete audioInput; - - device = deviceBox->itemData(idx).value(); - audioInput = new QAudioInput(device, format, this); - connect(audioInput, SIGNAL(notify()), SLOT(status())); - connect(audioInput, SIGNAL(stateChanged(QAudio::State)), SLOT(state(QAudio::State))); - audioinfo->start(); - audioInput->start(audioinfo); + m_audioInfo->stop(); + m_audioInput->stop(); + m_audioInput->disconnect(this); + delete m_audioInput; + + m_device = m_deviceBox->itemData(idx).value(); + m_audioInput = new QAudioInput(m_device, m_format, this); + connect(m_audioInput, SIGNAL(notify()), SLOT(status())); + connect(m_audioInput, SIGNAL(stateChanged(QAudio::State)), SLOT(state(QAudio::State))); + m_audioInfo->start(); + m_audioInput->start(m_audioInfo); } diff --git a/examples/multimedia/audioinput/audioinput.h b/examples/multimedia/audioinput/audioinput.h index 33b9ac6..b189e84 100644 --- a/examples/multimedia/audioinput/audioinput.h +++ b/examples/multimedia/audioinput/audioinput.h @@ -86,8 +86,8 @@ protected: void paintEvent(QPaintEvent *event); private: - qreal level; - QPixmap pixmap; + qreal m_level; + QPixmap m_pixmap; }; class InputTest : public QMainWindow @@ -103,23 +103,23 @@ private slots: void readMore(); void toggleMode(); void toggleSuspend(); - void state(QAudio::State s); - void deviceChanged(int idx); + void state(QAudio::State state); + void deviceChanged(int index); private: - AudioInfo *audioinfo; - QAudioDeviceInfo device; - QAudioFormat format; - QAudioInput *audioInput; - QIODevice *input; - RenderArea *canvas; + AudioInfo *m_audioInfo; + QAudioDeviceInfo m_device; + QAudioFormat m_format; + QAudioInput *m_audioInput; + QIODevice *m_input; + RenderArea *m_canvas; - bool pullMode; + bool m_pullMode; - QPushButton *button; - QPushButton *button2; - QComboBox *deviceBox; + QPushButton *m_modeButton; + QPushButton *m_suspendResumeButton; + QComboBox *m_deviceBox; - char *buffer; + char *m_buffer; }; -- cgit v0.12 From 77818e65f47fe211f328649085a297c9d2baeb45 Mon Sep 17 00:00:00 2001 From: Gareth Stockwell Date: Tue, 16 Feb 2010 17:29:35 +0000 Subject: Cleaned up memory management in audio input example Reviewed-by: trustme --- examples/multimedia/audioinput/audioinput.cpp | 69 ++++++++++++++++----------- examples/multimedia/audioinput/audioinput.h | 21 ++++---- 2 files changed, 54 insertions(+), 36 deletions(-) diff --git a/examples/multimedia/audioinput/audioinput.cpp b/examples/multimedia/audioinput/audioinput.cpp index e18e3a7..48763c9 100644 --- a/examples/multimedia/audioinput/audioinput.cpp +++ b/examples/multimedia/audioinput/audioinput.cpp @@ -53,7 +53,7 @@ #include "audioinput.h" -#define BUFFER_SIZE 4096 +const int BufferSize = 4096; AudioInfo::AudioInfo(const QAudioFormat &format, QObject *parent) : QIODevice(parent) @@ -199,11 +199,28 @@ void RenderArea::setLevel(qreal value) InputTest::InputTest() + : m_canvas(0) + , m_modeButton(0) + , m_suspendResumeButton(0) + , m_deviceBox(0) + , m_audioInfo(0) + , m_audioInput(0) + , m_input(0) + , m_pullMode(false) + , m_buffer(BufferSize, 0) { - QWidget *window = new QWidget; - QVBoxLayout* layout = new QVBoxLayout; + initializeWindow(); + initializeAudio(); +} + +InputTest::~InputTest() {} - m_canvas = new RenderArea; +void InputTest::initializeWindow() +{ + QScopedPointer window(new QWidget); + QScopedPointer layout(new QVBoxLayout); + + m_canvas = new RenderArea(this); layout->addWidget(m_canvas); m_deviceBox = new QComboBox(this); @@ -224,12 +241,16 @@ InputTest::InputTest() connect(m_suspendResumeButton, SIGNAL(clicked()), SLOT(toggleSuspend())); layout->addWidget(m_suspendResumeButton); - window->setLayout(layout); - setCentralWidget(window); - window->show(); + window->setLayout(layout.data()); + layout.take(); // ownership transferred - m_buffer = new char[BUFFER_SIZE]; + setCentralWidget(window.data()); + QWidget *const windowPtr = window.take(); // ownership transferred + windowPtr->show(); +} +void InputTest::initializeAudio() +{ m_pullMode = true; m_format.setFrequency(8000); @@ -245,25 +266,21 @@ InputTest::InputTest() m_format = info.nearestFormat(m_format); } - if(m_format.sampleSize() != 16) { - qWarning()<<"audio device doesn't support 16 bit samples, example cannot run"; - m_audioInput = 0; - m_modeButton->setDisabled(true); - m_suspendResumeButton->setDisabled(true); - return; - } + m_audioInfo = new AudioInfo(m_format, this); + connect(m_audioInfo, SIGNAL(update()), SLOT(refreshDisplay())); + + createAudioInput(); +} - m_audioInput = new QAudioInput(m_format,this); +void InputTest::createAudioInput() +{ + m_audioInput = new QAudioInput(m_device, m_format, this); connect(m_audioInput, SIGNAL(notify()), SLOT(status())); connect(m_audioInput, SIGNAL(stateChanged(QAudio::State)), SLOT(state(QAudio::State))); - m_audioInfo = new AudioInfo(m_format, this); - connect(m_audioInfo, SIGNAL(update()), SLOT(refreshDisplay())); m_audioInfo->start(); m_audioInput->start(m_audioInfo); } -InputTest::~InputTest() {} - void InputTest::status() { qWarning()<<"bytesReady = "<bytesReady()<<" bytes, elapsedUSecs = "<elapsedUSecs()<<", processedUSecs = "<processedUSecs(); @@ -276,9 +293,9 @@ void InputTest::readMore() qint64 len = m_audioInput->bytesReady(); if(len > 4096) len = 4096; - qint64 l = m_input->read(m_buffer,len); + qint64 l = m_input->read(m_buffer.data(), len); if(l > 0) { - m_audioInfo->write(m_buffer,l); + m_audioInfo->write(m_buffer.constData(), l); } } @@ -339,10 +356,6 @@ void InputTest::deviceChanged(int index) m_audioInput->disconnect(this); delete m_audioInput; - m_device = m_deviceBox->itemData(idx).value(); - m_audioInput = new QAudioInput(m_device, m_format, this); - connect(m_audioInput, SIGNAL(notify()), SLOT(status())); - connect(m_audioInput, SIGNAL(stateChanged(QAudio::State)), SLOT(state(QAudio::State))); - m_audioInfo->start(); - m_audioInput->start(m_audioInfo); + m_device = m_deviceBox->itemData(index).value(); + createAudioInput(); } diff --git a/examples/multimedia/audioinput/audioinput.h b/examples/multimedia/audioinput/audioinput.h index b189e84..a32a374 100644 --- a/examples/multimedia/audioinput/audioinput.h +++ b/examples/multimedia/audioinput/audioinput.h @@ -45,6 +45,7 @@ #include #include #include +#include #include @@ -97,6 +98,11 @@ public: InputTest(); ~InputTest(); +private: + void initializeWindow(); + void initializeAudio(); + void createAudioInput(); + private slots: void refreshDisplay(); void status(); @@ -107,19 +113,18 @@ private slots: void deviceChanged(int index); private: + // Owned by layout + RenderArea *m_canvas; + QPushButton *m_modeButton; + QPushButton *m_suspendResumeButton; + QComboBox *m_deviceBox; + AudioInfo *m_audioInfo; QAudioDeviceInfo m_device; QAudioFormat m_format; QAudioInput *m_audioInput; QIODevice *m_input; - RenderArea *m_canvas; - bool m_pullMode; - - QPushButton *m_modeButton; - QPushButton *m_suspendResumeButton; - QComboBox *m_deviceBox; - - char *m_buffer; + QByteArray m_buffer; }; -- cgit v0.12 From 81a96e9da45cbdf0bab221e3dd0b617ec7dcb890 Mon Sep 17 00:00:00 2001 From: Gareth Stockwell Date: Tue, 16 Feb 2010 17:35:38 +0000 Subject: Removed redundant strings from audio input example Reviewed-by: trustme --- examples/multimedia/audioinput/audioinput.cpp | 21 +++++++++++++-------- examples/multimedia/audioinput/audioinput.h | 5 +++++ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/examples/multimedia/audioinput/audioinput.cpp b/examples/multimedia/audioinput/audioinput.cpp index 48763c9..10941ca 100644 --- a/examples/multimedia/audioinput/audioinput.cpp +++ b/examples/multimedia/audioinput/audioinput.cpp @@ -53,6 +53,11 @@ #include "audioinput.h" +const QString InputTest::PushModeLabel(tr("Enable push mode")); +const QString InputTest::PullModeLabel(tr("Enable pull mode")); +const QString InputTest::SuspendLabel(tr("Suspend recording")); +const QString InputTest::ResumeLabel(tr("Resume recording")); + const int BufferSize = 4096; AudioInfo::AudioInfo(const QAudioFormat &format, QObject *parent) @@ -232,12 +237,12 @@ void InputTest::initializeWindow() layout->addWidget(m_deviceBox); m_modeButton = new QPushButton(this); - m_modeButton->setText(tr("Click for Push Mode")); + m_modeButton->setText(PushModeLabel); connect(m_modeButton, SIGNAL(clicked()), SLOT(toggleMode())); layout->addWidget(m_modeButton); m_suspendResumeButton = new QPushButton(this); - m_suspendResumeButton->setText(tr("Click To Suspend")); + m_suspendResumeButton->setText(SuspendLabel); connect(m_suspendResumeButton, SIGNAL(clicked()), SLOT(toggleSuspend())); layout->addWidget(m_suspendResumeButton); @@ -305,17 +310,17 @@ void InputTest::toggleMode() m_audioInput->stop(); if (m_pullMode) { - m_modeButton->setText(tr("Click for Pull Mode")); + m_modeButton->setText(PullModeLabel); m_input = m_audioInput->start(); connect(m_input, SIGNAL(readyRead()), SLOT(readMore())); m_pullMode = false; } else { - m_modeButton->setText(tr("Click for Push Mode")); + m_modeButton->setText(PushModeLabel); m_pullMode = true; m_audioInput->start(m_audioInfo); } - m_suspendResumeButton->setText("Click To Suspend"); + m_suspendResumeButton->setText(SuspendLabel); } void InputTest::toggleSuspend() @@ -324,15 +329,15 @@ void InputTest::toggleSuspend() if(m_audioInput->state() == QAudio::SuspendedState) { qWarning() << "status: Suspended, resume()"; m_audioInput->resume(); - m_suspendResumeButton->setText("Click To Suspend"); + m_suspendResumeButton->setText(SuspendLabel); } else if (m_audioInput->state() == QAudio::ActiveState) { qWarning() << "status: Active, suspend()"; m_audioInput->suspend(); - m_suspendResumeButton->setText("Click To Resume"); + m_suspendResumeButton->setText(ResumeLabel); } else if (m_audioInput->state() == QAudio::StoppedState) { qWarning() << "status: Stopped, resume()"; m_audioInput->resume(); - m_suspendResumeButton->setText("Click To Suspend"); + m_suspendResumeButton->setText(SuspendLabel); } else if (m_audioInput->state() == QAudio::IdleState) { qWarning() << "status: IdleState"; } diff --git a/examples/multimedia/audioinput/audioinput.h b/examples/multimedia/audioinput/audioinput.h index a32a374..f1ab254 100644 --- a/examples/multimedia/audioinput/audioinput.h +++ b/examples/multimedia/audioinput/audioinput.h @@ -126,5 +126,10 @@ private: QIODevice *m_input; bool m_pullMode; QByteArray m_buffer; + + static const QString PushModeLabel; + static const QString PullModeLabel; + static const QString SuspendLabel; + static const QString ResumeLabel; }; -- cgit v0.12 From 96a6c921d940c802f7a282067f5b1790af725e6f Mon Sep 17 00:00:00 2001 From: Gareth Stockwell Date: Tue, 16 Feb 2010 17:38:35 +0000 Subject: Tidied up debug output in audio input example Reviewed-by: trustme --- examples/multimedia/audioinput/audioinput.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/examples/multimedia/audioinput/audioinput.cpp b/examples/multimedia/audioinput/audioinput.cpp index 10941ca..2258854 100644 --- a/examples/multimedia/audioinput/audioinput.cpp +++ b/examples/multimedia/audioinput/audioinput.cpp @@ -267,7 +267,7 @@ void InputTest::initializeAudio() QAudioDeviceInfo info(QAudioDeviceInfo::defaultInputDevice()); if (!info.isFormatSupported(m_format)) { - qWarning()<<"default format not supported try to use nearest"; + qWarning() << "Default format not supported - trying to use nearest"; m_format = info.nearestFormat(m_format); } @@ -288,7 +288,9 @@ void InputTest::createAudioInput() void InputTest::status() { - qWarning()<<"bytesReady = "<bytesReady()<<" bytes, elapsedUSecs = "<elapsedUSecs()<<", processedUSecs = "<processedUSecs(); + qWarning() << "bytesReady = " << m_audioInput->bytesReady() + << ", " << "elapsedUSecs = " <elapsedUSecs() + << ", " << "processedUSecs = "<processedUSecs(); } void InputTest::readMore() @@ -345,7 +347,7 @@ void InputTest::toggleSuspend() void InputTest::state(QAudio::State state) { - qWarning() << " state=" << state; + qWarning() << "state = " << state; } void InputTest::refreshDisplay() -- cgit v0.12 From c22299dd388af117e436c17258d7afc1623af9b6 Mon Sep 17 00:00:00 2001 From: Gareth Stockwell Date: Tue, 16 Feb 2010 17:41:25 +0000 Subject: Changed function names in audio input example to clarify meaning Reviewed-by: trustme --- examples/multimedia/audioinput/audioinput.cpp | 9 +++++---- examples/multimedia/audioinput/audioinput.h | 4 ++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/examples/multimedia/audioinput/audioinput.cpp b/examples/multimedia/audioinput/audioinput.cpp index 2258854..8a97640 100644 --- a/examples/multimedia/audioinput/audioinput.cpp +++ b/examples/multimedia/audioinput/audioinput.cpp @@ -279,14 +279,15 @@ void InputTest::initializeAudio() void InputTest::createAudioInput() { + m_audioInput = new QAudioInput(m_device, m_format, this); - connect(m_audioInput, SIGNAL(notify()), SLOT(status())); - connect(m_audioInput, SIGNAL(stateChanged(QAudio::State)), SLOT(state(QAudio::State))); + connect(m_audioInput, SIGNAL(notify()), SLOT(notified())); + connect(m_audioInput, SIGNAL(stateChanged(QAudio::State)), SLOT(stateChanged(QAudio::State))); m_audioInfo->start(); m_audioInput->start(m_audioInfo); } -void InputTest::status() +void InputTest::notified() { qWarning() << "bytesReady = " << m_audioInput->bytesReady() << ", " << "elapsedUSecs = " <elapsedUSecs() @@ -345,7 +346,7 @@ void InputTest::toggleSuspend() } } -void InputTest::state(QAudio::State state) +void InputTest::stateChanged(QAudio::State state) { qWarning() << "state = " << state; } diff --git a/examples/multimedia/audioinput/audioinput.h b/examples/multimedia/audioinput/audioinput.h index f1ab254..f87c682 100644 --- a/examples/multimedia/audioinput/audioinput.h +++ b/examples/multimedia/audioinput/audioinput.h @@ -105,11 +105,11 @@ private: private slots: void refreshDisplay(); - void status(); + void notified(); void readMore(); void toggleMode(); void toggleSuspend(); - void state(QAudio::State state); + void stateChanged(QAudio::State state); void deviceChanged(int index); private: -- cgit v0.12 From 1e7b737596db7be0a221aa44d1a329d3fdb5d6e3 Mon Sep 17 00:00:00 2001 From: Jason McDonald Date: Wed, 17 Feb 2010 06:08:20 +1000 Subject: Check in sample license headers Reviewed-by: Trust Me --- header.BSD | 40 ++++++++++++++++++++++++++++++++++++++++ header.LGPL | 41 +++++++++++++++++++++++++++++++++++++++++ header.LGPL-ONLY | 22 ++++++++++++++++++++++ 3 files changed, 103 insertions(+) create mode 100644 header.BSD create mode 100644 header.LGPL create mode 100644 header.LGPL-ONLY diff --git a/header.BSD b/header.BSD new file mode 100644 index 0000000..3c0d604 --- /dev/null +++ b/header.BSD @@ -0,0 +1,40 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the FOO module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** $QT_END_LICENSE$ +** +****************************************************************************/ + diff --git a/header.LGPL b/header.LGPL new file mode 100644 index 0000000..4fbd874 --- /dev/null +++ b/header.LGPL @@ -0,0 +1,41 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the FOO module 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$ +** +****************************************************************************/ + diff --git a/header.LGPL-ONLY b/header.LGPL-ONLY new file mode 100644 index 0000000..59b4c04 --- /dev/null +++ b/header.LGPL-ONLY @@ -0,0 +1,22 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the FOO module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL-ONLY$ +** GNU Lesser General Public License Usage +** 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ -- cgit v0.12 From b7406af04ec83b3e8d712b42a87f6c29121b998d Mon Sep 17 00:00:00 2001 From: Rohan McGovern Date: Tue, 16 Feb 2010 09:47:16 +1000 Subject: Fixed compile of these tests when Qt is configured with -qtnamespace --- tests/auto/modeltest/dynamictreemodel.h | 2 -- tests/auto/qpixmapcache/tst_qpixmapcache.cpp | 2 ++ tests/auto/qtextstream/tst_qtextstream.cpp | 7 ++++++- tests/auto/xmlpatternsxqts/lib/XSDTSTestCase.h | 2 ++ tests/auto/xmlpatternsxqts/lib/XSDTestSuiteHandler.h | 2 ++ 5 files changed, 12 insertions(+), 3 deletions(-) diff --git a/tests/auto/modeltest/dynamictreemodel.h b/tests/auto/modeltest/dynamictreemodel.h index 3f0d90d..9633755 100644 --- a/tests/auto/modeltest/dynamictreemodel.h +++ b/tests/auto/modeltest/dynamictreemodel.h @@ -48,8 +48,6 @@ #include -template class QList; - class DynamicTreeModel : public QAbstractItemModel { Q_OBJECT diff --git a/tests/auto/qpixmapcache/tst_qpixmapcache.cpp b/tests/auto/qpixmapcache/tst_qpixmapcache.cpp index a0f4339..f8951f5 100644 --- a/tests/auto/qpixmapcache/tst_qpixmapcache.cpp +++ b/tests/auto/qpixmapcache/tst_qpixmapcache.cpp @@ -483,7 +483,9 @@ void tst_QPixmapCache::pixmapKey() QVERIFY(!getPrivate(key8)); } +QT_BEGIN_NAMESPACE extern int q_QPixmapCache_keyHashSize(); +QT_END_NAMESPACE void tst_QPixmapCache::noLeak() { diff --git a/tests/auto/qtextstream/tst_qtextstream.cpp b/tests/auto/qtextstream/tst_qtextstream.cpp index 8ff6bee..9146be2 100644 --- a/tests/auto/qtextstream/tst_qtextstream.cpp +++ b/tests/auto/qtextstream/tst_qtextstream.cpp @@ -4308,10 +4308,15 @@ void tst_QTextStream::int_write_with_locale() // ------------------------------------------------------------------------------ // like QTEST_APPLESS_MAIN, but initialising the locale on Unix +#if defined (Q_OS_UNIX) && !defined (Q_OS_SYMBIAN) +QT_BEGIN_NAMESPACE +extern bool qt_locale_initialized; +QT_END_NAMESPACE +#endif + int main(int argc, char *argv[]) { #if defined (Q_OS_UNIX) && !defined (Q_OS_SYMBIAN) - extern bool qt_locale_initialized; ::setlocale(LC_ALL, ""); qt_locale_initialized = true; #endif diff --git a/tests/auto/xmlpatternsxqts/lib/XSDTSTestCase.h b/tests/auto/xmlpatternsxqts/lib/XSDTSTestCase.h index 8cfa143..947687a 100644 --- a/tests/auto/xmlpatternsxqts/lib/XSDTSTestCase.h +++ b/tests/auto/xmlpatternsxqts/lib/XSDTSTestCase.h @@ -50,6 +50,7 @@ #include "TestCase.h" QT_BEGIN_HEADER +QT_BEGIN_NAMESPACE namespace QPatternistSDK { @@ -153,6 +154,7 @@ namespace QPatternistSDK }; } +QT_END_NAMESPACE QT_END_HEADER #endif diff --git a/tests/auto/xmlpatternsxqts/lib/XSDTestSuiteHandler.h b/tests/auto/xmlpatternsxqts/lib/XSDTestSuiteHandler.h index 9179a2d..5493c7d 100644 --- a/tests/auto/xmlpatternsxqts/lib/XSDTestSuiteHandler.h +++ b/tests/auto/xmlpatternsxqts/lib/XSDTestSuiteHandler.h @@ -50,6 +50,7 @@ #include "XQTSTestCase.h" QT_BEGIN_HEADER +QT_BEGIN_NAMESPACE namespace QPatternistSDK { @@ -113,6 +114,7 @@ namespace QPatternistSDK }; } +QT_END_NAMESPACE QT_END_HEADER #endif -- cgit v0.12 From 48f4fe4897ba6b98434993179b47d6d9491ae173 Mon Sep 17 00:00:00 2001 From: Rohan McGovern Date: Tue, 16 Feb 2010 10:25:03 +1000 Subject: Fixed tests using Q_DECLARE_* when Qt is configured with -qtnamespace --- tests/auto/qlocalsocket/lackey/main.cpp | 2 ++ tests/auto/qpluginloader/theplugin/plugininterface.h | 3 +++ tests/auto/qsharedmemory/lackey/main.cpp | 2 ++ tests/auto/qvariant/tst_qvariant.cpp | 5 +++++ 4 files changed, 12 insertions(+) diff --git a/tests/auto/qlocalsocket/lackey/main.cpp b/tests/auto/qlocalsocket/lackey/main.cpp index 0f1930c..1bba4f8 100644 --- a/tests/auto/qlocalsocket/lackey/main.cpp +++ b/tests/auto/qlocalsocket/lackey/main.cpp @@ -172,8 +172,10 @@ static int _q_ScriptRegisterQObjectMetaType(QScriptEngine *engine, const QScript return qScriptRegisterMetaType(engine, _q_ScriptValueFromQObject, _q_ScriptValueToQObject, prototype); } +QT_BEGIN_NAMESPACE Q_SCRIPT_DECLARE_QMETAOBJECT(QScriptLocalSocket, QObject*); Q_SCRIPT_DECLARE_QMETAOBJECT(QScriptLocalServer, QObject*); +QT_END_NAMESPACE static void interactive(QScriptEngine &eng) { diff --git a/tests/auto/qpluginloader/theplugin/plugininterface.h b/tests/auto/qpluginloader/theplugin/plugininterface.h index 0b093db..9b69429 100644 --- a/tests/auto/qpluginloader/theplugin/plugininterface.h +++ b/tests/auto/qpluginloader/theplugin/plugininterface.h @@ -45,7 +45,10 @@ struct PluginInterface { virtual ~PluginInterface() {} virtual QString pluginName() const = 0; }; + +QT_BEGIN_NAMESPACE Q_DECLARE_INTERFACE(PluginInterface, "com.trolltect.autotests.plugininterface/1.0") +QT_END_NAMESPACE #endif // PLUGININTERFACE_H diff --git a/tests/auto/qsharedmemory/lackey/main.cpp b/tests/auto/qsharedmemory/lackey/main.cpp index 5a5bf5e..fef8d22 100644 --- a/tests/auto/qsharedmemory/lackey/main.cpp +++ b/tests/auto/qsharedmemory/lackey/main.cpp @@ -242,9 +242,11 @@ private: QSharedMemory sm; }; +QT_BEGIN_NAMESPACE Q_SCRIPT_DECLARE_QMETAOBJECT(ScriptSharedMemory, QObject*); Q_SCRIPT_DECLARE_QMETAOBJECT(ScriptSystemLock, QObject*); Q_SCRIPT_DECLARE_QMETAOBJECT(ScriptSystemSemaphore, QObject*); +QT_END_NAMESPACE static void interactive(QScriptEngine &eng) { diff --git a/tests/auto/qvariant/tst_qvariant.cpp b/tests/auto/qvariant/tst_qvariant.cpp index 21b2fe3..a316dda 100644 --- a/tests/auto/qvariant/tst_qvariant.cpp +++ b/tests/auto/qvariant/tst_qvariant.cpp @@ -3200,7 +3200,10 @@ struct MyPrimitive return x == o.x && y == o.y; } }; + +QT_BEGIN_NAMESPACE Q_DECLARE_TYPEINFO(MyPrimitive, Q_PRIMITIVE_TYPE); +QT_END_NAMESPACE struct MyData { @@ -3239,7 +3242,9 @@ struct MyMovable int MyMovable::count = 0; +QT_BEGIN_NAMESPACE Q_DECLARE_TYPEINFO(MyMovable, Q_MOVABLE_TYPE); +QT_END_NAMESPACE Q_DECLARE_METATYPE(QList) Q_DECLARE_METATYPE(MyPrimitive) -- cgit v0.12 From edb3480202b762860913e5a7b9f5eafe8bda5eff Mon Sep 17 00:00:00 2001 From: Rohan McGovern Date: Tue, 16 Feb 2010 14:10:51 +1000 Subject: Fixed compile of QtHelp tests with vcproj generator. These tests were doing: SUBDIRS+=../../../tools/assistant/lib ... to ensure that part of Qt was built before building the test. That's a cute hack, but it's a bad idea: it breaks the vcproj generator to process the same subdir multiple times, and it also gives the very unintuitive result that doing `make clean' under tests/auto cleans out a part of the Qt build! --- tests/auto/qhelpcontentmodel/qhelpcontentmodel.pro | 26 +++++++++++++++------ .../qhelpcontentmodel/tst_qhelpcontentmodel.pro | 22 ------------------ tests/auto/qhelpenginecore/qhelpenginecore.pro | 27 ++++++++++++++++------ tests/auto/qhelpenginecore/tst_qhelpenginecore.pro | 23 ------------------ tests/auto/qhelpgenerator/qhelpgenerator.pro | 15 ++++++------ tests/auto/qhelpgenerator/tst_qhelpgenerator.pro | 9 -------- tests/auto/qhelpindexmodel/qhelpindexmodel.pro | 15 ++++++------ tests/auto/qhelpindexmodel/tst_qhelpindexmodel.pro | 9 -------- tests/auto/qhelpprojectdata/qhelpprojectdata.pro | 13 +++++------ .../auto/qhelpprojectdata/tst_qhelpprojectdata.pro | 9 -------- 10 files changed, 59 insertions(+), 109 deletions(-) delete mode 100644 tests/auto/qhelpcontentmodel/tst_qhelpcontentmodel.pro delete mode 100644 tests/auto/qhelpenginecore/tst_qhelpenginecore.pro delete mode 100644 tests/auto/qhelpgenerator/tst_qhelpgenerator.pro delete mode 100644 tests/auto/qhelpindexmodel/tst_qhelpindexmodel.pro delete mode 100644 tests/auto/qhelpprojectdata/tst_qhelpprojectdata.pro diff --git a/tests/auto/qhelpcontentmodel/qhelpcontentmodel.pro b/tests/auto/qhelpcontentmodel/qhelpcontentmodel.pro index 79bb44c..889aac9 100644 --- a/tests/auto/qhelpcontentmodel/qhelpcontentmodel.pro +++ b/tests/auto/qhelpcontentmodel/qhelpcontentmodel.pro @@ -1,10 +1,22 @@ -TEMPLATE = subdirs -CONFIG += ordered +load(qttest_p4) +SOURCES += tst_qhelpcontentmodel.cpp -contains(QT_BUILD_PARTS, tools): { - SUBDIRS += ../../../tools/assistant/lib/fulltextsearch \ - ../../../tools/assistant/lib -} +CONFIG += help -SUBDIRS += tst_qhelpcontentmodel.pro +DEFINES += QT_USE_USING_NAMESPACE +!contains(QT_BUILD_PARTS, tools): DEFINES += QT_NO_BUILD_TOOLS +wince*: { + DEFINES += SRCDIR=\\\"./\\\" + QT += network + addFiles.sources = $$PWD/data/*.* + addFiles.path = data + clucene.sources = $$QT_BUILD_TREE/lib/QtCLucene*.dll + + DEPLOYMENT += addFiles + DEPLOYMENT += clucene + + DEPLOYMENT_PLUGIN += qsqlite +} else { + DEFINES += SRCDIR=\\\"$$PWD\\\" +} \ No newline at end of file diff --git a/tests/auto/qhelpcontentmodel/tst_qhelpcontentmodel.pro b/tests/auto/qhelpcontentmodel/tst_qhelpcontentmodel.pro deleted file mode 100644 index 889aac9..0000000 --- a/tests/auto/qhelpcontentmodel/tst_qhelpcontentmodel.pro +++ /dev/null @@ -1,22 +0,0 @@ -load(qttest_p4) -SOURCES += tst_qhelpcontentmodel.cpp - -CONFIG += help - -DEFINES += QT_USE_USING_NAMESPACE -!contains(QT_BUILD_PARTS, tools): DEFINES += QT_NO_BUILD_TOOLS - -wince*: { - DEFINES += SRCDIR=\\\"./\\\" - QT += network - addFiles.sources = $$PWD/data/*.* - addFiles.path = data - clucene.sources = $$QT_BUILD_TREE/lib/QtCLucene*.dll - - DEPLOYMENT += addFiles - DEPLOYMENT += clucene - - DEPLOYMENT_PLUGIN += qsqlite -} else { - DEFINES += SRCDIR=\\\"$$PWD\\\" -} \ No newline at end of file diff --git a/tests/auto/qhelpenginecore/qhelpenginecore.pro b/tests/auto/qhelpenginecore/qhelpenginecore.pro index ee9b0c4..27ebd0f 100644 --- a/tests/auto/qhelpenginecore/qhelpenginecore.pro +++ b/tests/auto/qhelpenginecore/qhelpenginecore.pro @@ -1,10 +1,23 @@ -TEMPLATE = subdirs -CONFIG += ordered +load(qttest_p4) +SOURCES += tst_qhelpenginecore.cpp +CONFIG += help +QT += sql -contains(QT_BUILD_PARTS, tools): { - SUBDIRS += ../../../tools/assistant/lib/fulltextsearch \ - ../../../tools/assistant/lib -} -SUBDIRS += tst_qhelpenginecore.pro +DEFINES += QT_USE_USING_NAMESPACE +!contains(QT_BUILD_PARTS, tools): DEFINES += QT_NO_BUILD_TOOLS + +wince*: { + DEFINES += SRCDIR=\\\"./\\\" + QT += network + addFiles.sources = $$PWD/data/*.* + addFiles.path = data + clucene.sources = $$QT_BUILD_TREE/lib/QtCLucene*.dll + DEPLOYMENT += addFiles + DEPLOYMENT += clucene + + DEPLOYMENT_PLUGIN += qsqlite +} else { + DEFINES += SRCDIR=\\\"$$PWD\\\" +} diff --git a/tests/auto/qhelpenginecore/tst_qhelpenginecore.pro b/tests/auto/qhelpenginecore/tst_qhelpenginecore.pro deleted file mode 100644 index 27ebd0f..0000000 --- a/tests/auto/qhelpenginecore/tst_qhelpenginecore.pro +++ /dev/null @@ -1,23 +0,0 @@ -load(qttest_p4) -SOURCES += tst_qhelpenginecore.cpp -CONFIG += help -QT += sql - - -DEFINES += QT_USE_USING_NAMESPACE -!contains(QT_BUILD_PARTS, tools): DEFINES += QT_NO_BUILD_TOOLS - -wince*: { - DEFINES += SRCDIR=\\\"./\\\" - QT += network - addFiles.sources = $$PWD/data/*.* - addFiles.path = data - clucene.sources = $$QT_BUILD_TREE/lib/QtCLucene*.dll - - DEPLOYMENT += addFiles - DEPLOYMENT += clucene - - DEPLOYMENT_PLUGIN += qsqlite -} else { - DEFINES += SRCDIR=\\\"$$PWD\\\" -} diff --git a/tests/auto/qhelpgenerator/qhelpgenerator.pro b/tests/auto/qhelpgenerator/qhelpgenerator.pro index efa1ef5..b4b07dd 100644 --- a/tests/auto/qhelpgenerator/qhelpgenerator.pro +++ b/tests/auto/qhelpgenerator/qhelpgenerator.pro @@ -1,10 +1,9 @@ -TEMPLATE = subdirs -CONFIG += ordered +load(qttest_p4) -contains(QT_BUILD_PARTS, tools): { - SUBDIRS += ../../../tools/assistant/lib/fulltextsearch \ - ../../../tools/assistant/lib -} - -SUBDIRS += tst_qhelpgenerator.pro +SOURCES += tst_qhelpgenerator.cpp +CONFIG += help +QT += sql +DEFINES += SRCDIR=\\\"$$PWD\\\" +DEFINES += QT_USE_USING_NAMESPACE +!contains(QT_BUILD_PARTS, tools): DEFINES += QT_NO_BUILD_TOOLS diff --git a/tests/auto/qhelpgenerator/tst_qhelpgenerator.pro b/tests/auto/qhelpgenerator/tst_qhelpgenerator.pro deleted file mode 100644 index b4b07dd..0000000 --- a/tests/auto/qhelpgenerator/tst_qhelpgenerator.pro +++ /dev/null @@ -1,9 +0,0 @@ -load(qttest_p4) - -SOURCES += tst_qhelpgenerator.cpp -CONFIG += help -QT += sql - -DEFINES += SRCDIR=\\\"$$PWD\\\" -DEFINES += QT_USE_USING_NAMESPACE -!contains(QT_BUILD_PARTS, tools): DEFINES += QT_NO_BUILD_TOOLS diff --git a/tests/auto/qhelpindexmodel/qhelpindexmodel.pro b/tests/auto/qhelpindexmodel/qhelpindexmodel.pro index 1325e09..927c2e1 100644 --- a/tests/auto/qhelpindexmodel/qhelpindexmodel.pro +++ b/tests/auto/qhelpindexmodel/qhelpindexmodel.pro @@ -1,10 +1,9 @@ -TEMPLATE = subdirs -CONFIG += ordered +load(qttest_p4) -contains(QT_BUILD_PARTS, tools): { - SUBDIRS += ../../../tools/assistant/lib/fulltextsearch \ - ../../../tools/assistant/lib -} - -SUBDIRS += tst_qhelpindexmodel.pro +SOURCES += tst_qhelpindexmodel.cpp +CONFIG += help +QT += sql +DEFINES += SRCDIR=\\\"$$PWD\\\" +DEFINES += QT_USE_USING_NAMESPACE +!contains(QT_BUILD_PARTS, tools): DEFINES += QT_NO_BUILD_TOOLS diff --git a/tests/auto/qhelpindexmodel/tst_qhelpindexmodel.pro b/tests/auto/qhelpindexmodel/tst_qhelpindexmodel.pro deleted file mode 100644 index 927c2e1..0000000 --- a/tests/auto/qhelpindexmodel/tst_qhelpindexmodel.pro +++ /dev/null @@ -1,9 +0,0 @@ -load(qttest_p4) - -SOURCES += tst_qhelpindexmodel.cpp -CONFIG += help -QT += sql - -DEFINES += SRCDIR=\\\"$$PWD\\\" -DEFINES += QT_USE_USING_NAMESPACE -!contains(QT_BUILD_PARTS, tools): DEFINES += QT_NO_BUILD_TOOLS diff --git a/tests/auto/qhelpprojectdata/qhelpprojectdata.pro b/tests/auto/qhelpprojectdata/qhelpprojectdata.pro index 9617416..92dc620 100644 --- a/tests/auto/qhelpprojectdata/qhelpprojectdata.pro +++ b/tests/auto/qhelpprojectdata/qhelpprojectdata.pro @@ -1,10 +1,9 @@ -TEMPLATE = subdirs -CONFIG += ordered +load(qttest_p4) -contains(QT_BUILD_PARTS, tools): { - SUBDIRS += ../../../tools/assistant/lib/fulltextsearch \ - ../../../tools/assistant/lib -} +SOURCES += tst_qhelpprojectdata.cpp +CONFIG += help -SUBDIRS += tst_qhelpprojectdata.pro +DEFINES += SRCDIR=\\\"$$PWD\\\" +DEFINES += QT_USE_USING_NAMESPACE +!contains(QT_BUILD_PARTS, tools): DEFINES += QT_NO_BUILD_TOOLS diff --git a/tests/auto/qhelpprojectdata/tst_qhelpprojectdata.pro b/tests/auto/qhelpprojectdata/tst_qhelpprojectdata.pro deleted file mode 100644 index 92dc620..0000000 --- a/tests/auto/qhelpprojectdata/tst_qhelpprojectdata.pro +++ /dev/null @@ -1,9 +0,0 @@ -load(qttest_p4) - -SOURCES += tst_qhelpprojectdata.cpp -CONFIG += help - -DEFINES += SRCDIR=\\\"$$PWD\\\" -DEFINES += QT_USE_USING_NAMESPACE -!contains(QT_BUILD_PARTS, tools): DEFINES += QT_NO_BUILD_TOOLS - -- cgit v0.12 From 0cdf33e9acb00b8f3654e8268253a3fb7c5db92c Mon Sep 17 00:00:00 2001 From: Rohan McGovern Date: Tue, 16 Feb 2010 14:54:05 +1000 Subject: Fixed compile of shm/sem tests with vcproj generator. SUBDIRS+=../path/to/lackey from two different places means that qmake sees the lackey project twice. This breaks the vcproj generator. Make it so that lackey is only referred to once. --- tests/auto/auto.pro | 3 +- tests/auto/qsharedmemory/.gitignore | 3 - tests/auto/qsharedmemory/lackey/lackey.pro | 20 - tests/auto/qsharedmemory/lackey/main.cpp | 370 ---------- .../auto/qsharedmemory/lackey/scripts/consumer.js | 41 -- .../auto/qsharedmemory/lackey/scripts/producer.js | 44 -- .../lackey/scripts/readonly_segfault.js | 4 - .../lackey/scripts/systemlock_read.js | 11 - .../lackey/scripts/systemlock_readwrite.js | 11 - .../lackey/scripts/systemsemaphore_acquire.js | 18 - .../scripts/systemsemaphore_acquirerelease.js | 11 - .../lackey/scripts/systemsemaphore_release.js | 11 - tests/auto/qsharedmemory/qsharedmemory.pro | 4 - .../auto/qsharedmemory/qsystemlock/qsystemlock.pro | 22 - .../qsharedmemory/qsystemlock/tst_qsystemlock.cpp | 239 ------- tests/auto/qsharedmemory/src/qsystemlock.cpp | 246 ------- tests/auto/qsharedmemory/src/qsystemlock.h | 135 ---- tests/auto/qsharedmemory/src/qsystemlock_p.h | 109 --- tests/auto/qsharedmemory/src/qsystemlock_unix.cpp | 233 ------ tests/auto/qsharedmemory/src/qsystemlock_win.cpp | 182 ----- tests/auto/qsharedmemory/src/src.pri | 10 - tests/auto/qsharedmemory/test/test.pro | 37 - tests/auto/qsharedmemory/tst_qsharedmemory.cpp | 778 --------------------- tests/auto/qsystemsemaphore/.gitignore | 1 - tests/auto/qsystemsemaphore/files.qrc | 7 - tests/auto/qsystemsemaphore/qsystemsemaphore.pro | 4 - tests/auto/qsystemsemaphore/test/test.pro | 40 -- .../auto/qsystemsemaphore/tst_qsystemsemaphore.cpp | 302 -------- tests/auto/qtipc/lackey/lackey.pro | 20 + tests/auto/qtipc/lackey/main.cpp | 370 ++++++++++ tests/auto/qtipc/lackey/scripts/consumer.js | 41 ++ tests/auto/qtipc/lackey/scripts/producer.js | 44 ++ .../auto/qtipc/lackey/scripts/readonly_segfault.js | 4 + tests/auto/qtipc/lackey/scripts/systemlock_read.js | 11 + .../qtipc/lackey/scripts/systemlock_readwrite.js | 11 + .../lackey/scripts/systemsemaphore_acquire.js | 18 + .../scripts/systemsemaphore_acquirerelease.js | 11 + .../lackey/scripts/systemsemaphore_release.js | 11 + tests/auto/qtipc/qsharedmemory/.gitignore | 3 + tests/auto/qtipc/qsharedmemory/qsharedmemory.pro | 4 + .../qsharedmemory/qsystemlock/qsystemlock.pro | 22 + .../qsharedmemory/qsystemlock/tst_qsystemlock.cpp | 239 +++++++ tests/auto/qtipc/qsharedmemory/src/qsystemlock.cpp | 246 +++++++ tests/auto/qtipc/qsharedmemory/src/qsystemlock.h | 135 ++++ tests/auto/qtipc/qsharedmemory/src/qsystemlock_p.h | 109 +++ .../qtipc/qsharedmemory/src/qsystemlock_unix.cpp | 233 ++++++ .../qtipc/qsharedmemory/src/qsystemlock_win.cpp | 182 +++++ tests/auto/qtipc/qsharedmemory/src/src.pri | 10 + tests/auto/qtipc/qsharedmemory/test/test.pro | 37 + .../auto/qtipc/qsharedmemory/tst_qsharedmemory.cpp | 776 ++++++++++++++++++++ tests/auto/qtipc/qsystemsemaphore/.gitignore | 1 + tests/auto/qtipc/qsystemsemaphore/files.qrc | 7 + .../qtipc/qsystemsemaphore/qsystemsemaphore.pro | 36 + .../qsystemsemaphore/tst_qsystemsemaphore.cpp | 302 ++++++++ tests/auto/qtipc/qtipc.pro | 6 + 55 files changed, 2890 insertions(+), 2895 deletions(-) delete mode 100644 tests/auto/qsharedmemory/.gitignore delete mode 100644 tests/auto/qsharedmemory/lackey/lackey.pro delete mode 100644 tests/auto/qsharedmemory/lackey/main.cpp delete mode 100644 tests/auto/qsharedmemory/lackey/scripts/consumer.js delete mode 100644 tests/auto/qsharedmemory/lackey/scripts/producer.js delete mode 100644 tests/auto/qsharedmemory/lackey/scripts/readonly_segfault.js delete mode 100644 tests/auto/qsharedmemory/lackey/scripts/systemlock_read.js delete mode 100644 tests/auto/qsharedmemory/lackey/scripts/systemlock_readwrite.js delete mode 100644 tests/auto/qsharedmemory/lackey/scripts/systemsemaphore_acquire.js delete mode 100644 tests/auto/qsharedmemory/lackey/scripts/systemsemaphore_acquirerelease.js delete mode 100644 tests/auto/qsharedmemory/lackey/scripts/systemsemaphore_release.js delete mode 100644 tests/auto/qsharedmemory/qsharedmemory.pro delete mode 100644 tests/auto/qsharedmemory/qsystemlock/qsystemlock.pro delete mode 100644 tests/auto/qsharedmemory/qsystemlock/tst_qsystemlock.cpp delete mode 100644 tests/auto/qsharedmemory/src/qsystemlock.cpp delete mode 100644 tests/auto/qsharedmemory/src/qsystemlock.h delete mode 100644 tests/auto/qsharedmemory/src/qsystemlock_p.h delete mode 100644 tests/auto/qsharedmemory/src/qsystemlock_unix.cpp delete mode 100644 tests/auto/qsharedmemory/src/qsystemlock_win.cpp delete mode 100644 tests/auto/qsharedmemory/src/src.pri delete mode 100644 tests/auto/qsharedmemory/test/test.pro delete mode 100644 tests/auto/qsharedmemory/tst_qsharedmemory.cpp delete mode 100644 tests/auto/qsystemsemaphore/.gitignore delete mode 100644 tests/auto/qsystemsemaphore/files.qrc delete mode 100644 tests/auto/qsystemsemaphore/qsystemsemaphore.pro delete mode 100644 tests/auto/qsystemsemaphore/test/test.pro delete mode 100644 tests/auto/qsystemsemaphore/tst_qsystemsemaphore.cpp create mode 100644 tests/auto/qtipc/lackey/lackey.pro create mode 100644 tests/auto/qtipc/lackey/main.cpp create mode 100644 tests/auto/qtipc/lackey/scripts/consumer.js create mode 100644 tests/auto/qtipc/lackey/scripts/producer.js create mode 100644 tests/auto/qtipc/lackey/scripts/readonly_segfault.js create mode 100644 tests/auto/qtipc/lackey/scripts/systemlock_read.js create mode 100644 tests/auto/qtipc/lackey/scripts/systemlock_readwrite.js create mode 100644 tests/auto/qtipc/lackey/scripts/systemsemaphore_acquire.js create mode 100644 tests/auto/qtipc/lackey/scripts/systemsemaphore_acquirerelease.js create mode 100644 tests/auto/qtipc/lackey/scripts/systemsemaphore_release.js create mode 100644 tests/auto/qtipc/qsharedmemory/.gitignore create mode 100644 tests/auto/qtipc/qsharedmemory/qsharedmemory.pro create mode 100644 tests/auto/qtipc/qsharedmemory/qsystemlock/qsystemlock.pro create mode 100644 tests/auto/qtipc/qsharedmemory/qsystemlock/tst_qsystemlock.cpp create mode 100644 tests/auto/qtipc/qsharedmemory/src/qsystemlock.cpp create mode 100644 tests/auto/qtipc/qsharedmemory/src/qsystemlock.h create mode 100644 tests/auto/qtipc/qsharedmemory/src/qsystemlock_p.h create mode 100644 tests/auto/qtipc/qsharedmemory/src/qsystemlock_unix.cpp create mode 100644 tests/auto/qtipc/qsharedmemory/src/qsystemlock_win.cpp create mode 100644 tests/auto/qtipc/qsharedmemory/src/src.pri create mode 100644 tests/auto/qtipc/qsharedmemory/test/test.pro create mode 100644 tests/auto/qtipc/qsharedmemory/tst_qsharedmemory.cpp create mode 100644 tests/auto/qtipc/qsystemsemaphore/.gitignore create mode 100644 tests/auto/qtipc/qsystemsemaphore/files.qrc create mode 100644 tests/auto/qtipc/qsystemsemaphore/qsystemsemaphore.pro create mode 100644 tests/auto/qtipc/qsystemsemaphore/tst_qsystemsemaphore.cpp create mode 100644 tests/auto/qtipc/qtipc.pro diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro index 022b19a..9961e25 100644 --- a/tests/auto/auto.pro +++ b/tests/auto/auto.pro @@ -445,17 +445,16 @@ SUBDIRS += \ qplugin \ qpluginloader \ qscrollbar \ - qsharedmemory \ qsidebar \ qsizegrip \ qsqldriver \ - qsystemsemaphore \ qtconcurrentfilter \ qtconcurrentiteratekernel \ qtconcurrentmap \ qtconcurrentrun \ qtconcurrentthreadengine \ qthreadpool \ + qtipc \ qtokenautomaton \ qtouchevent \ qwidget_window \ diff --git a/tests/auto/qsharedmemory/.gitignore b/tests/auto/qsharedmemory/.gitignore deleted file mode 100644 index 03ddcf2..0000000 --- a/tests/auto/qsharedmemory/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -tst_qsharedmemory -lackey/lackey.exe -qsystemlock/tst_qsystemlock.exe diff --git a/tests/auto/qsharedmemory/lackey/lackey.pro b/tests/auto/qsharedmemory/lackey/lackey.pro deleted file mode 100644 index d25a50a..0000000 --- a/tests/auto/qsharedmemory/lackey/lackey.pro +++ /dev/null @@ -1,20 +0,0 @@ -include(../src/src.pri) - -QT = core script - -CONFIG += qtestlib - -DESTDIR = ./ - -win32: CONFIG += console -mac:CONFIG -= app_bundle - -requires(contains(QT_CONFIG,script)) - -DEFINES += QSHAREDMEMORY_DEBUG -DEFINES += QSYSTEMSEMAPHORE_DEBUG - -SOURCES += main.cpp -TARGET = lackey - - diff --git a/tests/auto/qsharedmemory/lackey/main.cpp b/tests/auto/qsharedmemory/lackey/main.cpp deleted file mode 100644 index fef8d22..0000000 --- a/tests/auto/qsharedmemory/lackey/main.cpp +++ /dev/null @@ -1,370 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 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 -#include - -#include -#include -#include -#include -#include - -class ScriptSystemSemaphore : public QObject -{ - Q_OBJECT - -public: - ScriptSystemSemaphore(QObject *parent = 0) : QObject(parent), ss(QString()) - { - } - -public slots: - bool acquire() - { - return ss.acquire(); - }; - - bool release(int n = 1) - { - return ss.release(n); - }; - - void setKey(const QString &key, int n = 0) - { - ss.setKey(key, n); - }; - - QString key() const - { - return ss.key(); - } - -private: - QSystemSemaphore ss; -}; - -class ScriptSystemLock : public QObject -{ - Q_OBJECT - Q_PROPERTY(QString key WRITE setKey READ key) - -public: - ScriptSystemLock(QObject *parent = 0) : QObject(parent), sl(QString()) - { - } - -public slots: - - bool lockReadOnly() - { - return sl.lock(QSystemLock::ReadOnly); - } - - bool lock() - { - return sl.lock(); - }; - - bool unlock() - { - return sl.unlock(); - }; - - void setKey(const QString &key) - { - sl.setKey(key); - }; - - QString key() const - { - return sl.key(); - } - -private: - QSystemLock sl; -}; - -class ScriptSharedMemory : public QObject -{ - Q_OBJECT - Q_PROPERTY(bool attached READ isAttached) - Q_PROPERTY(QString key WRITE setKey READ key) - -public: - enum SharedMemoryError - { - NoError = 0, - PermissionDenied = 1, - InvalidSize = 2, - KeyError = 3, - AlreadyExists = 4, - NotFound = 5, - LockError = 6, - OutOfResources = 7, - UnknownError = 8 - }; - - ScriptSharedMemory(QObject *parent = 0) : QObject(parent) - { - } - -public slots: - void sleep(int x) const - { - QTest::qSleep(x); - } - - bool create(int size) - { - return sm.create(size); - }; - - bool createReadOnly(int size) - { - return sm.create(size, QSharedMemory::ReadOnly); - }; - - int size() const - { - return sm.size(); - }; - - bool attach() - { - return sm.attach(); - }; - - bool attachReadOnly() - { - return sm.attach(QSharedMemory::ReadOnly); - }; - - bool isAttached() const - { - return sm.isAttached(); - }; - - bool detach() - { - return sm.detach(); - }; - - int error() const - { - return (int)sm.error(); - }; - - QString errorString() const - { - return sm.errorString(); - }; - - void set(int i, QChar value) - { - ((char*)sm.data())[i] = value.toLatin1(); - } - - QString get(int i) - { - return QChar::fromLatin1(((char*)sm.data())[i]); - } - - char *data() const - { - return (char*)sm.data(); - }; - - void setKey(const QString &key) - { - sm.setKey(key); - }; - - QString key() const - { - return sm.key(); - } - - bool lock() - { - return sm.lock(); - } - - bool unlock() - { - return sm.unlock(); - } - -private: - QSharedMemory sm; -}; - -QT_BEGIN_NAMESPACE -Q_SCRIPT_DECLARE_QMETAOBJECT(ScriptSharedMemory, QObject*); -Q_SCRIPT_DECLARE_QMETAOBJECT(ScriptSystemLock, QObject*); -Q_SCRIPT_DECLARE_QMETAOBJECT(ScriptSystemSemaphore, QObject*); -QT_END_NAMESPACE - -static void interactive(QScriptEngine &eng) -{ -#ifdef Q_OS_WINCE - fprintf(stderr, "Interactive mode not supported on Windows CE\n"); - return; -#endif - QTextStream qin(stdin, QFile::ReadOnly); - - const char *qscript_prompt = "qs> "; - const char *dot_prompt = ".... "; - const char *prompt = qscript_prompt; - - QString code; - - forever { - QString line; - - printf("%s", prompt); - fflush(stdout); - - line = qin.readLine(); - if (line.isNull()) - break; - - code += line; - code += QLatin1Char('\n'); - - if (line.trimmed().isEmpty()) { - continue; - - } else if (! eng.canEvaluate(code)) { - prompt = dot_prompt; - - } else { - QScriptValue result = eng.evaluate(code); - code.clear(); - prompt = qscript_prompt; - if (!result.isUndefined()) - fprintf(stderr, "%s\n", qPrintable(result.toString())); - } - } -} - -int main(int argc, char *argv[]) -{ - QCoreApplication app(argc, argv); - - QScriptEngine eng; - QScriptValue globalObject = eng.globalObject(); - - QScriptValue sm = qScriptValueFromQMetaObject(&eng); - eng.globalObject().setProperty("ScriptSharedMemory", sm); - - QScriptValue sl = qScriptValueFromQMetaObject(&eng); - eng.globalObject().setProperty("ScriptSystemLock", sl); - - QScriptValue ss = qScriptValueFromQMetaObject(&eng); - eng.globalObject().setProperty("ScriptSystemSemaphore", ss); - - - if (! *++argv) { - interactive(eng); - return EXIT_SUCCESS; - } - - QStringList arguments = app.arguments(); - arguments.takeFirst(); - - while (!arguments.isEmpty()) { - QString fn = arguments.takeFirst(); - - if (fn == QLatin1String("-i")) { - interactive(eng); - break; - } - - QString contents; - - if (fn == QLatin1String("-")) { - QTextStream stream(stdin, QFile::ReadOnly); - contents = stream.readAll(); - } else { - QFile file(fn); - if (!file.exists()) { - fprintf(stderr, "%s doesn't exists\n", qPrintable(fn)); - return EXIT_FAILURE; - } - if (file.open(QFile::ReadOnly)) { - QTextStream stream(&file); - contents = stream.readAll(); - file.close(); - } - } - - if (contents.isEmpty()) - continue; - - if (contents[0] == '#') { - contents.prepend("//"); - QScriptValue args = eng.newArray(); - args.setProperty("0", QScriptValue(&eng, fn)); - int i = 1; - while (!arguments.isEmpty()) - args.setProperty(i++, QScriptValue(&eng, arguments.takeFirst())); - eng.currentContext()->activationObject().setProperty("args", args); - } - QScriptValue r = eng.evaluate(contents); - if (eng.hasUncaughtException()) { - int line = eng.uncaughtExceptionLineNumber(); - fprintf(stderr, "%d: %s\n\t%s\n\n", line, qPrintable(fn), qPrintable(r.toString())); - return EXIT_FAILURE; - } - if (r.isNumber()) - return r.toInt32(); - } - - return EXIT_SUCCESS; -} - -#include "main.moc" diff --git a/tests/auto/qsharedmemory/lackey/scripts/consumer.js b/tests/auto/qsharedmemory/lackey/scripts/consumer.js deleted file mode 100644 index 4d12dca..0000000 --- a/tests/auto/qsharedmemory/lackey/scripts/consumer.js +++ /dev/null @@ -1,41 +0,0 @@ -function QVERIFY(x, debugInfo) { - if (!(x)) { - print(debugInfo); - throw(debugInfo); - } -} - -var consumer = new ScriptSharedMemory; -consumer.setKey("market"); - -//print("consumer starting"); -var tries = 0;; -while(!consumer.attach()) { - if (tries == 5000) { - var message = "consumer exiting, waiting too long"; - print(message); - throw(message); - } - ++tries; - consumer.sleep(1); -} -//print("consumer attached"); - - -var i = 0; -while(true) { - QVERIFY(consumer.lock(), "lock"); - if (consumer.get(0) == 'Q') { - consumer.set(0, ++i); - //print ("consumer sets" + i); - } - if (consumer.get(0) == 'E') { - QVERIFY(consumer.unlock(), "unlock"); - break; - } - QVERIFY(consumer.unlock(), "unlock"); - consumer.sleep(10); -} - -//print("consumer detaching"); -QVERIFY(consumer.detach()); diff --git a/tests/auto/qsharedmemory/lackey/scripts/producer.js b/tests/auto/qsharedmemory/lackey/scripts/producer.js deleted file mode 100644 index e02cd8b..0000000 --- a/tests/auto/qsharedmemory/lackey/scripts/producer.js +++ /dev/null @@ -1,44 +0,0 @@ -function QVERIFY(x, debugInfo) { - if (!(x)) { - print(debugInfo); - throw(debugInfo); - } -} - -var producer = new ScriptSharedMemory; -producer.setKey("market"); - -var size = 1024; -if (!producer.create(size)) { - QVERIFY(producer.error() == 4, "create"); - QVERIFY(producer.attach()); -} -//print ("producer created and attached"); - -QVERIFY(producer.lock()); -producer.set(0, 'Q'); -QVERIFY(producer.unlock()); - -var i = 0; -while(i < 5) { - QVERIFY(producer.lock(), "lock"); - if (producer.get(0) == 'Q') { - QVERIFY(producer.unlock(), "unlock"); - producer.sleep(1); - continue; - } - //print("producer: " + i); - ++i; - producer.set(0, 'Q'); - QVERIFY(producer.unlock(), "unlock"); - producer.sleep(1); -} -QVERIFY(producer.lock()); -producer.set(0, 'E'); -QVERIFY(producer.unlock()); - -//print ("producer done"); - -// Sleep for a bit to let all consumers start, otherwise they will get stuck in the attach loop, -// because at least in Symbian the shared memory will be destroyed if there are no active handles to it. -producer.sleep(3000); \ No newline at end of file diff --git a/tests/auto/qsharedmemory/lackey/scripts/readonly_segfault.js b/tests/auto/qsharedmemory/lackey/scripts/readonly_segfault.js deleted file mode 100644 index 3eaf789..0000000 --- a/tests/auto/qsharedmemory/lackey/scripts/readonly_segfault.js +++ /dev/null @@ -1,4 +0,0 @@ -var sm = new ScriptSharedMemory; -sm.setKey("readonly_segfault"); -sm.createReadOnly(1024); -var data = sm.set(0, "a"); diff --git a/tests/auto/qsharedmemory/lackey/scripts/systemlock_read.js b/tests/auto/qsharedmemory/lackey/scripts/systemlock_read.js deleted file mode 100644 index 1048bc7..0000000 --- a/tests/auto/qsharedmemory/lackey/scripts/systemlock_read.js +++ /dev/null @@ -1,11 +0,0 @@ -function QVERIFY(x, debugInfo) { - if (!(x)) { - print(debugInfo); - throw(debugInfo); - } -} - -var lock = new ScriptSystemLock; -lock.setKey("market"); -QVERIFY(lock.lockReadOnly()); -QVERIFY(lock.unlock()); \ No newline at end of file diff --git a/tests/auto/qsharedmemory/lackey/scripts/systemlock_readwrite.js b/tests/auto/qsharedmemory/lackey/scripts/systemlock_readwrite.js deleted file mode 100644 index fc6367f..0000000 --- a/tests/auto/qsharedmemory/lackey/scripts/systemlock_readwrite.js +++ /dev/null @@ -1,11 +0,0 @@ -function QVERIFY(x, debugInfo) { - if (!(x)) { - print(debugInfo); - throw(debugInfo); - } -} - -var lock = new ScriptSystemLock; -lock.setKey("market"); -QVERIFY(lock.lock()); -QVERIFY(lock.unlock()); diff --git a/tests/auto/qsharedmemory/lackey/scripts/systemsemaphore_acquire.js b/tests/auto/qsharedmemory/lackey/scripts/systemsemaphore_acquire.js deleted file mode 100644 index 5cff429..0000000 --- a/tests/auto/qsharedmemory/lackey/scripts/systemsemaphore_acquire.js +++ /dev/null @@ -1,18 +0,0 @@ -#/bin/qscript -function QVERIFY(x, debugInfo) { - if (!(x)) { - print(debugInfo); - throw(debugInfo); - } -} - - -var sem = new ScriptSystemSemaphore; -sem.setKey("store"); - -var count = Number(args[1]); -if (isNaN(count)) - count = 1; -for (var i = 0; i < count; ++i) - QVERIFY(sem.acquire()); -print("done aquiring"); diff --git a/tests/auto/qsharedmemory/lackey/scripts/systemsemaphore_acquirerelease.js b/tests/auto/qsharedmemory/lackey/scripts/systemsemaphore_acquirerelease.js deleted file mode 100644 index cedde3f..0000000 --- a/tests/auto/qsharedmemory/lackey/scripts/systemsemaphore_acquirerelease.js +++ /dev/null @@ -1,11 +0,0 @@ -function QVERIFY(x, debugInfo) { - if (!(x)) { - print(debugInfo); - throw(debugInfo); - } -} - -var lock = new ScriptSystemSemaphore; -lock.setKey("store"); -QVERIFY(lock.acquire()); -QVERIFY(lock.release()); diff --git a/tests/auto/qsharedmemory/lackey/scripts/systemsemaphore_release.js b/tests/auto/qsharedmemory/lackey/scripts/systemsemaphore_release.js deleted file mode 100644 index c805e0f..0000000 --- a/tests/auto/qsharedmemory/lackey/scripts/systemsemaphore_release.js +++ /dev/null @@ -1,11 +0,0 @@ -function QVERIFY(x, debugInfo) { - if (!(x)) { - print(debugInfo); - throw(debugInfo); - } -} - -var sem = new ScriptSystemSemaphore; -sem.setKey("store"); -QVERIFY(sem.release()); -print ("done releasing"); diff --git a/tests/auto/qsharedmemory/qsharedmemory.pro b/tests/auto/qsharedmemory/qsharedmemory.pro deleted file mode 100644 index 0aad554..0000000 --- a/tests/auto/qsharedmemory/qsharedmemory.pro +++ /dev/null @@ -1,4 +0,0 @@ -TEMPLATE = subdirs -SUBDIRS = lackey test qsystemlock - - diff --git a/tests/auto/qsharedmemory/qsystemlock/qsystemlock.pro b/tests/auto/qsharedmemory/qsystemlock/qsystemlock.pro deleted file mode 100644 index e232443..0000000 --- a/tests/auto/qsharedmemory/qsystemlock/qsystemlock.pro +++ /dev/null @@ -1,22 +0,0 @@ -CONFIG += qttest_p4 -#QT = core - -include(../src/src.pri) -win32: CONFIG += console -mac:CONFIG -= app_bundle - -wince* { - DEFINES += SRCDIR=\\\"\\\" -} else:!symbian { - DEFINES += SRCDIR=\\\"$$PWD\\\" -} - -DESTDIR = ./ - -DEFINES += QSHAREDMEMORY_DEBUG -DEFINES += QSYSTEMSEMAPHORE_DEBUG - -SOURCES += tst_qsystemlock.cpp -TARGET = tst_qsystemlock - - diff --git a/tests/auto/qsharedmemory/qsystemlock/tst_qsystemlock.cpp b/tests/auto/qsharedmemory/qsystemlock/tst_qsystemlock.cpp deleted file mode 100644 index ea906b7..0000000 --- a/tests/auto/qsharedmemory/qsystemlock/tst_qsystemlock.cpp +++ /dev/null @@ -1,239 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 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 - -//TESTED_CLASS= -//TESTED_FILES= - -#ifdef Q_OS_SYMBIAN -// In Symbian OS test data is located in applications private dir -// And underlying Open C have application private dir in default search path -#define SRCDIR "" -#endif - - -#define EXISTING_SHARE "existing" - -class tst_QSystemLock : public QObject -{ - Q_OBJECT - -public: - tst_QSystemLock(); - virtual ~tst_QSystemLock(); - -public Q_SLOTS: - void init(); - void cleanup(); - -private slots: - void key_data(); - void key(); - - void basicLock(); - void complexLock(); - void lockModes(); - void sucessive(); - void processes_data(); - void processes(); - -private: - QSystemLock *existingLock; - -}; - -tst_QSystemLock::tst_QSystemLock() -{ -} - -tst_QSystemLock::~tst_QSystemLock() -{ -} - -void tst_QSystemLock::init() -{ - existingLock = new QSystemLock(EXISTING_SHARE); -} - -void tst_QSystemLock::cleanup() -{ - delete existingLock; -} - -void tst_QSystemLock::key_data() -{ - QTest::addColumn("constructorKey"); - QTest::addColumn("setKey"); - - QTest::newRow("null, null") << QString() << QString(); - QTest::newRow("null, one") << QString() << QString("one"); - QTest::newRow("one, two") << QString("one") << QString("two"); -} - -/*! - Basic key testing - */ -void tst_QSystemLock::key() -{ - QFETCH(QString, constructorKey); - QFETCH(QString, setKey); - - QSystemLock sl(constructorKey); - QCOMPARE(sl.key(), constructorKey); - sl.setKey(setKey); - QCOMPARE(sl.key(), setKey); -} - -void tst_QSystemLock::basicLock() -{ - QSystemLock lock("foo"); - QVERIFY(lock.lock()); - QVERIFY(lock.unlock()); -} - -void tst_QSystemLock::complexLock() -{ - QSystemLock lock("foo"); - QVERIFY(lock.lock(QSystemLock::ReadOnly)); - QVERIFY(lock.unlock()); - - QVERIFY(lock.lock(QSystemLock::ReadWrite)); - QVERIFY(lock.unlock()); - - QVERIFY(lock.lock(QSystemLock::ReadOnly)); - QVERIFY(lock.lock(QSystemLock::ReadOnly)); - QVERIFY(lock.unlock()); - QVERIFY(lock.unlock()); -} - -void tst_QSystemLock::lockModes() -{ - QSystemLock reader1("library"); - QSystemLock reader2("library"); - - QSystemLock librarian("library"); - QVERIFY(reader1.lock(QSystemLock::ReadOnly)); - QVERIFY(reader2.lock(QSystemLock::ReadOnly)); - QVERIFY(reader1.unlock()); - QVERIFY(reader2.unlock()); - QVERIFY(librarian.lock(QSystemLock::ReadWrite)); - QVERIFY(librarian.unlock()); -} - -void tst_QSystemLock::sucessive() -{ - QSystemLock lock("library"); - QVERIFY(lock.lock(QSystemLock::ReadOnly)); - QVERIFY(lock.lock(QSystemLock::ReadOnly)); - QVERIFY(lock.lock(QSystemLock::ReadOnly)); - QVERIFY(lock.lock(QSystemLock::ReadOnly)); - QVERIFY(lock.lock(QSystemLock::ReadOnly)); - QVERIFY(lock.unlock()); - QVERIFY(lock.unlock()); - QVERIFY(lock.unlock()); - QVERIFY(lock.unlock()); - QVERIFY(lock.unlock()); - QVERIFY(!lock.unlock()); -} - -void tst_QSystemLock::processes_data() -{ - QTest::addColumn("readOnly"); - QTest::addColumn("readWrite"); - for (int i = 0; i < 5; ++i) { - QTest::newRow("1/0 process") << 1 << 0; - QTest::newRow("0/1 process") << 0 << 1; - QTest::newRow("0/4 process") << 0 << 4; - QTest::newRow("1/1 process") << 1 << 1; - QTest::newRow("10/1 process") << 10 << 1; - QTest::newRow("1/10 process") << 1 << 10; - QTest::newRow("10/10 processes") << 10 << 10; - } -} - -/*! - Create external processes - */ -void tst_QSystemLock::processes() -{ - QSKIP("This test takes about 15 minutes and needs to be trimmed down before we can re-enable it", SkipAll); - QFETCH(int, readOnly); - QFETCH(int, readWrite); - - QStringList scripts; - for (int i = 0; i < readOnly; ++i) - scripts.append(QFileInfo(SRCDIR "/../lackey/scripts/systemlock_read.js").absoluteFilePath() ); - for (int i = 0; i < readWrite; ++i) - scripts.append(QFileInfo(SRCDIR "/../lackey/scripts/systemlock_readwrite.js").absoluteFilePath()); - - QList consumers; - unsigned int failedProcesses = 0; - for (int i = 0; i < scripts.count(); ++i) { - - QStringList arguments = QStringList() << scripts.at(i); - QProcess *p = new QProcess; - p->setProcessChannelMode(QProcess::ForwardedChannels); - - p->start("../lackey/lackey", arguments); - // test, if the process could be started. - - if (p->waitForStarted(2000)) - consumers.append(p); - else - ++failedProcesses; - } - - while (!consumers.isEmpty()) { - consumers.first()->waitForFinished(3000); - consumers.first()->kill(); - QCOMPARE(consumers.first()->exitStatus(), QProcess::NormalExit); - QCOMPARE(consumers.first()->exitCode(), 0); - delete consumers.takeFirst(); - } - QCOMPARE(failedProcesses, (unsigned int)(0)); -} - -QTEST_MAIN(tst_QSystemLock) -#include "tst_qsystemlock.moc" - diff --git a/tests/auto/qsharedmemory/src/qsystemlock.cpp b/tests/auto/qsharedmemory/src/qsystemlock.cpp deleted file mode 100644 index 4ead748..0000000 --- a/tests/auto/qsharedmemory/src/qsystemlock.cpp +++ /dev/null @@ -1,246 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 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 "qsystemlock.h" -#include "qsystemlock_p.h" - -#include - -/*! \class QSystemLocker - - \brief The QSystemLocker class is a convenience class that simplifies - locking and unlocking system locks. - - The purpose of QSystemLocker is to simplify QSystemLock locking and - unlocking. Locking and unlocking a QSystemLock in complex functions and - statements or in exception handling code is error-prone and difficult to - debug. QSystemLocker can be used in such situations to ensure that the - state of the locks is always well-defined. - - QSystemLocker should be created within a function where a QSystemLock needs - to be locked. The system lock is locked when QSystemLocker is created. If - locked, the system lock will be unlocked when the QSystemLocker is - destroyed. QSystemLocker can be unlocked with unlock() and relocked with - relock(). - - \sa QSystemLock - */ - -/*! \fn QSystemLocker::QSystemLocker() - - Constructs a QSystemLocker and locks \a lock. The \a lock will be - unlocked when the QSystemLocker is destroyed. If lock is zero, - QSystemLocker does nothing. - - \sa QSystemLock::lock() - */ - -/*! \fn QSystemLocker::~QSystemLocker() - - Destroys the QSystemLocker and unlocks it if it was - locked in the constructor. - - \sa QSystemLock::unlock() - */ - -/*! \fn QSystemLocker::systemLock() - - Returns a pointer to the lock that was locked in the constructor. - */ - -/*! \fn QSystemLocker::relock() - - Relocks an unlocked locker. - - \sa unlock() - */ - -/*! \fn QSystemLocker::unlock() - - Unlocks this locker. You can use relock() to lock it again. - It does not need to be locked when destroyed. - - \sa relock() - */ - -/*! \class QSystemLock - - \brief The QSystemLock class provides a system wide lock - that can be used between threads or processes. - - The purpose of a QSystemLocker is to protect an object that can be - accessed by multiple threads or processes such as shared memory or a file. - - For example, say there is a method which prints a message to a log file: - - void log(const QString &logText) - { - QSystemLock systemLock(QLatin1String("logfile")); - systemLock.lock(); - QFile file(QDir::temp() + QLatin1String("/log")); - if (file.open(QIODevice::Append)) { - QTextStream out(&file); - out << logText; - } - systemLock.unlock(); - } - - If this is called from two seperate processes the resulting log file is - guaranteed to contain both lines. - - When you call lock(), other threads or processes that try to call lock() - with the same key will block until the thread or process that got the lock - calls unlock(). - - A non-blocking alternative to lock() is tryLock(). - */ - -/*! - Constructs a new system lock with \a key. The lock is created in an - unlocked state. - - \sa lock(), key(). - */ -QSystemLock::QSystemLock(const QString &key) -{ - d = new QSystemLockPrivate; - setKey(key); -} - -/*! - Destroys a system lock. - - warning: This will not unlock the system lock if it has been locked. -*/ -QSystemLock::~QSystemLock() -{ - d->cleanHandle(); - delete d; -} - -/*! - Sets a new key to this system lock. - - \sa key() - */ -void QSystemLock::setKey(const QString &key) -{ - if (key == d->key) - return; - d->cleanHandle(); - d->lockCount = 0; - d->key = key; - // cache the file name so it doesn't have to be generated all the time. - d->fileName = d->makeKeyFileName(); - d->error = QSystemLock::NoError; - d->errorString = QString(); - d->handle(); -} - -/*! - Returns the key assigned to this system lock - - \sa setKey() - */ -QString QSystemLock::key() const -{ - return d->key; -} - -/*! - Locks the system lock. Lock \a mode can either be ReadOnly or ReadWrite. - If a mode is ReadOnly, attempts by other processes to obtain - ReadOnly locks will succeed, and ReadWrite attempts will block until - all of the ReadOnly locks are unlocked. If locked as ReadWrite, all - other attempts to lock will block until the lock is unlocked. A given - QSystemLock can be locked multiple times without blocking, and will - only be unlocked after a corresponding number of unlock() - calls are made. Returns true on success; otherwise returns false. - - \sa unlock(), tryLock() - */ -bool QSystemLock::lock(LockMode mode) -{ - if (d->lockCount > 0 && mode == ReadOnly && d->lockedMode == ReadWrite) { - qWarning() << "QSystemLock::lock readwrite lock on top of readonly lock."; - return false; - } - return d->modifySemaphore(QSystemLockPrivate::Lock, mode); -} - -/*! - Unlocks the system lock. - Returns true on success; otherwise returns false. - - \sa lock() - */ -bool QSystemLock::unlock() -{ - if (d->lockCount == 0) { - qWarning() << "QSystemLock::unlock: unlock with no lock."; - return false; - } - return d->modifySemaphore(QSystemLockPrivate::Unlock, d->lockedMode); -} - -/*! - Returns the type of error that occurred last or NoError. - - \sa errorString() - */ -QSystemLock::SystemLockError QSystemLock::error() const -{ - return d->error; -} - -/*! - Returns the human-readable message appropriate to the current error - reported by error(). If no suitable string is available, an empty - string is returned. - - \sa error() - */ -QString QSystemLock::errorString() const -{ - return d->errorString; -} - diff --git a/tests/auto/qsharedmemory/src/qsystemlock.h b/tests/auto/qsharedmemory/src/qsystemlock.h deleted file mode 100644 index 7cd6b89..0000000 --- a/tests/auto/qsharedmemory/src/qsystemlock.h +++ /dev/null @@ -1,135 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 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$ -** -****************************************************************************/ - - -#ifndef QSYSTEMLOCK_H -#define QSYSTEMLOCK_H - -#include - -QT_BEGIN_HEADER - -#ifndef QT_NO_SYSTEMLOCK - -QT_FORWARD_DECLARE_CLASS(QSystemLockPrivate) - -class QSystemLock -{ - -public: - enum SystemLockError - { - NoError, - UnknownError - }; - - QSystemLock(const QString &key); - ~QSystemLock(); - - void setKey(const QString &key); - QString key() const; - - enum LockMode - { - ReadOnly, - ReadWrite - }; - - bool lock(LockMode mode = ReadWrite); - bool unlock(); - - SystemLockError error() const; - QString errorString() const; - -private: - Q_DISABLE_COPY(QSystemLock) - - QSystemLockPrivate *d; -}; - -class QSystemLocker -{ - -public: - inline QSystemLocker(QSystemLock *systemLock, - QSystemLock::LockMode mode = QSystemLock::ReadWrite) : q_lock(systemLock) - { - autoUnLocked = relock(mode); - } - - inline ~QSystemLocker() - { - if (autoUnLocked) - unlock(); - } - - inline QSystemLock *systemLock() const - { - return q_lock; - } - - inline bool relock(QSystemLock::LockMode mode = QSystemLock::ReadWrite) - { - return (q_lock && q_lock->lock(mode)); - } - - inline bool unlock() - { - if (q_lock && q_lock->unlock()) { - autoUnLocked = false; - return true; - } - return false; - } - -private: - Q_DISABLE_COPY(QSystemLocker) - - bool autoUnLocked; - QSystemLock *q_lock; -}; - -#endif // QT_NO_SYSTEMLOCK - -QT_END_HEADER - -#endif // QSYSTEMLOCK_H - diff --git a/tests/auto/qsharedmemory/src/qsystemlock_p.h b/tests/auto/qsharedmemory/src/qsystemlock_p.h deleted file mode 100644 index 7995a91..0000000 --- a/tests/auto/qsharedmemory/src/qsystemlock_p.h +++ /dev/null @@ -1,109 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 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$ -** -****************************************************************************/ - - -#ifndef QSYSTEMLOCK_P_H -#define QSYSTEMLOCK_P_H - -#ifndef QT_NO_SYSTEMLOCK - -#include "qsystemlock.h" -#include "private/qsharedmemory_p.h" -#ifndef Q_OS_WINCE -#include -#endif - -#define MAX_LOCKS 64 - -class QSystemLockPrivate -{ - -public: - QSystemLockPrivate(); - - QString makeKeyFileName() - { - return QSharedMemoryPrivate::makePlatformSafeKey(key, QLatin1String("qipc_systemlock_")); - } - - void setErrorString(const QString &function); - -#ifdef Q_OS_WIN - HANDLE handle(); - bool lock(HANDLE, int count); - bool unlock(HANDLE, int count); -#else - key_t handle(); -#endif - void cleanHandle(); - - enum Operation { - Lock, - Unlock - }; - bool modifySemaphore(Operation op, QSystemLock::LockMode mode = QSystemLock::ReadOnly); - - QString key; - QString fileName; -#ifdef Q_OS_WIN - HANDLE semaphore; - HANDLE semaphoreLock; -#else - int semaphore; -#endif - int lockCount; - QSystemLock::LockMode lockedMode; - - QSystemLock::SystemLockError error; - QString errorString; - -private: -#ifndef Q_OS_WIN - key_t unix_key; - bool createdFile; - bool createdSemaphore; -#endif -}; - -#endif // QT_NO_SYSTEMLOCK - -#endif // QSYSTEMLOCK_P_H - diff --git a/tests/auto/qsharedmemory/src/qsystemlock_unix.cpp b/tests/auto/qsharedmemory/src/qsystemlock_unix.cpp deleted file mode 100644 index 525aa78..0000000 --- a/tests/auto/qsharedmemory/src/qsystemlock_unix.cpp +++ /dev/null @@ -1,233 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 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 "qsystemlock.h" -#include "qsystemlock_p.h" - -#include -#include - -#include -#include -#include -#include -#include -#include - -#include -// We have to define this as on some sem.h will have it -union qt_semun { - int val; /* value for SETVAL */ - struct semid_ds *buf; /* buffer for IPC_STAT, IPC_SET */ - unsigned short *array; /* array for GETALL, SETALL */ -}; - -#define tr(x) QT_TRANSLATE_NOOP(QLatin1String("QSystemLock"), (x)) - -#if defined(Q_OS_SYMBIAN) -int createUnixKeyFile(const QString &fileName) -{ - if (QFile::exists(fileName)) - return 0; - - int fd = open(QFile::encodeName(fileName).constData(), - O_EXCL | O_CREAT | O_RDWR, 0640); - if (-1 == fd) { - if (errno == EEXIST) - return 0; - return -1; - } else { - close(fd); - } - return 1; -} -#endif - -QSystemLockPrivate::QSystemLockPrivate() : - semaphore(-1), lockCount(0), - error(QSystemLock::NoError), unix_key(-1), createdFile(false), createdSemaphore(false) -{ -} - -void QSystemLockPrivate::setErrorString(const QString &function) -{ - switch (errno) { - case EIDRM: - errorString = function + QLatin1String(": ") + tr("The semaphore set was removed"); - error = QSystemLock::UnknownError; - break; - default: - errorString = function + QLatin1String(": ") + tr("unknown error"); - error = QSystemLock::UnknownError; - qWarning() << errorString << "key" << key << "errno" << errno << ERANGE << ENOMEM << EINVAL << EINTR << EFBIG << EFAULT << EAGAIN << EACCES << E2BIG; - } -} - -/*! - \internal - - Setup unix_key - */ -key_t QSystemLockPrivate::handle() -{ - if (key.isEmpty()) - return -1; - - // ftok requires that an actual file exists somewhere - // If we have already made at some point in the past, - // double check that it is still there. - if (-1 != unix_key) { - int aNewunix_key = ftok(QFile::encodeName(fileName).constData(), 'Q'); - if (aNewunix_key != unix_key) { - cleanHandle(); - } else { - return unix_key; - } - } - - // Create the file needed for ftok -#if defined(Q_OS_SYMBIAN) - int built = createUnixKeyFile(fileName); -#else - int built = QSharedMemoryPrivate::createUnixKeyFile(fileName); -#endif - if (-1 == built) - return -1; - createdFile = (1 == built); - - // Get the unix key for the created file - unix_key = ftok(QFile::encodeName(fileName).constData(), 'Q'); - if (-1 == unix_key) { - setErrorString(QLatin1String("QSystemLock::handle ftok")); - return -1; - } - - // Get semaphore - semaphore = semget(unix_key, 1, 0666 | IPC_CREAT | IPC_EXCL); - if (-1 == semaphore) { - if (errno == EEXIST) - semaphore = semget(unix_key, 1, 0666 | IPC_CREAT); - if (-1 == semaphore) { - setErrorString(QLatin1String("QSystemLock::handle semget")); - cleanHandle(); - return -1; - } - } else { - // Created semaphore, initialize value. - createdSemaphore = true; - qt_semun init_op; - init_op.val = MAX_LOCKS; - if (-1 == semctl(semaphore, 0, SETVAL, init_op)) { - setErrorString(QLatin1String("QSystemLock::handle semctl")); - cleanHandle(); - return -1; - } - } - - return unix_key; -} - -/*! - \internal - - Cleanup the unix_key - */ -void QSystemLockPrivate::cleanHandle() -{ - unix_key = -1; - - // remove the file if we made it - if (createdFile) { - if (!QFile::remove(fileName)) - setErrorString(QLatin1String("QSystemLock::cleanHandle QFile::remove")); - createdFile = false; - } - - if (createdSemaphore) { - if (-1 != semaphore) { - if (-1 == semctl(semaphore, 0, IPC_RMID)) { - setErrorString(QLatin1String("QSystemLock::cleanHandle semctl")); - } - semaphore = -1; - } - createdSemaphore = false; - } -} - -/*! - \internal - - modifySemaphore generates operation.sem_op and handles recursive behavior. - */ -bool QSystemLockPrivate::modifySemaphore(QSystemLockPrivate::Operation op, - QSystemLock::LockMode mode) -{ - if (-1 == handle()) - return false; - - if ((lockCount == 0 && op == Lock) || (lockCount > 0 && op == Unlock)) { - if (op == Unlock) { - --lockCount; - Q_ASSERT(lockCount >= 0); - if (lockCount > 0) - return true; - } - - struct sembuf operation; - operation.sem_num = 0; - operation.sem_op = (mode == QSystemLock::ReadWrite) ? MAX_LOCKS : 1; - if (op == Lock) - operation.sem_op *= -1; - operation.sem_flg = SEM_UNDO; - - if (-1 == semop(semaphore, &operation, 1)) { - setErrorString(QLatin1String("QSystemLock::modify")); - return false; - } - lockedMode = mode; - } - if (op == Lock) - lockCount++; - - return true; -} - diff --git a/tests/auto/qsharedmemory/src/qsystemlock_win.cpp b/tests/auto/qsharedmemory/src/qsystemlock_win.cpp deleted file mode 100644 index ac97100..0000000 --- a/tests/auto/qsharedmemory/src/qsystemlock_win.cpp +++ /dev/null @@ -1,182 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 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 "qsystemlock.h" -#include "qsystemlock_p.h" -#include -#include -QSystemLockPrivate::QSystemLockPrivate() : - semaphore(0), semaphoreLock(0), - lockCount(0), error(QSystemLock::NoError) -{ -} - -void QSystemLockPrivate::setErrorString(const QString &function) -{ - BOOL windowsError = GetLastError(); - if (windowsError == 0) - return; - errorString = function + QLatin1String(": ") - + QLatin1String("Unknown error"); - error = QSystemLock::UnknownError; - qWarning() << errorString << "key" << key << (int)windowsError << semaphore << semaphoreLock; -} - -/*! - \internal - - Setup the semaphore - */ -HANDLE QSystemLockPrivate::handle() -{ - // don't allow making handles on empty keys - if (key.isEmpty()) - return 0; - - // Create it if it doesn't already exists. - if (semaphore == 0) { - QString safeName = makeKeyFileName(); - semaphore = CreateSemaphore(0, MAX_LOCKS, MAX_LOCKS, (wchar_t*)safeName.utf16()); - - if (semaphore == 0) { - setErrorString(QLatin1String("QSystemLockPrivate::handle")); - return 0; - } - } - - if (semaphoreLock == 0) { - QString safeLockName = QSharedMemoryPrivate::makePlatformSafeKey(key + QLatin1String("lock"), QLatin1String("qipc_systemlock_")); - semaphoreLock = CreateSemaphore(0, 1, 1, (wchar_t*)safeLockName.utf16()); - - if (semaphoreLock == 0) { - setErrorString(QLatin1String("QSystemLockPrivate::handle")); - return 0; - } - } - - return semaphore; -} - -/*! - \internal - - Cleanup the semaphore - */ -void QSystemLockPrivate::cleanHandle() -{ - if (semaphore && !CloseHandle(semaphore)) - setErrorString(QLatin1String("QSystemLockPrivate::cleanHandle:")); - if (semaphoreLock && !CloseHandle(semaphoreLock)) - setErrorString(QLatin1String("QSystemLockPrivate::cleanHandle:")); - semaphore = 0; - semaphoreLock = 0; -} - -bool QSystemLockPrivate::lock(HANDLE handle, int count) -{ - if (count == 1) { - WaitForSingleObject(handle, INFINITE); - return true; - } - - int i = count; - while (i > 0) { - if (WAIT_OBJECT_0 == WaitForSingleObject(handle, 0)) { - --i; - } else { - // undo what we have done, sleep and then try again later - ReleaseSemaphore(handle, (count - i), 0); - i = count; - ReleaseSemaphore(semaphoreLock, 1, 0); - Sleep(1); - WaitForSingleObject(semaphoreLock, INFINITE); - } - } - return true; -} - -bool QSystemLockPrivate::unlock(HANDLE handle, int count) -{ - if (0 == ReleaseSemaphore(handle, count, 0)) { - setErrorString(QLatin1String("QSystemLockPrivate::unlock")); - return false; - } - return true; -} - -/*! - \internal - - modifySemaphore handles recursive behavior and modifies the semaphore. - */ -bool QSystemLockPrivate::modifySemaphore(QSystemLockPrivate::Operation op, - QSystemLock::LockMode mode) -{ - if (0 == handle()) - return false; - - if ((lockCount == 0 && op == Lock) || (lockCount > 0 && op == Unlock)) { - if (op == Unlock) { - --lockCount; - Q_ASSERT(lockCount >= 0); - if (lockCount > 0) - return true; - } - - int count = (mode == QSystemLock::ReadWrite) ? MAX_LOCKS : 1; - if (op == Lock) { - lock(semaphoreLock, 1); - lock(semaphore, count); - if (count != MAX_LOCKS) unlock(semaphoreLock, 1); - lockedMode = mode; - } else { - if (count == MAX_LOCKS) unlock(semaphoreLock, 1); - unlock(semaphore, count); - } - - } - if (op == Lock) - lockCount++; - - return true; -} - diff --git a/tests/auto/qsharedmemory/src/src.pri b/tests/auto/qsharedmemory/src/src.pri deleted file mode 100644 index 5bc9de6..0000000 --- a/tests/auto/qsharedmemory/src/src.pri +++ /dev/null @@ -1,10 +0,0 @@ -INCLUDEPATH += $$PWD -DEPENDPATH += $$PWD - -SOURCES += $$PWD/qsystemlock.cpp - -HEADERS += $$PWD/qsystemlock.h \ - $$PWD/qsystemlock_p.h - -unix:SOURCES += $$PWD/qsystemlock_unix.cpp -win32:SOURCES += $$PWD/qsystemlock_win.cpp diff --git a/tests/auto/qsharedmemory/test/test.pro b/tests/auto/qsharedmemory/test/test.pro deleted file mode 100644 index c9f4fec..0000000 --- a/tests/auto/qsharedmemory/test/test.pro +++ /dev/null @@ -1,37 +0,0 @@ -load(qttest_p4) - -include(../src/src.pri) -QT -= gui - -DEFINES += QSHAREDMEMORY_DEBUG -DEFINES += QSYSTEMSEMAPHORE_DEBUG - -SOURCES += ../tst_qsharedmemory.cpp -TARGET = ../tst_qsharedmemory - -!wince*:win32 { - CONFIG(debug, debug|release) { - TARGET = ../../debug/tst_qsharedmemory -} else { - TARGET = ../../release/tst_qsharedmemory - } -} - -wince*:{ -requires(contains(QT_CONFIG,script)) -QT += gui script -addFiles.sources = ../lackey/lackey.exe ../lackey/scripts -addFiles.path = lackey -DEPLOYMENT += addFiles -DEFINES += SRCDIR=\\\"\\\" -}else:symbian*{ -requires(contains(QT_CONFIG,script)) -QT += gui script -addFiles.sources = ../lackey/scripts -addFiles.path = /data/qsharedmemorytemp/lackey -addBin.sources = lackey.exe -addBin.path = /sys/bin -DEPLOYMENT += addFiles addBin -} else { -DEFINES += SRCDIR=\\\"$$PWD/../\\\" -} diff --git a/tests/auto/qsharedmemory/tst_qsharedmemory.cpp b/tests/auto/qsharedmemory/tst_qsharedmemory.cpp deleted file mode 100644 index cea75bf..0000000 --- a/tests/auto/qsharedmemory/tst_qsharedmemory.cpp +++ /dev/null @@ -1,778 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 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 - -//TESTED_CLASS= -//TESTED_FILES= - -#define EXISTING_SHARE "existing" -#define EXISTING_SIZE 1024 - -#ifdef Q_OS_SYMBIAN -#define SRCDIR "c:/data/qsharedmemorytemp/" -#endif -Q_DECLARE_METATYPE(QSharedMemory::SharedMemoryError) -Q_DECLARE_METATYPE(QSharedMemory::AccessMode) - -class tst_QSharedMemory : public QObject -{ - Q_OBJECT - -public: - tst_QSharedMemory(); - virtual ~tst_QSharedMemory(); - -public Q_SLOTS: - void init(); - void cleanup(); - -private slots: - // basics - void constructor(); - void key_data(); - void key(); - void create_data(); - void create(); - void attach_data(); - void attach(); - void lock(); - - // custom edge cases - void removeWhileAttached(); - void emptyMemory(); - void readOnly(); - - // basics all together - void simpleProducerConsumer_data(); - void simpleProducerConsumer(); - void simpleDoubleProducerConsumer(); - - // with threads - void simpleThreadedProducerConsumer_data(); - void simpleThreadedProducerConsumer(); - - // with processes - void simpleProcessProducerConsumer_data(); - void simpleProcessProducerConsumer(); - - // extreme cases - void useTooMuchMemory(); - void attachTooMuch(); - -protected: - int remove(const QString &key); - - QString rememberKey(const QString &key) - { - if (key == EXISTING_SHARE) - return key; - if (!keys.contains(key)) { - keys.append(key); - remove(key); - } - return key; - } - - QStringList keys; - QList jail; - QSharedMemory *existingSharedMemory; -}; - -tst_QSharedMemory::tst_QSharedMemory() : existingSharedMemory(0) -{ -} - -tst_QSharedMemory::~tst_QSharedMemory() -{ -} - -void tst_QSharedMemory::init() -{ - existingSharedMemory = new QSharedMemory(EXISTING_SHARE); - if (!existingSharedMemory->create(EXISTING_SIZE)) { - QVERIFY(existingSharedMemory->error() == QSharedMemory::AlreadyExists); - } -} - -void tst_QSharedMemory::cleanup() -{ - delete existingSharedMemory; - qDeleteAll(jail.begin(), jail.end()); - jail.clear(); - - keys.append(EXISTING_SHARE); - for (int i = 0; i < keys.count(); ++i) { - QSharedMemory sm(keys.at(i)); - if (!sm.create(1024)) { - //if(sm.error() != QSharedMemory::KeyError) - // qWarning() << "test cleanup: remove failed:" << keys.at(i) << sm.error() << sm.errorString(); - sm.attach(); - sm.detach(); - remove(keys.at(i)); - } - } -} - -#ifndef Q_OS_WIN -#include "private/qsharedmemory_p.h" -#include -#include -#include -#endif - -int tst_QSharedMemory::remove(const QString &key) -{ -#ifndef Q_OS_WIN - // On unix the shared memory might exists from a previously failed test - // or segfault, remove it it does - if (key.isEmpty()) - return -1; - - // ftok requires that an actual file exists somewhere - QString fileName = QSharedMemoryPrivate::makePlatformSafeKey(key); - if (!QFile::exists(fileName)) { - //qDebug() << "exits failed"; - return -2; - } - - int unix_key = ftok(fileName.toLatin1().constData(), 'Q'); - if (-1 == unix_key) { - qDebug() << "ftok failed"; - return -3; - } - - int id = shmget(unix_key, 0, 0660); - if (-1 == id) { - qDebug() << "shmget failed"; - return -4; - } - - struct shmid_ds shmid_ds; - if (-1 == shmctl(id, IPC_RMID, &shmid_ds)) { - qDebug() << "shmctl failed"; - return -5; - } - return QFile::remove(fileName); -#else - Q_UNUSED(key); - return 0; -#endif -} - -/*! - Tests the default values - */ -void tst_QSharedMemory::constructor() -{ - QSharedMemory sm; - QCOMPARE(sm.key(), QString()); - QVERIFY(!sm.isAttached()); - QVERIFY(sm.data() == 0); - QCOMPARE(sm.size(), 0); - QCOMPARE(sm.error(), QSharedMemory::NoError); - QVERIFY(sm.errorString() == QString()); -} - -void tst_QSharedMemory::key_data() -{ - QTest::addColumn("constructorKey"); - QTest::addColumn("setKey"); - - QTest::newRow("null, null") << QString() << QString(); - QTest::newRow("null, one") << QString() << QString("one"); - QTest::newRow("one, two") << QString("one") << QString("two"); - QTest::newRow("invalid") << QString("o/e") << QString("t/o"); -} - -/*! - Basic key testing - */ -void tst_QSharedMemory::key() -{ - QFETCH(QString, constructorKey); - QFETCH(QString, setKey); - - QSharedMemory sm(constructorKey); - QCOMPARE(sm.key(), constructorKey); - sm.setKey(setKey); - QCOMPARE(sm.key(), setKey); - QCOMPARE(sm.isAttached(), false); - - QCOMPARE(sm.error(), QSharedMemory::NoError); - QVERIFY(sm.errorString() == QString()); - QVERIFY(sm.data() == 0); - QCOMPARE(sm.size(), 0); - - QCOMPARE(sm.detach(), false); -} - -void tst_QSharedMemory::create_data() -{ - QTest::addColumn("key"); - QTest::addColumn("size"); - QTest::addColumn("canCreate"); - QTest::addColumn("error"); - - QTest::newRow("null key") << QString() << 1024 - << false << QSharedMemory::LockError; - QTest::newRow("-1 size") << QString("negsize") << -1 - << false << QSharedMemory::InvalidSize; - QTest::newRow("nor size") << QString("norsize") << 1024 - << true << QSharedMemory::NoError; - QTest::newRow("already exists") << QString(EXISTING_SHARE) << EXISTING_SIZE - << false << QSharedMemory::AlreadyExists; -} - -/*! - Basic create testing - */ -void tst_QSharedMemory::create() -{ - QFETCH(QString, key); - QFETCH(int, size); - QFETCH(bool, canCreate); - QFETCH(QSharedMemory::SharedMemoryError, error); - - QSharedMemory sm(rememberKey(key)); - QCOMPARE(sm.create(size), canCreate); - if(sm.error() != error) - qDebug() << sm.errorString(); - QCOMPARE(sm.key(), key); - if (canCreate) { - QVERIFY(sm.errorString() == QString()); - QVERIFY(sm.data() != 0); - QVERIFY(sm.size() != 0); - } else { - QVERIFY(sm.data() == 0); - QVERIFY(sm.errorString() != QString()); - } -} - -void tst_QSharedMemory::attach_data() -{ - QTest::addColumn("key"); - QTest::addColumn("exists"); - QTest::addColumn("error"); - - QTest::newRow("null key") << QString() << false << QSharedMemory::LockError; - QTest::newRow("doesn't exists") << QString("doesntexists") << false << QSharedMemory::NotFound; - QTest::newRow("already exists") << QString(EXISTING_SHARE) << true << QSharedMemory::NoError; -} - -/*! - Basic attach/detach testing - */ -void tst_QSharedMemory::attach() -{ - QFETCH(QString, key); - QFETCH(bool, exists); - QFETCH(QSharedMemory::SharedMemoryError, error); -#ifdef Q_OS_HPUX - if (QLatin1String(QTest::currentDataTag()) == QLatin1String("already exists")) { - QSKIP("HPUX doesn't allow for multiple attaches per process", SkipSingle); - } -#endif - QSharedMemory sm(key); - QCOMPARE(sm.attach(), exists); - QCOMPARE(sm.isAttached(), exists); - QCOMPARE(sm.error(), error); - QCOMPARE(sm.key(), key); - if (exists) { - QVERIFY(sm.data() != 0); - QVERIFY(sm.size() != 0); - QCOMPARE(sm.errorString(), QString()); - QVERIFY(sm.detach()); - // Make sure detach doesn't screw up something and we can't re-attach. - QVERIFY(sm.attach()); - QVERIFY(sm.detach()); - QCOMPARE(sm.size(), 0); - QVERIFY(sm.data() == 0); - } else { - QVERIFY(sm.data() == 0); - QVERIFY(sm.size() == 0); - QVERIFY(sm.errorString() != QString()); - QVERIFY(!sm.detach()); - } -} - -void tst_QSharedMemory::lock() -{ - QSharedMemory shm; - QVERIFY(!shm.lock()); - QCOMPARE(shm.error(), QSharedMemory::LockError); - - shm.setKey(QLatin1String("qsharedmemory")); - - QVERIFY(!shm.lock()); - QCOMPARE(shm.error(), QSharedMemory::LockError); - - QVERIFY(shm.create(100)); - QVERIFY(shm.lock()); - QTest::ignoreMessage(QtWarningMsg, "QSharedMemory::lock: already locked"); - QVERIFY(shm.lock()); - // don't lock forever -} - -/*! - Other shared memory are allowed to be attached after we remove, - but new shared memory are not allowed to attach after a remove. - */ -void tst_QSharedMemory::removeWhileAttached() -{ -#ifdef Q_OS_HPUX - QSKIP("HPUX doesn't allow for multiple attaches per process", SkipAll); -#endif - rememberKey("one"); - - // attach 1 - QSharedMemory *smOne = new QSharedMemory(QLatin1String("one")); - QVERIFY(smOne->create(1024)); - QVERIFY(smOne->isAttached()); - - // attach 2 - QSharedMemory *smTwo = new QSharedMemory(QLatin1String("one")); - QVERIFY(smTwo->attach()); - QVERIFY(smTwo->isAttached()); - - // detach 1 and remove, remove one first to catch another error. - delete smOne; - delete smTwo; - - // three shouldn't be able to attach - QSharedMemory smThree(QLatin1String("one")); - QVERIFY(!smThree.attach()); - QCOMPARE(smThree.error(), QSharedMemory::NotFound); -} - -/*! - The memory should be set to 0 after created. - */ -void tst_QSharedMemory::emptyMemory() -{ - QSharedMemory sm(rememberKey(QLatin1String("voidland"))); - int size = 1024; - QVERIFY(sm.create(size, QSharedMemory::ReadOnly)); - char *get = (char*)sm.data(); - char null = 0; - for (int i = 0; i < size; ++i) - QCOMPARE(get[i], null); -} - -/*! - Verify that attach with ReadOnly is actually read only - by writing to data and causing a segfault. -*/ -void tst_QSharedMemory::readOnly() -{ -#ifdef Q_OS_WIN - QSKIP("This test opens a crash dialog on Windows", SkipSingle); -#endif -#if defined (Q_OS_SYMBIAN) - QSKIP("Readonly shared memory is not supported in symbian", SkipAll); -#endif - QString program = "./lackey/lackey"; - QStringList arguments; - rememberKey("readonly_segfault"); - arguments << SRCDIR "lackey/scripts/readonly_segfault.js"; - - // ### on windows disable the popup somehow - QProcess p; - p.start(program, arguments); - p.setProcessChannelMode(QProcess::ForwardedChannels); - p.waitForFinished(); - QCOMPARE(p.error(), QProcess::Crashed); -} - -/*! - Keep making shared memory until the kernel stops us. - */ -void tst_QSharedMemory::useTooMuchMemory() -{ -#ifdef Q_OS_LINUX - bool success = true; - int count = 0; - while (success) { - QString key = QString("maxmemorytest_%1").arg(count++); - QSharedMemory *sm = new QSharedMemory(rememberKey(key)); - QVERIFY(sm); - jail.append(sm); - int size = 32768 * 1024; - success = sm->create(size); - if (!success && sm->error() == QSharedMemory::AlreadyExists) { - // left over from a crash, clean it up - sm->attach(); - sm->detach(); - success = sm->create(size); - } - - if (!success) { - QVERIFY(!sm->isAttached()); - QCOMPARE(sm->key(), key); - QCOMPARE(sm->size(), 0); - QVERIFY(sm->data() == 0); - if (sm->error() != QSharedMemory::OutOfResources) - qDebug() << sm->error() << sm->errorString(); - // ### Linux wont return OutOfResources if there are not enough semaphores to use. - QVERIFY(sm->error() == QSharedMemory::OutOfResources - || sm->error() == QSharedMemory::LockError); - QVERIFY(sm->errorString() != QString()); - QVERIFY(!sm->attach()); - QVERIFY(!sm->detach()); - } else { - QVERIFY(sm->isAttached()); - } - } -#endif -} - -/*! - Create one shared memory (government) and see how many other shared memories (wars) we can - attach before the system runs out of resources. - */ -void tst_QSharedMemory::attachTooMuch() -{ - QSKIP("disabled", SkipAll); -#ifdef Q_OS_HPUX - QSKIP("HPUX doesn't allow for multiple attaches per process", SkipAll); -#endif -#ifdef Q_OS_WINCE - QSKIP("This nearly kills the system itself, so skip for Qt/WinCE", SkipAll); -#endif - QSharedMemory government(rememberKey("government")); - QVERIFY(government.create(1024)); - while (true) { - QSharedMemory *war = new QSharedMemory(government.key()); - QVERIFY(war); - jail.append(war); - if (!war->attach()) { - QVERIFY(!war->isAttached()); - QCOMPARE(war->key(), government.key()); - QCOMPARE(war->size(), 0); - QVERIFY(war->data() == 0); - QCOMPARE(war->error(), QSharedMemory::OutOfResources); - QVERIFY(war->errorString() != QString()); - QVERIFY(!war->detach()); - break; - } else { - QVERIFY(war->isAttached()); - } - } -} - -void tst_QSharedMemory::simpleProducerConsumer_data() -{ - QTest::addColumn("mode"); - - QTest::newRow("readonly") << QSharedMemory::ReadOnly; - QTest::newRow("readwrite") << QSharedMemory::ReadWrite; -} - -/*! - The basic consumer producer that rounds out the basic testing. - If this fails then any muli-threading/process might fail (but be - harder to debug) - - This doesn't require nor test any locking system. - */ -void tst_QSharedMemory::simpleProducerConsumer() -{ -#ifdef Q_OS_HPUX - QSKIP("HPUX doesn't allow for multiple attaches per process", SkipAll); -#endif - QFETCH(QSharedMemory::AccessMode, mode); - - rememberKey(QLatin1String("market")); - QSharedMemory producer(QLatin1String("market")); - QSharedMemory consumer(QLatin1String("market")); - int size = 512; - QVERIFY(producer.create(size)); - QVERIFY(consumer.attach(mode)); - - char *put = (char*)producer.data(); - char *get = (char*)consumer.data(); - // On Windows CE you always have ReadWrite access. Thus - // ViewMapOfFile returns the same pointer - // On Symbian, the address will always be same, as - // write protection of chunks is not currently supported by Symbian -#if !defined(Q_OS_WINCE) && !defined(Q_OS_SYMBIAN) - QVERIFY(put != get); -#endif - for (int i = 0; i < size; ++i) { - put[i] = 'Q'; - QCOMPARE(get[i], 'Q'); - } - QVERIFY(consumer.detach()); -} - -void tst_QSharedMemory::simpleDoubleProducerConsumer() -{ -#ifdef Q_OS_HPUX - QSKIP("HPUX doesn't allow for multiple attaches per process", SkipAll); -#endif - rememberKey(QLatin1String("market")); - QSharedMemory producer(QLatin1String("market")); - int size = 512; - QVERIFY(producer.create(size)); - QVERIFY(producer.detach()); - QVERIFY(producer.create(size)); - - { - QSharedMemory consumer(QLatin1String("market")); - QVERIFY(consumer.attach()); - } -} - -class Consumer : public QThread -{ - -public: - void run() - { - QSharedMemory consumer(QLatin1String("market")); - while (!consumer.attach()) { - if (consumer.error() != QSharedMemory::NotFound) - qDebug() << "consumer: failed to connect" << consumer.error() << consumer.errorString(); - QVERIFY(consumer.error() == QSharedMemory::NotFound || consumer.error() == QSharedMemory::KeyError); - QTest::qWait(1); - } - - char *memory = (char*)consumer.data(); - - int i = 0; - while (true) { - if(!consumer.lock()) - break; - if (memory[0] == 'Q') - memory[0] = ++i; - if (memory[0] == 'E') { - memory[1]++; - QVERIFY(consumer.unlock()); - break; - } - QVERIFY(consumer.unlock()); - QTest::qWait(1); - } - - QVERIFY(consumer.detach()); - } -}; - -class Producer : public QThread -{ - -public: - void run() - { - QSharedMemory producer(QLatin1String("market")); - int size = 1024; - if (!producer.create(size)) { - // left over from a crash... - if (producer.error() == QSharedMemory::AlreadyExists) { - producer.attach(); - producer.detach(); - QVERIFY(producer.create(size)); - } - } - QVERIFY(producer.isAttached()); - char *memory = (char*)producer.data(); - memory[1] = '0'; - QTime timer; - timer.start(); - int i = 0; - while (i < 5 && timer.elapsed() < 5000) { - QVERIFY(producer.lock()); - if (memory[0] == 'Q') { - QVERIFY(producer.unlock()); - QTest::qWait(1); - continue; - } - ++i; - memory[0] = 'Q'; - QVERIFY(producer.unlock()); - QTest::qWait(1); - } - - // tell everyone to quit - QVERIFY(producer.lock()); - memory[0] = 'E'; - QVERIFY(producer.unlock()); - -#if defined(Q_OS_SYMBIAN) - // Sleep a while to ensure that consumers start properly - QTest::qSleep(1000); -#endif - } -private: - -}; - -void tst_QSharedMemory::simpleThreadedProducerConsumer_data() -{ - QTest::addColumn("producerIsThread"); - QTest::addColumn("threads"); - for (int i = 0; i < 5; ++i) { - QTest::newRow("1 consumer, producer is thread") << true << 1; - QTest::newRow("1 consumer, producer is this") << false << 1; - QTest::newRow("5 consumers, producer is thread") << true << 5; - QTest::newRow("5 consumers, producer is this") << false << 5; - } -} - -/*! - The basic producer/consumer, but this time using threads. - */ -void tst_QSharedMemory::simpleThreadedProducerConsumer() -{ - QFETCH(bool, producerIsThread); - QFETCH(int, threads); - rememberKey(QLatin1String("market")); - -#if defined Q_OS_HPUX && defined __ia64 - QSKIP("This test locks up on gravlaks.troll.no", SkipSingle); -#endif - - Producer p; -#if defined(Q_OS_SYMBIAN) - enum - { - /** - * The maximum stack size. - */ - SymbianStackSize = 0x14000 - }; - p.setStackSize(SymbianStackSize); -#endif - if (producerIsThread) - p.start(); - - QList consumers; - for (int i = 0; i < threads; ++i) { - consumers.append(new Consumer()); -#if defined(Q_OS_SYMBIAN) - consumers.last()->setStackSize(SymbianStackSize); -#endif - consumers.last()->start(); - } - - if (!producerIsThread) - p.run(); - - p.wait(5000); - while (!consumers.isEmpty()) { - QVERIFY(consumers.first()->wait(5000)); - delete consumers.takeFirst(); - } -} - -void tst_QSharedMemory::simpleProcessProducerConsumer_data() -{ - QTest::addColumn("processes"); - int tries = 5; - for (int i = 0; i < tries; ++i) { - QTest::newRow("1 process") << 1; - QTest::newRow("5 processes") << 5; - } -} - -/*! - Create external processes that produce and consume. - */ -void tst_QSharedMemory::simpleProcessProducerConsumer() -{ -#if defined (Q_OS_SYMBIAN) && defined(Q_CC_NOKIAX86) - QSKIP("Cannot launch multiple Qt processes in Symbian emulator", SkipAll); -#endif - QFETCH(int, processes); - - rememberKey("market"); - -#ifndef Q_OS_WINCE - QStringList arguments = QStringList() << SRCDIR "lackey/scripts/producer.js"; -#else - QStringList arguments = QStringList() << QFileInfo(SRCDIR "lackey/scripts/producer.js").absoluteFilePath(); -#endif - QProcess producer; - producer.setProcessChannelMode(QProcess::ForwardedChannels); - producer.start( "./lackey/lackey", arguments); - producer.waitForStarted(); - QVERIFY(producer.error() != QProcess::FailedToStart); - - QList consumers; - unsigned int failedProcesses = 0; - for (int i = 0; i < processes; ++i) { -#ifndef Q_OS_WINCE - QStringList arguments = QStringList() << SRCDIR "lackey/scripts/consumer.js"; -#else - QStringList arguments = QStringList() << QFileInfo(SRCDIR "lackey/scripts/consumer.js").absoluteFilePath(); -#endif - QProcess *p = new QProcess; - p->setProcessChannelMode(QProcess::ForwardedChannels); - p->start("./lackey/lackey", arguments); - - if (p->waitForStarted(2000)) - consumers.append(p); - else - ++failedProcesses; - } - - QVERIFY(producer.waitForFinished(5000)); - - bool consumerFailed = false; - - while (!consumers.isEmpty()) { - QVERIFY(consumers.first()->waitForFinished(3000)); - if (consumers.first()->state() == QProcess::Running || - consumers.first()->exitStatus() != QProcess::NormalExit || - consumers.first()->exitCode() != 0) { - consumerFailed = true; - } - delete consumers.takeFirst(); - } - QCOMPARE(consumerFailed, false); - QCOMPARE(failedProcesses, (unsigned int)(0)); -} - -QTEST_MAIN(tst_QSharedMemory) -#include "tst_qsharedmemory.moc" - diff --git a/tests/auto/qsystemsemaphore/.gitignore b/tests/auto/qsystemsemaphore/.gitignore deleted file mode 100644 index 2b60bfb..0000000 --- a/tests/auto/qsystemsemaphore/.gitignore +++ /dev/null @@ -1 +0,0 @@ -tst_qsystemsemaphore diff --git a/tests/auto/qsystemsemaphore/files.qrc b/tests/auto/qsystemsemaphore/files.qrc deleted file mode 100644 index 7b344ba..0000000 --- a/tests/auto/qsystemsemaphore/files.qrc +++ /dev/null @@ -1,7 +0,0 @@ - - - ../qsharedmemory/lackey/scripts/systemsemaphore_acquire.js - ../qsharedmemory/lackey/scripts/systemsemaphore_release.js - ../qsharedmemory/lackey/scripts/systemsemaphore_acquirerelease.js - - diff --git a/tests/auto/qsystemsemaphore/qsystemsemaphore.pro b/tests/auto/qsystemsemaphore/qsystemsemaphore.pro deleted file mode 100644 index a3f4a34..0000000 --- a/tests/auto/qsystemsemaphore/qsystemsemaphore.pro +++ /dev/null @@ -1,4 +0,0 @@ -TEMPLATE = subdirs -SUBDIRS = ../qsharedmemory/lackey test - - diff --git a/tests/auto/qsystemsemaphore/test/test.pro b/tests/auto/qsystemsemaphore/test/test.pro deleted file mode 100644 index ed7898c..0000000 --- a/tests/auto/qsystemsemaphore/test/test.pro +++ /dev/null @@ -1,40 +0,0 @@ -CONFIG += qttest_p4 -#QT = core - -include(../../qsharedmemory/src/src.pri) -win32: CONFIG += console - -DEFINES += QSHAREDMEMORY_DEBUG -DEFINES += QSYSTEMSEMAPHORE_DEBUG - -SOURCES += ../tst_qsystemsemaphore.cpp -TARGET = tst_qsystemsemaphore -DESTDIR = ../ -win32 { - CONFIG(debug, debug|release): DESTDIR = ../debug - else: DESTDIR = ../release -} - -RESOURCES += ../files.qrc - -wince*: { -requires(contains(QT_CONFIG,script)) -# this test calls lackey, which then again depends on QtScript. -# let's add it here so that it gets deployed easily -QT += script -lackey.sources = ../../qsharedmemory/lackey/lackey.exe -lackey.path = ../qsharedmemory/lackey - -DEPLOYMENT += lackey -} - -symbian: { -requires(contains(QT_CONFIG,script)) -# this test calls lackey, which then again depends on QtScript. -# let's add it here so that it gets deployed easily -QT += script - -lackey.sources = ../../qsharedmemory/lackey/lackey.exe -lackey.path = /sys/bin -DEPLOYMENT += lackey -} diff --git a/tests/auto/qsystemsemaphore/tst_qsystemsemaphore.cpp b/tests/auto/qsystemsemaphore/tst_qsystemsemaphore.cpp deleted file mode 100644 index bf4efdc..0000000 --- a/tests/auto/qsystemsemaphore/tst_qsystemsemaphore.cpp +++ /dev/null @@ -1,302 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 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 -//TESTED_CLASS= -//TESTED_FILES= - -#define EXISTING_SHARE "existing" -#define LACKYLOC "../qsharedmemory/lackey" -#define LACKYWAITTIME 10000 - -class tst_QSystemSemaphore : public QObject -{ - Q_OBJECT - -public: - tst_QSystemSemaphore(); - virtual ~tst_QSystemSemaphore(); - -public Q_SLOTS: - void init(); - void cleanup(); - -private slots: - void key_data(); - void key(); - - void basicacquire(); - void complexacquire(); - - void basicProcesses(); - - void processes_data(); - void processes(); - - void undo(); - void initialValue(); - -private: - QSystemSemaphore *existingLock; - - QString makeFile(const QString &resource) - { - QFile memory(resource); - if (!memory.open(QIODevice::ReadOnly)) { - qDebug() << "error reading resource" << resource; - return QString(); - } - QTemporaryFile *file = new QTemporaryFile; - file->open(); - file->write(memory.readAll()); - tempFiles.append(file); - file->flush(); -#ifdef Q_OS_WINCE - // flush does not flush to disk on Windows CE. It flushes it into its application - // cache. Thus we need to close the file to be able that other processes(lackey) can read it - QString fileName = file->fileName(); - file->close(); - return fileName; -#endif - return file->fileName(); - } - - QString acquire_js() { return makeFile(":/systemsemaphore_acquire.js"); } - QString release_js() { return makeFile(":/systemsemaphore_release.js"); } - QString acquirerelease_js() { return makeFile(":/systemsemaphore_acquirerelease.js"); } - QList tempFiles; -}; - -tst_QSystemSemaphore::tst_QSystemSemaphore() -{ - if (!QFile::exists(LACKYLOC "/lackey")) - qWarning() << "lackey executable doesn't exists!"; -} - -tst_QSystemSemaphore::~tst_QSystemSemaphore() -{ - qDeleteAll(tempFiles); -} - -void tst_QSystemSemaphore::init() -{ - existingLock = new QSystemSemaphore(EXISTING_SHARE, 1, QSystemSemaphore::Create); -} - -void tst_QSystemSemaphore::cleanup() -{ - delete existingLock; -} - -void tst_QSystemSemaphore::key_data() -{ - QTest::addColumn("constructorKey"); - QTest::addColumn("setKey"); - - QTest::newRow("null, null") << QString() << QString(); - QTest::newRow("null, one") << QString() << QString("one"); - QTest::newRow("one, two") << QString("one") << QString("two"); -} - -/*! - Basic key testing - */ -void tst_QSystemSemaphore::key() -{ - QFETCH(QString, constructorKey); - QFETCH(QString, setKey); - - QSystemSemaphore sem(constructorKey); - QCOMPARE(sem.key(), constructorKey); - QCOMPARE(sem.error(), QSystemSemaphore::NoError); - QCOMPARE(sem.errorString(), QString()); - - sem.setKey(setKey); - QCOMPARE(sem.key(), setKey); - QCOMPARE(sem.error(), QSystemSemaphore::NoError); - QCOMPARE(sem.errorString(), QString()); -} - -void tst_QSystemSemaphore::basicacquire() -{ - QSystemSemaphore sem("QSystemSemaphore_basicacquire", 1, QSystemSemaphore::Create); - QVERIFY(sem.acquire()); - QCOMPARE(sem.error(), QSystemSemaphore::NoError); - QVERIFY(sem.release()); - QCOMPARE(sem.error(), QSystemSemaphore::NoError); - QCOMPARE(sem.errorString(), QString()); -} - -void tst_QSystemSemaphore::complexacquire() -{ - QSystemSemaphore sem("QSystemSemaphore_complexacquire", 2, QSystemSemaphore::Create); - QVERIFY(sem.acquire()); - QVERIFY(sem.release()); - QVERIFY(sem.acquire()); - QVERIFY(sem.release()); - QVERIFY(sem.acquire()); - QVERIFY(sem.acquire()); - QVERIFY(sem.release()); - QVERIFY(sem.release()); - QCOMPARE(sem.error(), QSystemSemaphore::NoError); - QCOMPARE(sem.errorString(), QString()); -} - -void tst_QSystemSemaphore::basicProcesses() -{ -#if defined (Q_OS_SYMBIAN) && defined(Q_CC_NOKIAX86) - QSKIP("Cannot launch multiple Qt processes in Symbian emulator", SkipAll); -#endif - QSystemSemaphore sem("store", 0, QSystemSemaphore::Create); - - QStringList acquireArguments = QStringList() << acquire_js(); - QStringList releaseArguments = QStringList() << release_js(); - QProcess acquire; - acquire.setProcessChannelMode(QProcess::ForwardedChannels); - - QProcess release; - release.setProcessChannelMode(QProcess::ForwardedChannels); - - acquire.start(LACKYLOC "/lackey", acquireArguments); - acquire.waitForFinished(LACKYWAITTIME); - QVERIFY(acquire.state() == QProcess::Running); - acquire.kill(); - release.start(LACKYLOC "/lackey", releaseArguments); - acquire.waitForFinished(LACKYWAITTIME); - release.waitForFinished(LACKYWAITTIME); - QVERIFY(acquire.state() == QProcess::NotRunning); -} - -void tst_QSystemSemaphore::processes_data() -{ - QTest::addColumn("processes"); - for (int i = 0; i < 5; ++i) { - QTest::newRow("1 process") << 1; - QTest::newRow("3 process") << 3; - QTest::newRow("10 process") << 10; - } -} - -void tst_QSystemSemaphore::processes() -{ -#if defined (Q_OS_SYMBIAN) && defined(Q_CC_NOKIAX86) - QSKIP("Cannot launch multiple Qt processes in Symbian emulator", SkipAll); -#endif - QSystemSemaphore sem("store", 1, QSystemSemaphore::Create); - - QFETCH(int, processes); - QStringList scripts; - for (int i = 0; i < processes; ++i) - scripts.append(acquirerelease_js()); - - QList consumers; - for (int i = 0; i < scripts.count(); ++i) { - QStringList arguments = QStringList() << scripts.at(i); - QProcess *p = new QProcess; - p->setProcessChannelMode(QProcess::ForwardedChannels); - consumers.append(p); - p->start(LACKYLOC "/lackey", arguments); - } - - while (!consumers.isEmpty()) { - consumers.first()->waitForFinished(); - QCOMPARE(consumers.first()->exitStatus(), QProcess::NormalExit); - QCOMPARE(consumers.first()->exitCode(), 0); - delete consumers.takeFirst(); - } -} - -void tst_QSystemSemaphore::undo() -{ -#if defined(Q_OS_WIN) || defined(Q_OS_SYMBIAN) - QSKIP("This test only checks a unix behavior", SkipSingle); -#endif - - QSystemSemaphore sem("store", 1, QSystemSemaphore::Create); - - QStringList acquireArguments = QStringList() << acquire_js(); - QProcess acquire; - acquire.setProcessChannelMode(QProcess::ForwardedChannels); - acquire.start(LACKYLOC "/lackey", acquireArguments); - acquire.waitForFinished(LACKYWAITTIME); - QVERIFY(acquire.state()== QProcess::NotRunning); - - // At process exit the kernel should auto undo - - acquire.start(LACKYLOC "/lackey", acquireArguments); - acquire.waitForFinished(LACKYWAITTIME); - QVERIFY(acquire.state()== QProcess::NotRunning); -} - -void tst_QSystemSemaphore::initialValue() -{ -#if defined (Q_OS_SYMBIAN) && defined(Q_CC_NOKIAX86) - QSKIP("Cannot launch multiple Qt processes in Symbian emulator", SkipAll); -#endif - QSystemSemaphore sem("store", 1, QSystemSemaphore::Create); - - QStringList acquireArguments = QStringList() << acquire_js(); - QStringList releaseArguments = QStringList() << release_js(); - QProcess acquire; - acquire.setProcessChannelMode(QProcess::ForwardedChannels); - - QProcess release; - release.setProcessChannelMode(QProcess::ForwardedChannels); - - acquire.start(LACKYLOC "/lackey", acquireArguments); - acquire.waitForFinished(LACKYWAITTIME); - QVERIFY(acquire.state()== QProcess::NotRunning); - - acquire.start(LACKYLOC "/lackey", acquireArguments << "2"); - acquire.waitForFinished(LACKYWAITTIME); - QVERIFY(acquire.state()== QProcess::Running); - acquire.kill(); - - release.start(LACKYLOC "/lackey", releaseArguments); - acquire.waitForFinished(LACKYWAITTIME); - release.waitForFinished(LACKYWAITTIME); - QVERIFY(acquire.state()== QProcess::NotRunning); -} -QTEST_MAIN(tst_QSystemSemaphore) -#include "tst_qsystemsemaphore.moc" - diff --git a/tests/auto/qtipc/lackey/lackey.pro b/tests/auto/qtipc/lackey/lackey.pro new file mode 100644 index 0000000..3912312 --- /dev/null +++ b/tests/auto/qtipc/lackey/lackey.pro @@ -0,0 +1,20 @@ +include(../qsharedmemory/src/src.pri) + +QT = core script + +CONFIG += qtestlib + +DESTDIR = ./ + +win32: CONFIG += console +mac:CONFIG -= app_bundle + +requires(contains(QT_CONFIG,script)) + +DEFINES += QSHAREDMEMORY_DEBUG +DEFINES += QSYSTEMSEMAPHORE_DEBUG + +SOURCES += main.cpp +TARGET = lackey + + diff --git a/tests/auto/qtipc/lackey/main.cpp b/tests/auto/qtipc/lackey/main.cpp new file mode 100644 index 0000000..fef8d22 --- /dev/null +++ b/tests/auto/qtipc/lackey/main.cpp @@ -0,0 +1,370 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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 +#include + +#include +#include +#include +#include +#include + +class ScriptSystemSemaphore : public QObject +{ + Q_OBJECT + +public: + ScriptSystemSemaphore(QObject *parent = 0) : QObject(parent), ss(QString()) + { + } + +public slots: + bool acquire() + { + return ss.acquire(); + }; + + bool release(int n = 1) + { + return ss.release(n); + }; + + void setKey(const QString &key, int n = 0) + { + ss.setKey(key, n); + }; + + QString key() const + { + return ss.key(); + } + +private: + QSystemSemaphore ss; +}; + +class ScriptSystemLock : public QObject +{ + Q_OBJECT + Q_PROPERTY(QString key WRITE setKey READ key) + +public: + ScriptSystemLock(QObject *parent = 0) : QObject(parent), sl(QString()) + { + } + +public slots: + + bool lockReadOnly() + { + return sl.lock(QSystemLock::ReadOnly); + } + + bool lock() + { + return sl.lock(); + }; + + bool unlock() + { + return sl.unlock(); + }; + + void setKey(const QString &key) + { + sl.setKey(key); + }; + + QString key() const + { + return sl.key(); + } + +private: + QSystemLock sl; +}; + +class ScriptSharedMemory : public QObject +{ + Q_OBJECT + Q_PROPERTY(bool attached READ isAttached) + Q_PROPERTY(QString key WRITE setKey READ key) + +public: + enum SharedMemoryError + { + NoError = 0, + PermissionDenied = 1, + InvalidSize = 2, + KeyError = 3, + AlreadyExists = 4, + NotFound = 5, + LockError = 6, + OutOfResources = 7, + UnknownError = 8 + }; + + ScriptSharedMemory(QObject *parent = 0) : QObject(parent) + { + } + +public slots: + void sleep(int x) const + { + QTest::qSleep(x); + } + + bool create(int size) + { + return sm.create(size); + }; + + bool createReadOnly(int size) + { + return sm.create(size, QSharedMemory::ReadOnly); + }; + + int size() const + { + return sm.size(); + }; + + bool attach() + { + return sm.attach(); + }; + + bool attachReadOnly() + { + return sm.attach(QSharedMemory::ReadOnly); + }; + + bool isAttached() const + { + return sm.isAttached(); + }; + + bool detach() + { + return sm.detach(); + }; + + int error() const + { + return (int)sm.error(); + }; + + QString errorString() const + { + return sm.errorString(); + }; + + void set(int i, QChar value) + { + ((char*)sm.data())[i] = value.toLatin1(); + } + + QString get(int i) + { + return QChar::fromLatin1(((char*)sm.data())[i]); + } + + char *data() const + { + return (char*)sm.data(); + }; + + void setKey(const QString &key) + { + sm.setKey(key); + }; + + QString key() const + { + return sm.key(); + } + + bool lock() + { + return sm.lock(); + } + + bool unlock() + { + return sm.unlock(); + } + +private: + QSharedMemory sm; +}; + +QT_BEGIN_NAMESPACE +Q_SCRIPT_DECLARE_QMETAOBJECT(ScriptSharedMemory, QObject*); +Q_SCRIPT_DECLARE_QMETAOBJECT(ScriptSystemLock, QObject*); +Q_SCRIPT_DECLARE_QMETAOBJECT(ScriptSystemSemaphore, QObject*); +QT_END_NAMESPACE + +static void interactive(QScriptEngine &eng) +{ +#ifdef Q_OS_WINCE + fprintf(stderr, "Interactive mode not supported on Windows CE\n"); + return; +#endif + QTextStream qin(stdin, QFile::ReadOnly); + + const char *qscript_prompt = "qs> "; + const char *dot_prompt = ".... "; + const char *prompt = qscript_prompt; + + QString code; + + forever { + QString line; + + printf("%s", prompt); + fflush(stdout); + + line = qin.readLine(); + if (line.isNull()) + break; + + code += line; + code += QLatin1Char('\n'); + + if (line.trimmed().isEmpty()) { + continue; + + } else if (! eng.canEvaluate(code)) { + prompt = dot_prompt; + + } else { + QScriptValue result = eng.evaluate(code); + code.clear(); + prompt = qscript_prompt; + if (!result.isUndefined()) + fprintf(stderr, "%s\n", qPrintable(result.toString())); + } + } +} + +int main(int argc, char *argv[]) +{ + QCoreApplication app(argc, argv); + + QScriptEngine eng; + QScriptValue globalObject = eng.globalObject(); + + QScriptValue sm = qScriptValueFromQMetaObject(&eng); + eng.globalObject().setProperty("ScriptSharedMemory", sm); + + QScriptValue sl = qScriptValueFromQMetaObject(&eng); + eng.globalObject().setProperty("ScriptSystemLock", sl); + + QScriptValue ss = qScriptValueFromQMetaObject(&eng); + eng.globalObject().setProperty("ScriptSystemSemaphore", ss); + + + if (! *++argv) { + interactive(eng); + return EXIT_SUCCESS; + } + + QStringList arguments = app.arguments(); + arguments.takeFirst(); + + while (!arguments.isEmpty()) { + QString fn = arguments.takeFirst(); + + if (fn == QLatin1String("-i")) { + interactive(eng); + break; + } + + QString contents; + + if (fn == QLatin1String("-")) { + QTextStream stream(stdin, QFile::ReadOnly); + contents = stream.readAll(); + } else { + QFile file(fn); + if (!file.exists()) { + fprintf(stderr, "%s doesn't exists\n", qPrintable(fn)); + return EXIT_FAILURE; + } + if (file.open(QFile::ReadOnly)) { + QTextStream stream(&file); + contents = stream.readAll(); + file.close(); + } + } + + if (contents.isEmpty()) + continue; + + if (contents[0] == '#') { + contents.prepend("//"); + QScriptValue args = eng.newArray(); + args.setProperty("0", QScriptValue(&eng, fn)); + int i = 1; + while (!arguments.isEmpty()) + args.setProperty(i++, QScriptValue(&eng, arguments.takeFirst())); + eng.currentContext()->activationObject().setProperty("args", args); + } + QScriptValue r = eng.evaluate(contents); + if (eng.hasUncaughtException()) { + int line = eng.uncaughtExceptionLineNumber(); + fprintf(stderr, "%d: %s\n\t%s\n\n", line, qPrintable(fn), qPrintable(r.toString())); + return EXIT_FAILURE; + } + if (r.isNumber()) + return r.toInt32(); + } + + return EXIT_SUCCESS; +} + +#include "main.moc" diff --git a/tests/auto/qtipc/lackey/scripts/consumer.js b/tests/auto/qtipc/lackey/scripts/consumer.js new file mode 100644 index 0000000..4d12dca --- /dev/null +++ b/tests/auto/qtipc/lackey/scripts/consumer.js @@ -0,0 +1,41 @@ +function QVERIFY(x, debugInfo) { + if (!(x)) { + print(debugInfo); + throw(debugInfo); + } +} + +var consumer = new ScriptSharedMemory; +consumer.setKey("market"); + +//print("consumer starting"); +var tries = 0;; +while(!consumer.attach()) { + if (tries == 5000) { + var message = "consumer exiting, waiting too long"; + print(message); + throw(message); + } + ++tries; + consumer.sleep(1); +} +//print("consumer attached"); + + +var i = 0; +while(true) { + QVERIFY(consumer.lock(), "lock"); + if (consumer.get(0) == 'Q') { + consumer.set(0, ++i); + //print ("consumer sets" + i); + } + if (consumer.get(0) == 'E') { + QVERIFY(consumer.unlock(), "unlock"); + break; + } + QVERIFY(consumer.unlock(), "unlock"); + consumer.sleep(10); +} + +//print("consumer detaching"); +QVERIFY(consumer.detach()); diff --git a/tests/auto/qtipc/lackey/scripts/producer.js b/tests/auto/qtipc/lackey/scripts/producer.js new file mode 100644 index 0000000..e02cd8b --- /dev/null +++ b/tests/auto/qtipc/lackey/scripts/producer.js @@ -0,0 +1,44 @@ +function QVERIFY(x, debugInfo) { + if (!(x)) { + print(debugInfo); + throw(debugInfo); + } +} + +var producer = new ScriptSharedMemory; +producer.setKey("market"); + +var size = 1024; +if (!producer.create(size)) { + QVERIFY(producer.error() == 4, "create"); + QVERIFY(producer.attach()); +} +//print ("producer created and attached"); + +QVERIFY(producer.lock()); +producer.set(0, 'Q'); +QVERIFY(producer.unlock()); + +var i = 0; +while(i < 5) { + QVERIFY(producer.lock(), "lock"); + if (producer.get(0) == 'Q') { + QVERIFY(producer.unlock(), "unlock"); + producer.sleep(1); + continue; + } + //print("producer: " + i); + ++i; + producer.set(0, 'Q'); + QVERIFY(producer.unlock(), "unlock"); + producer.sleep(1); +} +QVERIFY(producer.lock()); +producer.set(0, 'E'); +QVERIFY(producer.unlock()); + +//print ("producer done"); + +// Sleep for a bit to let all consumers start, otherwise they will get stuck in the attach loop, +// because at least in Symbian the shared memory will be destroyed if there are no active handles to it. +producer.sleep(3000); \ No newline at end of file diff --git a/tests/auto/qtipc/lackey/scripts/readonly_segfault.js b/tests/auto/qtipc/lackey/scripts/readonly_segfault.js new file mode 100644 index 0000000..3eaf789 --- /dev/null +++ b/tests/auto/qtipc/lackey/scripts/readonly_segfault.js @@ -0,0 +1,4 @@ +var sm = new ScriptSharedMemory; +sm.setKey("readonly_segfault"); +sm.createReadOnly(1024); +var data = sm.set(0, "a"); diff --git a/tests/auto/qtipc/lackey/scripts/systemlock_read.js b/tests/auto/qtipc/lackey/scripts/systemlock_read.js new file mode 100644 index 0000000..1048bc7 --- /dev/null +++ b/tests/auto/qtipc/lackey/scripts/systemlock_read.js @@ -0,0 +1,11 @@ +function QVERIFY(x, debugInfo) { + if (!(x)) { + print(debugInfo); + throw(debugInfo); + } +} + +var lock = new ScriptSystemLock; +lock.setKey("market"); +QVERIFY(lock.lockReadOnly()); +QVERIFY(lock.unlock()); \ No newline at end of file diff --git a/tests/auto/qtipc/lackey/scripts/systemlock_readwrite.js b/tests/auto/qtipc/lackey/scripts/systemlock_readwrite.js new file mode 100644 index 0000000..fc6367f --- /dev/null +++ b/tests/auto/qtipc/lackey/scripts/systemlock_readwrite.js @@ -0,0 +1,11 @@ +function QVERIFY(x, debugInfo) { + if (!(x)) { + print(debugInfo); + throw(debugInfo); + } +} + +var lock = new ScriptSystemLock; +lock.setKey("market"); +QVERIFY(lock.lock()); +QVERIFY(lock.unlock()); diff --git a/tests/auto/qtipc/lackey/scripts/systemsemaphore_acquire.js b/tests/auto/qtipc/lackey/scripts/systemsemaphore_acquire.js new file mode 100644 index 0000000..5cff429 --- /dev/null +++ b/tests/auto/qtipc/lackey/scripts/systemsemaphore_acquire.js @@ -0,0 +1,18 @@ +#/bin/qscript +function QVERIFY(x, debugInfo) { + if (!(x)) { + print(debugInfo); + throw(debugInfo); + } +} + + +var sem = new ScriptSystemSemaphore; +sem.setKey("store"); + +var count = Number(args[1]); +if (isNaN(count)) + count = 1; +for (var i = 0; i < count; ++i) + QVERIFY(sem.acquire()); +print("done aquiring"); diff --git a/tests/auto/qtipc/lackey/scripts/systemsemaphore_acquirerelease.js b/tests/auto/qtipc/lackey/scripts/systemsemaphore_acquirerelease.js new file mode 100644 index 0000000..cedde3f --- /dev/null +++ b/tests/auto/qtipc/lackey/scripts/systemsemaphore_acquirerelease.js @@ -0,0 +1,11 @@ +function QVERIFY(x, debugInfo) { + if (!(x)) { + print(debugInfo); + throw(debugInfo); + } +} + +var lock = new ScriptSystemSemaphore; +lock.setKey("store"); +QVERIFY(lock.acquire()); +QVERIFY(lock.release()); diff --git a/tests/auto/qtipc/lackey/scripts/systemsemaphore_release.js b/tests/auto/qtipc/lackey/scripts/systemsemaphore_release.js new file mode 100644 index 0000000..c805e0f --- /dev/null +++ b/tests/auto/qtipc/lackey/scripts/systemsemaphore_release.js @@ -0,0 +1,11 @@ +function QVERIFY(x, debugInfo) { + if (!(x)) { + print(debugInfo); + throw(debugInfo); + } +} + +var sem = new ScriptSystemSemaphore; +sem.setKey("store"); +QVERIFY(sem.release()); +print ("done releasing"); diff --git a/tests/auto/qtipc/qsharedmemory/.gitignore b/tests/auto/qtipc/qsharedmemory/.gitignore new file mode 100644 index 0000000..03ddcf2 --- /dev/null +++ b/tests/auto/qtipc/qsharedmemory/.gitignore @@ -0,0 +1,3 @@ +tst_qsharedmemory +lackey/lackey.exe +qsystemlock/tst_qsystemlock.exe diff --git a/tests/auto/qtipc/qsharedmemory/qsharedmemory.pro b/tests/auto/qtipc/qsharedmemory/qsharedmemory.pro new file mode 100644 index 0000000..9fef8e4 --- /dev/null +++ b/tests/auto/qtipc/qsharedmemory/qsharedmemory.pro @@ -0,0 +1,4 @@ +TEMPLATE = subdirs +SUBDIRS = test qsystemlock + + diff --git a/tests/auto/qtipc/qsharedmemory/qsystemlock/qsystemlock.pro b/tests/auto/qtipc/qsharedmemory/qsystemlock/qsystemlock.pro new file mode 100644 index 0000000..e232443 --- /dev/null +++ b/tests/auto/qtipc/qsharedmemory/qsystemlock/qsystemlock.pro @@ -0,0 +1,22 @@ +CONFIG += qttest_p4 +#QT = core + +include(../src/src.pri) +win32: CONFIG += console +mac:CONFIG -= app_bundle + +wince* { + DEFINES += SRCDIR=\\\"\\\" +} else:!symbian { + DEFINES += SRCDIR=\\\"$$PWD\\\" +} + +DESTDIR = ./ + +DEFINES += QSHAREDMEMORY_DEBUG +DEFINES += QSYSTEMSEMAPHORE_DEBUG + +SOURCES += tst_qsystemlock.cpp +TARGET = tst_qsystemlock + + diff --git a/tests/auto/qtipc/qsharedmemory/qsystemlock/tst_qsystemlock.cpp b/tests/auto/qtipc/qsharedmemory/qsystemlock/tst_qsystemlock.cpp new file mode 100644 index 0000000..ea906b7 --- /dev/null +++ b/tests/auto/qtipc/qsharedmemory/qsystemlock/tst_qsystemlock.cpp @@ -0,0 +1,239 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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 + +//TESTED_CLASS= +//TESTED_FILES= + +#ifdef Q_OS_SYMBIAN +// In Symbian OS test data is located in applications private dir +// And underlying Open C have application private dir in default search path +#define SRCDIR "" +#endif + + +#define EXISTING_SHARE "existing" + +class tst_QSystemLock : public QObject +{ + Q_OBJECT + +public: + tst_QSystemLock(); + virtual ~tst_QSystemLock(); + +public Q_SLOTS: + void init(); + void cleanup(); + +private slots: + void key_data(); + void key(); + + void basicLock(); + void complexLock(); + void lockModes(); + void sucessive(); + void processes_data(); + void processes(); + +private: + QSystemLock *existingLock; + +}; + +tst_QSystemLock::tst_QSystemLock() +{ +} + +tst_QSystemLock::~tst_QSystemLock() +{ +} + +void tst_QSystemLock::init() +{ + existingLock = new QSystemLock(EXISTING_SHARE); +} + +void tst_QSystemLock::cleanup() +{ + delete existingLock; +} + +void tst_QSystemLock::key_data() +{ + QTest::addColumn("constructorKey"); + QTest::addColumn("setKey"); + + QTest::newRow("null, null") << QString() << QString(); + QTest::newRow("null, one") << QString() << QString("one"); + QTest::newRow("one, two") << QString("one") << QString("two"); +} + +/*! + Basic key testing + */ +void tst_QSystemLock::key() +{ + QFETCH(QString, constructorKey); + QFETCH(QString, setKey); + + QSystemLock sl(constructorKey); + QCOMPARE(sl.key(), constructorKey); + sl.setKey(setKey); + QCOMPARE(sl.key(), setKey); +} + +void tst_QSystemLock::basicLock() +{ + QSystemLock lock("foo"); + QVERIFY(lock.lock()); + QVERIFY(lock.unlock()); +} + +void tst_QSystemLock::complexLock() +{ + QSystemLock lock("foo"); + QVERIFY(lock.lock(QSystemLock::ReadOnly)); + QVERIFY(lock.unlock()); + + QVERIFY(lock.lock(QSystemLock::ReadWrite)); + QVERIFY(lock.unlock()); + + QVERIFY(lock.lock(QSystemLock::ReadOnly)); + QVERIFY(lock.lock(QSystemLock::ReadOnly)); + QVERIFY(lock.unlock()); + QVERIFY(lock.unlock()); +} + +void tst_QSystemLock::lockModes() +{ + QSystemLock reader1("library"); + QSystemLock reader2("library"); + + QSystemLock librarian("library"); + QVERIFY(reader1.lock(QSystemLock::ReadOnly)); + QVERIFY(reader2.lock(QSystemLock::ReadOnly)); + QVERIFY(reader1.unlock()); + QVERIFY(reader2.unlock()); + QVERIFY(librarian.lock(QSystemLock::ReadWrite)); + QVERIFY(librarian.unlock()); +} + +void tst_QSystemLock::sucessive() +{ + QSystemLock lock("library"); + QVERIFY(lock.lock(QSystemLock::ReadOnly)); + QVERIFY(lock.lock(QSystemLock::ReadOnly)); + QVERIFY(lock.lock(QSystemLock::ReadOnly)); + QVERIFY(lock.lock(QSystemLock::ReadOnly)); + QVERIFY(lock.lock(QSystemLock::ReadOnly)); + QVERIFY(lock.unlock()); + QVERIFY(lock.unlock()); + QVERIFY(lock.unlock()); + QVERIFY(lock.unlock()); + QVERIFY(lock.unlock()); + QVERIFY(!lock.unlock()); +} + +void tst_QSystemLock::processes_data() +{ + QTest::addColumn("readOnly"); + QTest::addColumn("readWrite"); + for (int i = 0; i < 5; ++i) { + QTest::newRow("1/0 process") << 1 << 0; + QTest::newRow("0/1 process") << 0 << 1; + QTest::newRow("0/4 process") << 0 << 4; + QTest::newRow("1/1 process") << 1 << 1; + QTest::newRow("10/1 process") << 10 << 1; + QTest::newRow("1/10 process") << 1 << 10; + QTest::newRow("10/10 processes") << 10 << 10; + } +} + +/*! + Create external processes + */ +void tst_QSystemLock::processes() +{ + QSKIP("This test takes about 15 minutes and needs to be trimmed down before we can re-enable it", SkipAll); + QFETCH(int, readOnly); + QFETCH(int, readWrite); + + QStringList scripts; + for (int i = 0; i < readOnly; ++i) + scripts.append(QFileInfo(SRCDIR "/../lackey/scripts/systemlock_read.js").absoluteFilePath() ); + for (int i = 0; i < readWrite; ++i) + scripts.append(QFileInfo(SRCDIR "/../lackey/scripts/systemlock_readwrite.js").absoluteFilePath()); + + QList consumers; + unsigned int failedProcesses = 0; + for (int i = 0; i < scripts.count(); ++i) { + + QStringList arguments = QStringList() << scripts.at(i); + QProcess *p = new QProcess; + p->setProcessChannelMode(QProcess::ForwardedChannels); + + p->start("../lackey/lackey", arguments); + // test, if the process could be started. + + if (p->waitForStarted(2000)) + consumers.append(p); + else + ++failedProcesses; + } + + while (!consumers.isEmpty()) { + consumers.first()->waitForFinished(3000); + consumers.first()->kill(); + QCOMPARE(consumers.first()->exitStatus(), QProcess::NormalExit); + QCOMPARE(consumers.first()->exitCode(), 0); + delete consumers.takeFirst(); + } + QCOMPARE(failedProcesses, (unsigned int)(0)); +} + +QTEST_MAIN(tst_QSystemLock) +#include "tst_qsystemlock.moc" + diff --git a/tests/auto/qtipc/qsharedmemory/src/qsystemlock.cpp b/tests/auto/qtipc/qsharedmemory/src/qsystemlock.cpp new file mode 100644 index 0000000..4ead748 --- /dev/null +++ b/tests/auto/qtipc/qsharedmemory/src/qsystemlock.cpp @@ -0,0 +1,246 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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 "qsystemlock.h" +#include "qsystemlock_p.h" + +#include + +/*! \class QSystemLocker + + \brief The QSystemLocker class is a convenience class that simplifies + locking and unlocking system locks. + + The purpose of QSystemLocker is to simplify QSystemLock locking and + unlocking. Locking and unlocking a QSystemLock in complex functions and + statements or in exception handling code is error-prone and difficult to + debug. QSystemLocker can be used in such situations to ensure that the + state of the locks is always well-defined. + + QSystemLocker should be created within a function where a QSystemLock needs + to be locked. The system lock is locked when QSystemLocker is created. If + locked, the system lock will be unlocked when the QSystemLocker is + destroyed. QSystemLocker can be unlocked with unlock() and relocked with + relock(). + + \sa QSystemLock + */ + +/*! \fn QSystemLocker::QSystemLocker() + + Constructs a QSystemLocker and locks \a lock. The \a lock will be + unlocked when the QSystemLocker is destroyed. If lock is zero, + QSystemLocker does nothing. + + \sa QSystemLock::lock() + */ + +/*! \fn QSystemLocker::~QSystemLocker() + + Destroys the QSystemLocker and unlocks it if it was + locked in the constructor. + + \sa QSystemLock::unlock() + */ + +/*! \fn QSystemLocker::systemLock() + + Returns a pointer to the lock that was locked in the constructor. + */ + +/*! \fn QSystemLocker::relock() + + Relocks an unlocked locker. + + \sa unlock() + */ + +/*! \fn QSystemLocker::unlock() + + Unlocks this locker. You can use relock() to lock it again. + It does not need to be locked when destroyed. + + \sa relock() + */ + +/*! \class QSystemLock + + \brief The QSystemLock class provides a system wide lock + that can be used between threads or processes. + + The purpose of a QSystemLocker is to protect an object that can be + accessed by multiple threads or processes such as shared memory or a file. + + For example, say there is a method which prints a message to a log file: + + void log(const QString &logText) + { + QSystemLock systemLock(QLatin1String("logfile")); + systemLock.lock(); + QFile file(QDir::temp() + QLatin1String("/log")); + if (file.open(QIODevice::Append)) { + QTextStream out(&file); + out << logText; + } + systemLock.unlock(); + } + + If this is called from two seperate processes the resulting log file is + guaranteed to contain both lines. + + When you call lock(), other threads or processes that try to call lock() + with the same key will block until the thread or process that got the lock + calls unlock(). + + A non-blocking alternative to lock() is tryLock(). + */ + +/*! + Constructs a new system lock with \a key. The lock is created in an + unlocked state. + + \sa lock(), key(). + */ +QSystemLock::QSystemLock(const QString &key) +{ + d = new QSystemLockPrivate; + setKey(key); +} + +/*! + Destroys a system lock. + + warning: This will not unlock the system lock if it has been locked. +*/ +QSystemLock::~QSystemLock() +{ + d->cleanHandle(); + delete d; +} + +/*! + Sets a new key to this system lock. + + \sa key() + */ +void QSystemLock::setKey(const QString &key) +{ + if (key == d->key) + return; + d->cleanHandle(); + d->lockCount = 0; + d->key = key; + // cache the file name so it doesn't have to be generated all the time. + d->fileName = d->makeKeyFileName(); + d->error = QSystemLock::NoError; + d->errorString = QString(); + d->handle(); +} + +/*! + Returns the key assigned to this system lock + + \sa setKey() + */ +QString QSystemLock::key() const +{ + return d->key; +} + +/*! + Locks the system lock. Lock \a mode can either be ReadOnly or ReadWrite. + If a mode is ReadOnly, attempts by other processes to obtain + ReadOnly locks will succeed, and ReadWrite attempts will block until + all of the ReadOnly locks are unlocked. If locked as ReadWrite, all + other attempts to lock will block until the lock is unlocked. A given + QSystemLock can be locked multiple times without blocking, and will + only be unlocked after a corresponding number of unlock() + calls are made. Returns true on success; otherwise returns false. + + \sa unlock(), tryLock() + */ +bool QSystemLock::lock(LockMode mode) +{ + if (d->lockCount > 0 && mode == ReadOnly && d->lockedMode == ReadWrite) { + qWarning() << "QSystemLock::lock readwrite lock on top of readonly lock."; + return false; + } + return d->modifySemaphore(QSystemLockPrivate::Lock, mode); +} + +/*! + Unlocks the system lock. + Returns true on success; otherwise returns false. + + \sa lock() + */ +bool QSystemLock::unlock() +{ + if (d->lockCount == 0) { + qWarning() << "QSystemLock::unlock: unlock with no lock."; + return false; + } + return d->modifySemaphore(QSystemLockPrivate::Unlock, d->lockedMode); +} + +/*! + Returns the type of error that occurred last or NoError. + + \sa errorString() + */ +QSystemLock::SystemLockError QSystemLock::error() const +{ + return d->error; +} + +/*! + Returns the human-readable message appropriate to the current error + reported by error(). If no suitable string is available, an empty + string is returned. + + \sa error() + */ +QString QSystemLock::errorString() const +{ + return d->errorString; +} + diff --git a/tests/auto/qtipc/qsharedmemory/src/qsystemlock.h b/tests/auto/qtipc/qsharedmemory/src/qsystemlock.h new file mode 100644 index 0000000..7cd6b89 --- /dev/null +++ b/tests/auto/qtipc/qsharedmemory/src/qsystemlock.h @@ -0,0 +1,135 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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$ +** +****************************************************************************/ + + +#ifndef QSYSTEMLOCK_H +#define QSYSTEMLOCK_H + +#include + +QT_BEGIN_HEADER + +#ifndef QT_NO_SYSTEMLOCK + +QT_FORWARD_DECLARE_CLASS(QSystemLockPrivate) + +class QSystemLock +{ + +public: + enum SystemLockError + { + NoError, + UnknownError + }; + + QSystemLock(const QString &key); + ~QSystemLock(); + + void setKey(const QString &key); + QString key() const; + + enum LockMode + { + ReadOnly, + ReadWrite + }; + + bool lock(LockMode mode = ReadWrite); + bool unlock(); + + SystemLockError error() const; + QString errorString() const; + +private: + Q_DISABLE_COPY(QSystemLock) + + QSystemLockPrivate *d; +}; + +class QSystemLocker +{ + +public: + inline QSystemLocker(QSystemLock *systemLock, + QSystemLock::LockMode mode = QSystemLock::ReadWrite) : q_lock(systemLock) + { + autoUnLocked = relock(mode); + } + + inline ~QSystemLocker() + { + if (autoUnLocked) + unlock(); + } + + inline QSystemLock *systemLock() const + { + return q_lock; + } + + inline bool relock(QSystemLock::LockMode mode = QSystemLock::ReadWrite) + { + return (q_lock && q_lock->lock(mode)); + } + + inline bool unlock() + { + if (q_lock && q_lock->unlock()) { + autoUnLocked = false; + return true; + } + return false; + } + +private: + Q_DISABLE_COPY(QSystemLocker) + + bool autoUnLocked; + QSystemLock *q_lock; +}; + +#endif // QT_NO_SYSTEMLOCK + +QT_END_HEADER + +#endif // QSYSTEMLOCK_H + diff --git a/tests/auto/qtipc/qsharedmemory/src/qsystemlock_p.h b/tests/auto/qtipc/qsharedmemory/src/qsystemlock_p.h new file mode 100644 index 0000000..7995a91 --- /dev/null +++ b/tests/auto/qtipc/qsharedmemory/src/qsystemlock_p.h @@ -0,0 +1,109 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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$ +** +****************************************************************************/ + + +#ifndef QSYSTEMLOCK_P_H +#define QSYSTEMLOCK_P_H + +#ifndef QT_NO_SYSTEMLOCK + +#include "qsystemlock.h" +#include "private/qsharedmemory_p.h" +#ifndef Q_OS_WINCE +#include +#endif + +#define MAX_LOCKS 64 + +class QSystemLockPrivate +{ + +public: + QSystemLockPrivate(); + + QString makeKeyFileName() + { + return QSharedMemoryPrivate::makePlatformSafeKey(key, QLatin1String("qipc_systemlock_")); + } + + void setErrorString(const QString &function); + +#ifdef Q_OS_WIN + HANDLE handle(); + bool lock(HANDLE, int count); + bool unlock(HANDLE, int count); +#else + key_t handle(); +#endif + void cleanHandle(); + + enum Operation { + Lock, + Unlock + }; + bool modifySemaphore(Operation op, QSystemLock::LockMode mode = QSystemLock::ReadOnly); + + QString key; + QString fileName; +#ifdef Q_OS_WIN + HANDLE semaphore; + HANDLE semaphoreLock; +#else + int semaphore; +#endif + int lockCount; + QSystemLock::LockMode lockedMode; + + QSystemLock::SystemLockError error; + QString errorString; + +private: +#ifndef Q_OS_WIN + key_t unix_key; + bool createdFile; + bool createdSemaphore; +#endif +}; + +#endif // QT_NO_SYSTEMLOCK + +#endif // QSYSTEMLOCK_P_H + diff --git a/tests/auto/qtipc/qsharedmemory/src/qsystemlock_unix.cpp b/tests/auto/qtipc/qsharedmemory/src/qsystemlock_unix.cpp new file mode 100644 index 0000000..525aa78 --- /dev/null +++ b/tests/auto/qtipc/qsharedmemory/src/qsystemlock_unix.cpp @@ -0,0 +1,233 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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 "qsystemlock.h" +#include "qsystemlock_p.h" + +#include +#include + +#include +#include +#include +#include +#include +#include + +#include +// We have to define this as on some sem.h will have it +union qt_semun { + int val; /* value for SETVAL */ + struct semid_ds *buf; /* buffer for IPC_STAT, IPC_SET */ + unsigned short *array; /* array for GETALL, SETALL */ +}; + +#define tr(x) QT_TRANSLATE_NOOP(QLatin1String("QSystemLock"), (x)) + +#if defined(Q_OS_SYMBIAN) +int createUnixKeyFile(const QString &fileName) +{ + if (QFile::exists(fileName)) + return 0; + + int fd = open(QFile::encodeName(fileName).constData(), + O_EXCL | O_CREAT | O_RDWR, 0640); + if (-1 == fd) { + if (errno == EEXIST) + return 0; + return -1; + } else { + close(fd); + } + return 1; +} +#endif + +QSystemLockPrivate::QSystemLockPrivate() : + semaphore(-1), lockCount(0), + error(QSystemLock::NoError), unix_key(-1), createdFile(false), createdSemaphore(false) +{ +} + +void QSystemLockPrivate::setErrorString(const QString &function) +{ + switch (errno) { + case EIDRM: + errorString = function + QLatin1String(": ") + tr("The semaphore set was removed"); + error = QSystemLock::UnknownError; + break; + default: + errorString = function + QLatin1String(": ") + tr("unknown error"); + error = QSystemLock::UnknownError; + qWarning() << errorString << "key" << key << "errno" << errno << ERANGE << ENOMEM << EINVAL << EINTR << EFBIG << EFAULT << EAGAIN << EACCES << E2BIG; + } +} + +/*! + \internal + + Setup unix_key + */ +key_t QSystemLockPrivate::handle() +{ + if (key.isEmpty()) + return -1; + + // ftok requires that an actual file exists somewhere + // If we have already made at some point in the past, + // double check that it is still there. + if (-1 != unix_key) { + int aNewunix_key = ftok(QFile::encodeName(fileName).constData(), 'Q'); + if (aNewunix_key != unix_key) { + cleanHandle(); + } else { + return unix_key; + } + } + + // Create the file needed for ftok +#if defined(Q_OS_SYMBIAN) + int built = createUnixKeyFile(fileName); +#else + int built = QSharedMemoryPrivate::createUnixKeyFile(fileName); +#endif + if (-1 == built) + return -1; + createdFile = (1 == built); + + // Get the unix key for the created file + unix_key = ftok(QFile::encodeName(fileName).constData(), 'Q'); + if (-1 == unix_key) { + setErrorString(QLatin1String("QSystemLock::handle ftok")); + return -1; + } + + // Get semaphore + semaphore = semget(unix_key, 1, 0666 | IPC_CREAT | IPC_EXCL); + if (-1 == semaphore) { + if (errno == EEXIST) + semaphore = semget(unix_key, 1, 0666 | IPC_CREAT); + if (-1 == semaphore) { + setErrorString(QLatin1String("QSystemLock::handle semget")); + cleanHandle(); + return -1; + } + } else { + // Created semaphore, initialize value. + createdSemaphore = true; + qt_semun init_op; + init_op.val = MAX_LOCKS; + if (-1 == semctl(semaphore, 0, SETVAL, init_op)) { + setErrorString(QLatin1String("QSystemLock::handle semctl")); + cleanHandle(); + return -1; + } + } + + return unix_key; +} + +/*! + \internal + + Cleanup the unix_key + */ +void QSystemLockPrivate::cleanHandle() +{ + unix_key = -1; + + // remove the file if we made it + if (createdFile) { + if (!QFile::remove(fileName)) + setErrorString(QLatin1String("QSystemLock::cleanHandle QFile::remove")); + createdFile = false; + } + + if (createdSemaphore) { + if (-1 != semaphore) { + if (-1 == semctl(semaphore, 0, IPC_RMID)) { + setErrorString(QLatin1String("QSystemLock::cleanHandle semctl")); + } + semaphore = -1; + } + createdSemaphore = false; + } +} + +/*! + \internal + + modifySemaphore generates operation.sem_op and handles recursive behavior. + */ +bool QSystemLockPrivate::modifySemaphore(QSystemLockPrivate::Operation op, + QSystemLock::LockMode mode) +{ + if (-1 == handle()) + return false; + + if ((lockCount == 0 && op == Lock) || (lockCount > 0 && op == Unlock)) { + if (op == Unlock) { + --lockCount; + Q_ASSERT(lockCount >= 0); + if (lockCount > 0) + return true; + } + + struct sembuf operation; + operation.sem_num = 0; + operation.sem_op = (mode == QSystemLock::ReadWrite) ? MAX_LOCKS : 1; + if (op == Lock) + operation.sem_op *= -1; + operation.sem_flg = SEM_UNDO; + + if (-1 == semop(semaphore, &operation, 1)) { + setErrorString(QLatin1String("QSystemLock::modify")); + return false; + } + lockedMode = mode; + } + if (op == Lock) + lockCount++; + + return true; +} + diff --git a/tests/auto/qtipc/qsharedmemory/src/qsystemlock_win.cpp b/tests/auto/qtipc/qsharedmemory/src/qsystemlock_win.cpp new file mode 100644 index 0000000..ac97100 --- /dev/null +++ b/tests/auto/qtipc/qsharedmemory/src/qsystemlock_win.cpp @@ -0,0 +1,182 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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 "qsystemlock.h" +#include "qsystemlock_p.h" +#include +#include +QSystemLockPrivate::QSystemLockPrivate() : + semaphore(0), semaphoreLock(0), + lockCount(0), error(QSystemLock::NoError) +{ +} + +void QSystemLockPrivate::setErrorString(const QString &function) +{ + BOOL windowsError = GetLastError(); + if (windowsError == 0) + return; + errorString = function + QLatin1String(": ") + + QLatin1String("Unknown error"); + error = QSystemLock::UnknownError; + qWarning() << errorString << "key" << key << (int)windowsError << semaphore << semaphoreLock; +} + +/*! + \internal + + Setup the semaphore + */ +HANDLE QSystemLockPrivate::handle() +{ + // don't allow making handles on empty keys + if (key.isEmpty()) + return 0; + + // Create it if it doesn't already exists. + if (semaphore == 0) { + QString safeName = makeKeyFileName(); + semaphore = CreateSemaphore(0, MAX_LOCKS, MAX_LOCKS, (wchar_t*)safeName.utf16()); + + if (semaphore == 0) { + setErrorString(QLatin1String("QSystemLockPrivate::handle")); + return 0; + } + } + + if (semaphoreLock == 0) { + QString safeLockName = QSharedMemoryPrivate::makePlatformSafeKey(key + QLatin1String("lock"), QLatin1String("qipc_systemlock_")); + semaphoreLock = CreateSemaphore(0, 1, 1, (wchar_t*)safeLockName.utf16()); + + if (semaphoreLock == 0) { + setErrorString(QLatin1String("QSystemLockPrivate::handle")); + return 0; + } + } + + return semaphore; +} + +/*! + \internal + + Cleanup the semaphore + */ +void QSystemLockPrivate::cleanHandle() +{ + if (semaphore && !CloseHandle(semaphore)) + setErrorString(QLatin1String("QSystemLockPrivate::cleanHandle:")); + if (semaphoreLock && !CloseHandle(semaphoreLock)) + setErrorString(QLatin1String("QSystemLockPrivate::cleanHandle:")); + semaphore = 0; + semaphoreLock = 0; +} + +bool QSystemLockPrivate::lock(HANDLE handle, int count) +{ + if (count == 1) { + WaitForSingleObject(handle, INFINITE); + return true; + } + + int i = count; + while (i > 0) { + if (WAIT_OBJECT_0 == WaitForSingleObject(handle, 0)) { + --i; + } else { + // undo what we have done, sleep and then try again later + ReleaseSemaphore(handle, (count - i), 0); + i = count; + ReleaseSemaphore(semaphoreLock, 1, 0); + Sleep(1); + WaitForSingleObject(semaphoreLock, INFINITE); + } + } + return true; +} + +bool QSystemLockPrivate::unlock(HANDLE handle, int count) +{ + if (0 == ReleaseSemaphore(handle, count, 0)) { + setErrorString(QLatin1String("QSystemLockPrivate::unlock")); + return false; + } + return true; +} + +/*! + \internal + + modifySemaphore handles recursive behavior and modifies the semaphore. + */ +bool QSystemLockPrivate::modifySemaphore(QSystemLockPrivate::Operation op, + QSystemLock::LockMode mode) +{ + if (0 == handle()) + return false; + + if ((lockCount == 0 && op == Lock) || (lockCount > 0 && op == Unlock)) { + if (op == Unlock) { + --lockCount; + Q_ASSERT(lockCount >= 0); + if (lockCount > 0) + return true; + } + + int count = (mode == QSystemLock::ReadWrite) ? MAX_LOCKS : 1; + if (op == Lock) { + lock(semaphoreLock, 1); + lock(semaphore, count); + if (count != MAX_LOCKS) unlock(semaphoreLock, 1); + lockedMode = mode; + } else { + if (count == MAX_LOCKS) unlock(semaphoreLock, 1); + unlock(semaphore, count); + } + + } + if (op == Lock) + lockCount++; + + return true; +} + diff --git a/tests/auto/qtipc/qsharedmemory/src/src.pri b/tests/auto/qtipc/qsharedmemory/src/src.pri new file mode 100644 index 0000000..5bc9de6 --- /dev/null +++ b/tests/auto/qtipc/qsharedmemory/src/src.pri @@ -0,0 +1,10 @@ +INCLUDEPATH += $$PWD +DEPENDPATH += $$PWD + +SOURCES += $$PWD/qsystemlock.cpp + +HEADERS += $$PWD/qsystemlock.h \ + $$PWD/qsystemlock_p.h + +unix:SOURCES += $$PWD/qsystemlock_unix.cpp +win32:SOURCES += $$PWD/qsystemlock_win.cpp diff --git a/tests/auto/qtipc/qsharedmemory/test/test.pro b/tests/auto/qtipc/qsharedmemory/test/test.pro new file mode 100644 index 0000000..40ba8b9 --- /dev/null +++ b/tests/auto/qtipc/qsharedmemory/test/test.pro @@ -0,0 +1,37 @@ +load(qttest_p4) + +include(../src/src.pri) +QT -= gui + +DEFINES += QSHAREDMEMORY_DEBUG +DEFINES += QSYSTEMSEMAPHORE_DEBUG + +SOURCES += ../tst_qsharedmemory.cpp +TARGET = ../tst_qsharedmemory + +!wince*:win32 { + CONFIG(debug, debug|release) { + TARGET = ../../debug/tst_qsharedmemory +} else { + TARGET = ../../release/tst_qsharedmemory + } +} + +wince*:{ +requires(contains(QT_CONFIG,script)) +QT += gui script +addFiles.sources = ../../lackey/lackey.exe ../../lackey/scripts +addFiles.path = lackey +DEPLOYMENT += addFiles +DEFINES += SRCDIR=\\\"\\\" +}else:symbian*{ +requires(contains(QT_CONFIG,script)) +QT += gui script +addFiles.sources = ../../lackey/scripts +addFiles.path = /data/qsharedmemorytemp/lackey +addBin.sources = lackey.exe +addBin.path = /sys/bin +DEPLOYMENT += addFiles addBin +} else { +DEFINES += SRCDIR=\\\"$$PWD/../\\\" +} diff --git a/tests/auto/qtipc/qsharedmemory/tst_qsharedmemory.cpp b/tests/auto/qtipc/qsharedmemory/tst_qsharedmemory.cpp new file mode 100644 index 0000000..83f65b0 --- /dev/null +++ b/tests/auto/qtipc/qsharedmemory/tst_qsharedmemory.cpp @@ -0,0 +1,776 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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 + +//TESTED_CLASS= +//TESTED_FILES= + +#define EXISTING_SHARE "existing" +#define EXISTING_SIZE 1024 + +#ifdef Q_OS_SYMBIAN +#define SRCDIR "c:/data/qsharedmemorytemp/" +#define LACKEYDIR SRCDIR "lackey" +#elif Q_OS_WINCE +#define LACKEYDIR SRCDIR "lackey" +#else +#define LACKEYDIR SRCDIR "../lackey" +#endif + +Q_DECLARE_METATYPE(QSharedMemory::SharedMemoryError) +Q_DECLARE_METATYPE(QSharedMemory::AccessMode) + +class tst_QSharedMemory : public QObject +{ + Q_OBJECT + +public: + tst_QSharedMemory(); + virtual ~tst_QSharedMemory(); + +public Q_SLOTS: + void init(); + void cleanup(); + +private slots: + // basics + void constructor(); + void key_data(); + void key(); + void create_data(); + void create(); + void attach_data(); + void attach(); + void lock(); + + // custom edge cases + void removeWhileAttached(); + void emptyMemory(); + void readOnly(); + + // basics all together + void simpleProducerConsumer_data(); + void simpleProducerConsumer(); + void simpleDoubleProducerConsumer(); + + // with threads + void simpleThreadedProducerConsumer_data(); + void simpleThreadedProducerConsumer(); + + // with processes + void simpleProcessProducerConsumer_data(); + void simpleProcessProducerConsumer(); + + // extreme cases + void useTooMuchMemory(); + void attachTooMuch(); + +protected: + int remove(const QString &key); + + QString rememberKey(const QString &key) + { + if (key == EXISTING_SHARE) + return key; + if (!keys.contains(key)) { + keys.append(key); + remove(key); + } + return key; + } + + QStringList keys; + QList jail; + QSharedMemory *existingSharedMemory; +}; + +tst_QSharedMemory::tst_QSharedMemory() : existingSharedMemory(0) +{ +} + +tst_QSharedMemory::~tst_QSharedMemory() +{ +} + +void tst_QSharedMemory::init() +{ + existingSharedMemory = new QSharedMemory(EXISTING_SHARE); + if (!existingSharedMemory->create(EXISTING_SIZE)) { + QVERIFY(existingSharedMemory->error() == QSharedMemory::AlreadyExists); + } +} + +void tst_QSharedMemory::cleanup() +{ + delete existingSharedMemory; + qDeleteAll(jail.begin(), jail.end()); + jail.clear(); + + keys.append(EXISTING_SHARE); + for (int i = 0; i < keys.count(); ++i) { + QSharedMemory sm(keys.at(i)); + if (!sm.create(1024)) { + //if(sm.error() != QSharedMemory::KeyError) + // qWarning() << "test cleanup: remove failed:" << keys.at(i) << sm.error() << sm.errorString(); + sm.attach(); + sm.detach(); + remove(keys.at(i)); + } + } +} + +#ifndef Q_OS_WIN +#include "private/qsharedmemory_p.h" +#include +#include +#include +#endif + +int tst_QSharedMemory::remove(const QString &key) +{ +#ifndef Q_OS_WIN + // On unix the shared memory might exists from a previously failed test + // or segfault, remove it it does + if (key.isEmpty()) + return -1; + + // ftok requires that an actual file exists somewhere + QString fileName = QSharedMemoryPrivate::makePlatformSafeKey(key); + if (!QFile::exists(fileName)) { + //qDebug() << "exits failed"; + return -2; + } + + int unix_key = ftok(fileName.toLatin1().constData(), 'Q'); + if (-1 == unix_key) { + qDebug() << "ftok failed"; + return -3; + } + + int id = shmget(unix_key, 0, 0660); + if (-1 == id) { + qDebug() << "shmget failed"; + return -4; + } + + struct shmid_ds shmid_ds; + if (-1 == shmctl(id, IPC_RMID, &shmid_ds)) { + qDebug() << "shmctl failed"; + return -5; + } + return QFile::remove(fileName); +#else + Q_UNUSED(key); + return 0; +#endif +} + +/*! + Tests the default values + */ +void tst_QSharedMemory::constructor() +{ + QSharedMemory sm; + QCOMPARE(sm.key(), QString()); + QVERIFY(!sm.isAttached()); + QVERIFY(sm.data() == 0); + QCOMPARE(sm.size(), 0); + QCOMPARE(sm.error(), QSharedMemory::NoError); + QVERIFY(sm.errorString() == QString()); +} + +void tst_QSharedMemory::key_data() +{ + QTest::addColumn("constructorKey"); + QTest::addColumn("setKey"); + + QTest::newRow("null, null") << QString() << QString(); + QTest::newRow("null, one") << QString() << QString("one"); + QTest::newRow("one, two") << QString("one") << QString("two"); + QTest::newRow("invalid") << QString("o/e") << QString("t/o"); +} + +/*! + Basic key testing + */ +void tst_QSharedMemory::key() +{ + QFETCH(QString, constructorKey); + QFETCH(QString, setKey); + + QSharedMemory sm(constructorKey); + QCOMPARE(sm.key(), constructorKey); + sm.setKey(setKey); + QCOMPARE(sm.key(), setKey); + QCOMPARE(sm.isAttached(), false); + + QCOMPARE(sm.error(), QSharedMemory::NoError); + QVERIFY(sm.errorString() == QString()); + QVERIFY(sm.data() == 0); + QCOMPARE(sm.size(), 0); + + QCOMPARE(sm.detach(), false); +} + +void tst_QSharedMemory::create_data() +{ + QTest::addColumn("key"); + QTest::addColumn("size"); + QTest::addColumn("canCreate"); + QTest::addColumn("error"); + + QTest::newRow("null key") << QString() << 1024 + << false << QSharedMemory::LockError; + QTest::newRow("-1 size") << QString("negsize") << -1 + << false << QSharedMemory::InvalidSize; + QTest::newRow("nor size") << QString("norsize") << 1024 + << true << QSharedMemory::NoError; + QTest::newRow("already exists") << QString(EXISTING_SHARE) << EXISTING_SIZE + << false << QSharedMemory::AlreadyExists; +} + +/*! + Basic create testing + */ +void tst_QSharedMemory::create() +{ + QFETCH(QString, key); + QFETCH(int, size); + QFETCH(bool, canCreate); + QFETCH(QSharedMemory::SharedMemoryError, error); + + QSharedMemory sm(rememberKey(key)); + QCOMPARE(sm.create(size), canCreate); + if(sm.error() != error) + qDebug() << sm.errorString(); + QCOMPARE(sm.key(), key); + if (canCreate) { + QVERIFY(sm.errorString() == QString()); + QVERIFY(sm.data() != 0); + QVERIFY(sm.size() != 0); + } else { + QVERIFY(sm.data() == 0); + QVERIFY(sm.errorString() != QString()); + } +} + +void tst_QSharedMemory::attach_data() +{ + QTest::addColumn("key"); + QTest::addColumn("exists"); + QTest::addColumn("error"); + + QTest::newRow("null key") << QString() << false << QSharedMemory::LockError; + QTest::newRow("doesn't exists") << QString("doesntexists") << false << QSharedMemory::NotFound; + QTest::newRow("already exists") << QString(EXISTING_SHARE) << true << QSharedMemory::NoError; +} + +/*! + Basic attach/detach testing + */ +void tst_QSharedMemory::attach() +{ + QFETCH(QString, key); + QFETCH(bool, exists); + QFETCH(QSharedMemory::SharedMemoryError, error); +#ifdef Q_OS_HPUX + if (QLatin1String(QTest::currentDataTag()) == QLatin1String("already exists")) { + QSKIP("HPUX doesn't allow for multiple attaches per process", SkipSingle); + } +#endif + QSharedMemory sm(key); + QCOMPARE(sm.attach(), exists); + QCOMPARE(sm.isAttached(), exists); + QCOMPARE(sm.error(), error); + QCOMPARE(sm.key(), key); + if (exists) { + QVERIFY(sm.data() != 0); + QVERIFY(sm.size() != 0); + QCOMPARE(sm.errorString(), QString()); + QVERIFY(sm.detach()); + // Make sure detach doesn't screw up something and we can't re-attach. + QVERIFY(sm.attach()); + QVERIFY(sm.detach()); + QCOMPARE(sm.size(), 0); + QVERIFY(sm.data() == 0); + } else { + QVERIFY(sm.data() == 0); + QVERIFY(sm.size() == 0); + QVERIFY(sm.errorString() != QString()); + QVERIFY(!sm.detach()); + } +} + +void tst_QSharedMemory::lock() +{ + QSharedMemory shm; + QVERIFY(!shm.lock()); + QCOMPARE(shm.error(), QSharedMemory::LockError); + + shm.setKey(QLatin1String("qsharedmemory")); + + QVERIFY(!shm.lock()); + QCOMPARE(shm.error(), QSharedMemory::LockError); + + QVERIFY(shm.create(100)); + QVERIFY(shm.lock()); + QTest::ignoreMessage(QtWarningMsg, "QSharedMemory::lock: already locked"); + QVERIFY(shm.lock()); + // don't lock forever +} + +/*! + Other shared memory are allowed to be attached after we remove, + but new shared memory are not allowed to attach after a remove. + */ +void tst_QSharedMemory::removeWhileAttached() +{ +#ifdef Q_OS_HPUX + QSKIP("HPUX doesn't allow for multiple attaches per process", SkipAll); +#endif + rememberKey("one"); + + // attach 1 + QSharedMemory *smOne = new QSharedMemory(QLatin1String("one")); + QVERIFY(smOne->create(1024)); + QVERIFY(smOne->isAttached()); + + // attach 2 + QSharedMemory *smTwo = new QSharedMemory(QLatin1String("one")); + QVERIFY(smTwo->attach()); + QVERIFY(smTwo->isAttached()); + + // detach 1 and remove, remove one first to catch another error. + delete smOne; + delete smTwo; + + // three shouldn't be able to attach + QSharedMemory smThree(QLatin1String("one")); + QVERIFY(!smThree.attach()); + QCOMPARE(smThree.error(), QSharedMemory::NotFound); +} + +/*! + The memory should be set to 0 after created. + */ +void tst_QSharedMemory::emptyMemory() +{ + QSharedMemory sm(rememberKey(QLatin1String("voidland"))); + int size = 1024; + QVERIFY(sm.create(size, QSharedMemory::ReadOnly)); + char *get = (char*)sm.data(); + char null = 0; + for (int i = 0; i < size; ++i) + QCOMPARE(get[i], null); +} + +/*! + Verify that attach with ReadOnly is actually read only + by writing to data and causing a segfault. +*/ +void tst_QSharedMemory::readOnly() +{ +#ifdef Q_OS_WIN + QSKIP("This test opens a crash dialog on Windows", SkipSingle); +#endif +#if defined (Q_OS_SYMBIAN) + QSKIP("Readonly shared memory is not supported in symbian", SkipAll); +#endif + QString program = LACKEYDIR "/lackey"; + QStringList arguments; + rememberKey("readonly_segfault"); + arguments << LACKEYDIR "/scripts/readonly_segfault.js"; + + // ### on windows disable the popup somehow + QProcess p; + p.start(program, arguments); + p.setProcessChannelMode(QProcess::ForwardedChannels); + p.waitForFinished(); + QCOMPARE(p.error(), QProcess::Crashed); +} + +/*! + Keep making shared memory until the kernel stops us. + */ +void tst_QSharedMemory::useTooMuchMemory() +{ +#ifdef Q_OS_LINUX + bool success = true; + int count = 0; + while (success) { + QString key = QString("maxmemorytest_%1").arg(count++); + QSharedMemory *sm = new QSharedMemory(rememberKey(key)); + QVERIFY(sm); + jail.append(sm); + int size = 32768 * 1024; + success = sm->create(size); + if (!success && sm->error() == QSharedMemory::AlreadyExists) { + // left over from a crash, clean it up + sm->attach(); + sm->detach(); + success = sm->create(size); + } + + if (!success) { + QVERIFY(!sm->isAttached()); + QCOMPARE(sm->key(), key); + QCOMPARE(sm->size(), 0); + QVERIFY(sm->data() == 0); + if (sm->error() != QSharedMemory::OutOfResources) + qDebug() << sm->error() << sm->errorString(); + // ### Linux wont return OutOfResources if there are not enough semaphores to use. + QVERIFY(sm->error() == QSharedMemory::OutOfResources + || sm->error() == QSharedMemory::LockError); + QVERIFY(sm->errorString() != QString()); + QVERIFY(!sm->attach()); + QVERIFY(!sm->detach()); + } else { + QVERIFY(sm->isAttached()); + } + } +#endif +} + +/*! + Create one shared memory (government) and see how many other shared memories (wars) we can + attach before the system runs out of resources. + */ +void tst_QSharedMemory::attachTooMuch() +{ + QSKIP("disabled", SkipAll); +#ifdef Q_OS_HPUX + QSKIP("HPUX doesn't allow for multiple attaches per process", SkipAll); +#endif +#ifdef Q_OS_WINCE + QSKIP("This nearly kills the system itself, so skip for Qt/WinCE", SkipAll); +#endif + QSharedMemory government(rememberKey("government")); + QVERIFY(government.create(1024)); + while (true) { + QSharedMemory *war = new QSharedMemory(government.key()); + QVERIFY(war); + jail.append(war); + if (!war->attach()) { + QVERIFY(!war->isAttached()); + QCOMPARE(war->key(), government.key()); + QCOMPARE(war->size(), 0); + QVERIFY(war->data() == 0); + QCOMPARE(war->error(), QSharedMemory::OutOfResources); + QVERIFY(war->errorString() != QString()); + QVERIFY(!war->detach()); + break; + } else { + QVERIFY(war->isAttached()); + } + } +} + +void tst_QSharedMemory::simpleProducerConsumer_data() +{ + QTest::addColumn("mode"); + + QTest::newRow("readonly") << QSharedMemory::ReadOnly; + QTest::newRow("readwrite") << QSharedMemory::ReadWrite; +} + +/*! + The basic consumer producer that rounds out the basic testing. + If this fails then any muli-threading/process might fail (but be + harder to debug) + + This doesn't require nor test any locking system. + */ +void tst_QSharedMemory::simpleProducerConsumer() +{ +#ifdef Q_OS_HPUX + QSKIP("HPUX doesn't allow for multiple attaches per process", SkipAll); +#endif + QFETCH(QSharedMemory::AccessMode, mode); + + rememberKey(QLatin1String("market")); + QSharedMemory producer(QLatin1String("market")); + QSharedMemory consumer(QLatin1String("market")); + int size = 512; + QVERIFY(producer.create(size)); + QVERIFY(consumer.attach(mode)); + + char *put = (char*)producer.data(); + char *get = (char*)consumer.data(); + // On Windows CE you always have ReadWrite access. Thus + // ViewMapOfFile returns the same pointer + // On Symbian, the address will always be same, as + // write protection of chunks is not currently supported by Symbian +#if !defined(Q_OS_WINCE) && !defined(Q_OS_SYMBIAN) + QVERIFY(put != get); +#endif + for (int i = 0; i < size; ++i) { + put[i] = 'Q'; + QCOMPARE(get[i], 'Q'); + } + QVERIFY(consumer.detach()); +} + +void tst_QSharedMemory::simpleDoubleProducerConsumer() +{ +#ifdef Q_OS_HPUX + QSKIP("HPUX doesn't allow for multiple attaches per process", SkipAll); +#endif + rememberKey(QLatin1String("market")); + QSharedMemory producer(QLatin1String("market")); + int size = 512; + QVERIFY(producer.create(size)); + QVERIFY(producer.detach()); + QVERIFY(producer.create(size)); + + { + QSharedMemory consumer(QLatin1String("market")); + QVERIFY(consumer.attach()); + } +} + +class Consumer : public QThread +{ + +public: + void run() + { + QSharedMemory consumer(QLatin1String("market")); + while (!consumer.attach()) { + if (consumer.error() != QSharedMemory::NotFound) + qDebug() << "consumer: failed to connect" << consumer.error() << consumer.errorString(); + QVERIFY(consumer.error() == QSharedMemory::NotFound || consumer.error() == QSharedMemory::KeyError); + QTest::qWait(1); + } + + char *memory = (char*)consumer.data(); + + int i = 0; + while (true) { + if(!consumer.lock()) + break; + if (memory[0] == 'Q') + memory[0] = ++i; + if (memory[0] == 'E') { + memory[1]++; + QVERIFY(consumer.unlock()); + break; + } + QVERIFY(consumer.unlock()); + QTest::qWait(1); + } + + QVERIFY(consumer.detach()); + } +}; + +class Producer : public QThread +{ + +public: + void run() + { + QSharedMemory producer(QLatin1String("market")); + int size = 1024; + if (!producer.create(size)) { + // left over from a crash... + if (producer.error() == QSharedMemory::AlreadyExists) { + producer.attach(); + producer.detach(); + QVERIFY(producer.create(size)); + } + } + QVERIFY(producer.isAttached()); + char *memory = (char*)producer.data(); + memory[1] = '0'; + QTime timer; + timer.start(); + int i = 0; + while (i < 5 && timer.elapsed() < 5000) { + QVERIFY(producer.lock()); + if (memory[0] == 'Q') { + QVERIFY(producer.unlock()); + QTest::qWait(1); + continue; + } + ++i; + memory[0] = 'Q'; + QVERIFY(producer.unlock()); + QTest::qWait(1); + } + + // tell everyone to quit + QVERIFY(producer.lock()); + memory[0] = 'E'; + QVERIFY(producer.unlock()); + +#if defined(Q_OS_SYMBIAN) + // Sleep a while to ensure that consumers start properly + QTest::qSleep(1000); +#endif + } +private: + +}; + +void tst_QSharedMemory::simpleThreadedProducerConsumer_data() +{ + QTest::addColumn("producerIsThread"); + QTest::addColumn("threads"); + for (int i = 0; i < 5; ++i) { + QTest::newRow("1 consumer, producer is thread") << true << 1; + QTest::newRow("1 consumer, producer is this") << false << 1; + QTest::newRow("5 consumers, producer is thread") << true << 5; + QTest::newRow("5 consumers, producer is this") << false << 5; + } +} + +/*! + The basic producer/consumer, but this time using threads. + */ +void tst_QSharedMemory::simpleThreadedProducerConsumer() +{ + QFETCH(bool, producerIsThread); + QFETCH(int, threads); + rememberKey(QLatin1String("market")); + +#if defined Q_OS_HPUX && defined __ia64 + QSKIP("This test locks up on gravlaks.troll.no", SkipSingle); +#endif + + Producer p; +#if defined(Q_OS_SYMBIAN) + enum + { + /** + * The maximum stack size. + */ + SymbianStackSize = 0x14000 + }; + p.setStackSize(SymbianStackSize); +#endif + if (producerIsThread) + p.start(); + + QList consumers; + for (int i = 0; i < threads; ++i) { + consumers.append(new Consumer()); +#if defined(Q_OS_SYMBIAN) + consumers.last()->setStackSize(SymbianStackSize); +#endif + consumers.last()->start(); + } + + if (!producerIsThread) + p.run(); + + p.wait(5000); + while (!consumers.isEmpty()) { + QVERIFY(consumers.first()->wait(5000)); + delete consumers.takeFirst(); + } +} + +void tst_QSharedMemory::simpleProcessProducerConsumer_data() +{ + QTest::addColumn("processes"); + int tries = 5; + for (int i = 0; i < tries; ++i) { + QTest::newRow("1 process") << 1; + QTest::newRow("5 processes") << 5; + } +} + +/*! + Create external processes that produce and consume. + */ +void tst_QSharedMemory::simpleProcessProducerConsumer() +{ +#if defined (Q_OS_SYMBIAN) && defined(Q_CC_NOKIAX86) + QSKIP("Cannot launch multiple Qt processes in Symbian emulator", SkipAll); +#endif + QFETCH(int, processes); + + rememberKey("market"); + + QStringList arguments = QStringList() << LACKEYDIR "/scripts/producer.js"; + QProcess producer; + producer.setProcessChannelMode(QProcess::ForwardedChannels); + producer.start( LACKEYDIR "/lackey", arguments); + producer.waitForStarted(); + QVERIFY(producer.error() != QProcess::FailedToStart); + + QList consumers; + unsigned int failedProcesses = 0; + for (int i = 0; i < processes; ++i) { + QStringList arguments = QStringList() << LACKEYDIR "/scripts/consumer.js"; + QProcess *p = new QProcess; + p->setProcessChannelMode(QProcess::ForwardedChannels); + p->start(LACKEYDIR "/lackey", arguments); + + if (p->waitForStarted(2000)) + consumers.append(p); + else + ++failedProcesses; + } + + QVERIFY(producer.waitForFinished(5000)); + + bool consumerFailed = false; + + while (!consumers.isEmpty()) { + QVERIFY(consumers.first()->waitForFinished(3000)); + if (consumers.first()->state() == QProcess::Running || + consumers.first()->exitStatus() != QProcess::NormalExit || + consumers.first()->exitCode() != 0) { + consumerFailed = true; + } + delete consumers.takeFirst(); + } + QCOMPARE(consumerFailed, false); + QCOMPARE(failedProcesses, (unsigned int)(0)); +} + +QTEST_MAIN(tst_QSharedMemory) +#include "tst_qsharedmemory.moc" + diff --git a/tests/auto/qtipc/qsystemsemaphore/.gitignore b/tests/auto/qtipc/qsystemsemaphore/.gitignore new file mode 100644 index 0000000..2b60bfb --- /dev/null +++ b/tests/auto/qtipc/qsystemsemaphore/.gitignore @@ -0,0 +1 @@ +tst_qsystemsemaphore diff --git a/tests/auto/qtipc/qsystemsemaphore/files.qrc b/tests/auto/qtipc/qsystemsemaphore/files.qrc new file mode 100644 index 0000000..6296690 --- /dev/null +++ b/tests/auto/qtipc/qsystemsemaphore/files.qrc @@ -0,0 +1,7 @@ + + + ../lackey/scripts/systemsemaphore_acquire.js + ../lackey/scripts/systemsemaphore_release.js + ../lackey/scripts/systemsemaphore_acquirerelease.js + + diff --git a/tests/auto/qtipc/qsystemsemaphore/qsystemsemaphore.pro b/tests/auto/qtipc/qsystemsemaphore/qsystemsemaphore.pro new file mode 100644 index 0000000..1f9205e --- /dev/null +++ b/tests/auto/qtipc/qsystemsemaphore/qsystemsemaphore.pro @@ -0,0 +1,36 @@ +CONFIG += qttest_p4 +#QT = core + +include(../qsharedmemory/src/src.pri) +win32: CONFIG += console + +DEFINES += QSHAREDMEMORY_DEBUG +DEFINES += QSYSTEMSEMAPHORE_DEBUG + +SOURCES += tst_qsystemsemaphore.cpp +TARGET = tst_qsystemsemaphore + +RESOURCES += files.qrc + +wince*: { +requires(contains(QT_CONFIG,script)) +# this test calls lackey, which then again depends on QtScript. +# let's add it here so that it gets deployed easily +QT += script +lackey.sources = ../lackey/lackey.exe +lackey.path = ../lackey + +DEPLOYMENT += lackey +} + +symbian: { +requires(contains(QT_CONFIG,script)) +# this test calls lackey, which then again depends on QtScript. +# let's add it here so that it gets deployed easily +QT += script + +lackey.sources = ../lackey/lackey.exe +lackey.path = /sys/bin +DEPLOYMENT += lackey +} + diff --git a/tests/auto/qtipc/qsystemsemaphore/tst_qsystemsemaphore.cpp b/tests/auto/qtipc/qsystemsemaphore/tst_qsystemsemaphore.cpp new file mode 100644 index 0000000..eb82fd4 --- /dev/null +++ b/tests/auto/qtipc/qsystemsemaphore/tst_qsystemsemaphore.cpp @@ -0,0 +1,302 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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 +//TESTED_CLASS= +//TESTED_FILES= + +#define EXISTING_SHARE "existing" +#define LACKYLOC "../lackey" +#define LACKYWAITTIME 10000 + +class tst_QSystemSemaphore : public QObject +{ + Q_OBJECT + +public: + tst_QSystemSemaphore(); + virtual ~tst_QSystemSemaphore(); + +public Q_SLOTS: + void init(); + void cleanup(); + +private slots: + void key_data(); + void key(); + + void basicacquire(); + void complexacquire(); + + void basicProcesses(); + + void processes_data(); + void processes(); + + void undo(); + void initialValue(); + +private: + QSystemSemaphore *existingLock; + + QString makeFile(const QString &resource) + { + QFile memory(resource); + if (!memory.open(QIODevice::ReadOnly)) { + qDebug() << "error reading resource" << resource; + return QString(); + } + QTemporaryFile *file = new QTemporaryFile; + file->open(); + file->write(memory.readAll()); + tempFiles.append(file); + file->flush(); +#ifdef Q_OS_WINCE + // flush does not flush to disk on Windows CE. It flushes it into its application + // cache. Thus we need to close the file to be able that other processes(lackey) can read it + QString fileName = file->fileName(); + file->close(); + return fileName; +#endif + return file->fileName(); + } + + QString acquire_js() { return makeFile(":/systemsemaphore_acquire.js"); } + QString release_js() { return makeFile(":/systemsemaphore_release.js"); } + QString acquirerelease_js() { return makeFile(":/systemsemaphore_acquirerelease.js"); } + QList tempFiles; +}; + +tst_QSystemSemaphore::tst_QSystemSemaphore() +{ + if (!QFile::exists(LACKYLOC "/lackey")) + qWarning() << "lackey executable doesn't exists!"; +} + +tst_QSystemSemaphore::~tst_QSystemSemaphore() +{ + qDeleteAll(tempFiles); +} + +void tst_QSystemSemaphore::init() +{ + existingLock = new QSystemSemaphore(EXISTING_SHARE, 1, QSystemSemaphore::Create); +} + +void tst_QSystemSemaphore::cleanup() +{ + delete existingLock; +} + +void tst_QSystemSemaphore::key_data() +{ + QTest::addColumn("constructorKey"); + QTest::addColumn("setKey"); + + QTest::newRow("null, null") << QString() << QString(); + QTest::newRow("null, one") << QString() << QString("one"); + QTest::newRow("one, two") << QString("one") << QString("two"); +} + +/*! + Basic key testing + */ +void tst_QSystemSemaphore::key() +{ + QFETCH(QString, constructorKey); + QFETCH(QString, setKey); + + QSystemSemaphore sem(constructorKey); + QCOMPARE(sem.key(), constructorKey); + QCOMPARE(sem.error(), QSystemSemaphore::NoError); + QCOMPARE(sem.errorString(), QString()); + + sem.setKey(setKey); + QCOMPARE(sem.key(), setKey); + QCOMPARE(sem.error(), QSystemSemaphore::NoError); + QCOMPARE(sem.errorString(), QString()); +} + +void tst_QSystemSemaphore::basicacquire() +{ + QSystemSemaphore sem("QSystemSemaphore_basicacquire", 1, QSystemSemaphore::Create); + QVERIFY(sem.acquire()); + QCOMPARE(sem.error(), QSystemSemaphore::NoError); + QVERIFY(sem.release()); + QCOMPARE(sem.error(), QSystemSemaphore::NoError); + QCOMPARE(sem.errorString(), QString()); +} + +void tst_QSystemSemaphore::complexacquire() +{ + QSystemSemaphore sem("QSystemSemaphore_complexacquire", 2, QSystemSemaphore::Create); + QVERIFY(sem.acquire()); + QVERIFY(sem.release()); + QVERIFY(sem.acquire()); + QVERIFY(sem.release()); + QVERIFY(sem.acquire()); + QVERIFY(sem.acquire()); + QVERIFY(sem.release()); + QVERIFY(sem.release()); + QCOMPARE(sem.error(), QSystemSemaphore::NoError); + QCOMPARE(sem.errorString(), QString()); +} + +void tst_QSystemSemaphore::basicProcesses() +{ +#if defined (Q_OS_SYMBIAN) && defined(Q_CC_NOKIAX86) + QSKIP("Cannot launch multiple Qt processes in Symbian emulator", SkipAll); +#endif + QSystemSemaphore sem("store", 0, QSystemSemaphore::Create); + + QStringList acquireArguments = QStringList() << acquire_js(); + QStringList releaseArguments = QStringList() << release_js(); + QProcess acquire; + acquire.setProcessChannelMode(QProcess::ForwardedChannels); + + QProcess release; + release.setProcessChannelMode(QProcess::ForwardedChannels); + + acquire.start(LACKYLOC "/lackey", acquireArguments); + acquire.waitForFinished(LACKYWAITTIME); + QVERIFY(acquire.state() == QProcess::Running); + acquire.kill(); + release.start(LACKYLOC "/lackey", releaseArguments); + acquire.waitForFinished(LACKYWAITTIME); + release.waitForFinished(LACKYWAITTIME); + QVERIFY(acquire.state() == QProcess::NotRunning); +} + +void tst_QSystemSemaphore::processes_data() +{ + QTest::addColumn("processes"); + for (int i = 0; i < 5; ++i) { + QTest::newRow("1 process") << 1; + QTest::newRow("3 process") << 3; + QTest::newRow("10 process") << 10; + } +} + +void tst_QSystemSemaphore::processes() +{ +#if defined (Q_OS_SYMBIAN) && defined(Q_CC_NOKIAX86) + QSKIP("Cannot launch multiple Qt processes in Symbian emulator", SkipAll); +#endif + QSystemSemaphore sem("store", 1, QSystemSemaphore::Create); + + QFETCH(int, processes); + QStringList scripts; + for (int i = 0; i < processes; ++i) + scripts.append(acquirerelease_js()); + + QList consumers; + for (int i = 0; i < scripts.count(); ++i) { + QStringList arguments = QStringList() << scripts.at(i); + QProcess *p = new QProcess; + p->setProcessChannelMode(QProcess::ForwardedChannels); + consumers.append(p); + p->start(LACKYLOC "/lackey", arguments); + } + + while (!consumers.isEmpty()) { + consumers.first()->waitForFinished(); + QCOMPARE(consumers.first()->exitStatus(), QProcess::NormalExit); + QCOMPARE(consumers.first()->exitCode(), 0); + delete consumers.takeFirst(); + } +} + +void tst_QSystemSemaphore::undo() +{ +#if defined(Q_OS_WIN) || defined(Q_OS_SYMBIAN) + QSKIP("This test only checks a unix behavior", SkipSingle); +#endif + + QSystemSemaphore sem("store", 1, QSystemSemaphore::Create); + + QStringList acquireArguments = QStringList() << acquire_js(); + QProcess acquire; + acquire.setProcessChannelMode(QProcess::ForwardedChannels); + acquire.start(LACKYLOC "/lackey", acquireArguments); + acquire.waitForFinished(LACKYWAITTIME); + QVERIFY(acquire.state()== QProcess::NotRunning); + + // At process exit the kernel should auto undo + + acquire.start(LACKYLOC "/lackey", acquireArguments); + acquire.waitForFinished(LACKYWAITTIME); + QVERIFY(acquire.state()== QProcess::NotRunning); +} + +void tst_QSystemSemaphore::initialValue() +{ +#if defined (Q_OS_SYMBIAN) && defined(Q_CC_NOKIAX86) + QSKIP("Cannot launch multiple Qt processes in Symbian emulator", SkipAll); +#endif + QSystemSemaphore sem("store", 1, QSystemSemaphore::Create); + + QStringList acquireArguments = QStringList() << acquire_js(); + QStringList releaseArguments = QStringList() << release_js(); + QProcess acquire; + acquire.setProcessChannelMode(QProcess::ForwardedChannels); + + QProcess release; + release.setProcessChannelMode(QProcess::ForwardedChannels); + + acquire.start(LACKYLOC "/lackey", acquireArguments); + acquire.waitForFinished(LACKYWAITTIME); + QVERIFY(acquire.state()== QProcess::NotRunning); + + acquire.start(LACKYLOC "/lackey", acquireArguments << "2"); + acquire.waitForFinished(LACKYWAITTIME); + QVERIFY(acquire.state()== QProcess::Running); + acquire.kill(); + + release.start(LACKYLOC "/lackey", releaseArguments); + acquire.waitForFinished(LACKYWAITTIME); + release.waitForFinished(LACKYWAITTIME); + QVERIFY(acquire.state()== QProcess::NotRunning); +} +QTEST_MAIN(tst_QSystemSemaphore) +#include "tst_qsystemsemaphore.moc" + diff --git a/tests/auto/qtipc/qtipc.pro b/tests/auto/qtipc/qtipc.pro new file mode 100644 index 0000000..60037d2 --- /dev/null +++ b/tests/auto/qtipc/qtipc.pro @@ -0,0 +1,6 @@ +TEMPLATE=subdirs +SUBDIRS=\ + lackey \ + qsharedmemory \ + qsystemsemaphore \ + -- cgit v0.12 From 2d67f6efc47986e8f6d69943f0986d18ae2ced96 Mon Sep 17 00:00:00 2001 From: Rohan McGovern Date: Tue, 16 Feb 2010 15:34:50 +1000 Subject: Fixed compile of xmlpatterns tests with vcproj generator. These tests were adding the same SUBDIR multiple times from different projects. Don't do that. --- tests/auto/auto.pro | 9 +- tests/auto/xmlpatternsdiagnosticsts/test/test.pro | 32 - .../test/tst_xmlpatternsdiagnosticsts.cpp | 80 -- .../tst_xmlpatternsdiagnosticsts.cpp | 80 ++ .../xmlpatternsdiagnosticsts.pro | 30 +- .../xmlpatternsschemats/xmlpatternsschemats.pro | 14 +- tests/auto/xmlpatternssdk/ASTItem.cpp | 161 ++++ tests/auto/xmlpatternssdk/ASTItem.h | 115 +++ .../auto/xmlpatternssdk/DebugExpressionFactory.cpp | 264 ++++++ tests/auto/xmlpatternssdk/DebugExpressionFactory.h | 128 +++ tests/auto/xmlpatternssdk/ErrorHandler.cpp | 166 ++++ tests/auto/xmlpatternssdk/ErrorHandler.h | 149 ++++ tests/auto/xmlpatternssdk/ErrorItem.cpp | 142 ++++ tests/auto/xmlpatternssdk/ErrorItem.h | 94 +++ tests/auto/xmlpatternssdk/ExitCode.h | 105 +++ tests/auto/xmlpatternssdk/ExpressionInfo.cpp | 54 ++ tests/auto/xmlpatternssdk/ExpressionInfo.h | 80 ++ tests/auto/xmlpatternssdk/ExpressionNamer.cpp | 316 +++++++ tests/auto/xmlpatternssdk/ExpressionNamer.h | 281 +++++++ tests/auto/xmlpatternssdk/ExternalSourceLoader.cpp | 140 ++++ tests/auto/xmlpatternssdk/ExternalSourceLoader.h | 137 ++++ tests/auto/xmlpatternssdk/Global.cpp | 83 ++ tests/auto/xmlpatternssdk/Global.h | 128 +++ tests/auto/xmlpatternssdk/ResultThreader.cpp | 76 ++ tests/auto/xmlpatternssdk/ResultThreader.h | 110 +++ tests/auto/xmlpatternssdk/TestBaseLine.cpp | 511 ++++++++++++ tests/auto/xmlpatternssdk/TestBaseLine.h | 212 +++++ tests/auto/xmlpatternssdk/TestCase.cpp | 439 ++++++++++ tests/auto/xmlpatternssdk/TestCase.h | 256 ++++++ tests/auto/xmlpatternssdk/TestContainer.cpp | 151 ++++ tests/auto/xmlpatternssdk/TestContainer.h | 123 +++ tests/auto/xmlpatternssdk/TestGroup.cpp | 143 ++++ tests/auto/xmlpatternssdk/TestGroup.h | 93 +++ tests/auto/xmlpatternssdk/TestItem.h | 133 +++ tests/auto/xmlpatternssdk/TestResult.cpp | 158 ++++ tests/auto/xmlpatternssdk/TestResult.h | 179 ++++ tests/auto/xmlpatternssdk/TestResultHandler.cpp | 98 +++ tests/auto/xmlpatternssdk/TestResultHandler.h | 115 +++ tests/auto/xmlpatternssdk/TestSuite.cpp | 269 ++++++ tests/auto/xmlpatternssdk/TestSuite.h | 160 ++++ tests/auto/xmlpatternssdk/TestSuiteHandler.cpp | 312 +++++++ tests/auto/xmlpatternssdk/TestSuiteHandler.h | 169 ++++ tests/auto/xmlpatternssdk/TestSuiteResult.cpp | 173 ++++ tests/auto/xmlpatternssdk/TestSuiteResult.h | 93 +++ tests/auto/xmlpatternssdk/TreeItem.cpp | 62 ++ tests/auto/xmlpatternssdk/TreeItem.h | 114 +++ tests/auto/xmlpatternssdk/TreeModel.cpp | 184 +++++ tests/auto/xmlpatternssdk/TreeModel.h | 110 +++ tests/auto/xmlpatternssdk/Worker.cpp | 258 ++++++ tests/auto/xmlpatternssdk/Worker.h | 100 +++ tests/auto/xmlpatternssdk/XMLWriter.cpp | 669 +++++++++++++++ tests/auto/xmlpatternssdk/XMLWriter.h | 403 +++++++++ tests/auto/xmlpatternssdk/XQTSTestCase.cpp | 286 +++++++ tests/auto/xmlpatternssdk/XQTSTestCase.h | 149 ++++ tests/auto/xmlpatternssdk/XSDTSTestCase.cpp | 375 +++++++++ tests/auto/xmlpatternssdk/XSDTSTestCase.h | 161 ++++ tests/auto/xmlpatternssdk/XSDTestSuiteHandler.cpp | 910 +++++++++++++++++++++ tests/auto/xmlpatternssdk/XSDTestSuiteHandler.h | 121 +++ tests/auto/xmlpatternssdk/XSLTTestSuiteHandler.cpp | 234 ++++++ tests/auto/xmlpatternssdk/XSLTTestSuiteHandler.h | 158 ++++ .../xmlpatternssdk/docs/XMLIndenterExample.cpp | 63 ++ .../docs/XMLIndenterExampleResult.xml | 3 + .../auto/xmlpatternssdk/docs/XMLWriterExample.cpp | 63 ++ .../xmlpatternssdk/docs/XMLWriterExampleResult.xml | 3 + tests/auto/xmlpatternssdk/tests/XMLWriterTest.cpp | 186 +++++ tests/auto/xmlpatternssdk/tests/XMLWriterTest.h | 77 ++ tests/auto/xmlpatternssdk/xmlpatternssdk.pro | 88 ++ tests/auto/xmlpatternsview/test/test.pro | 17 - .../xmlpatternsview/test/tst_xmlpatternsview.cpp | 74 -- tests/auto/xmlpatternsview/tst_xmlpatternsview.cpp | 74 ++ tests/auto/xmlpatternsview/xmlpatternsview.pro | 15 +- tests/auto/xmlpatternsxqts/lib/ASTItem.cpp | 161 ---- tests/auto/xmlpatternsxqts/lib/ASTItem.h | 115 --- .../xmlpatternsxqts/lib/DebugExpressionFactory.cpp | 264 ------ .../xmlpatternsxqts/lib/DebugExpressionFactory.h | 128 --- tests/auto/xmlpatternsxqts/lib/ErrorHandler.cpp | 166 ---- tests/auto/xmlpatternsxqts/lib/ErrorHandler.h | 149 ---- tests/auto/xmlpatternsxqts/lib/ErrorItem.cpp | 142 ---- tests/auto/xmlpatternsxqts/lib/ErrorItem.h | 94 --- tests/auto/xmlpatternsxqts/lib/ExitCode.h | 105 --- tests/auto/xmlpatternsxqts/lib/ExpressionInfo.cpp | 54 -- tests/auto/xmlpatternsxqts/lib/ExpressionInfo.h | 80 -- tests/auto/xmlpatternsxqts/lib/ExpressionNamer.cpp | 316 ------- tests/auto/xmlpatternsxqts/lib/ExpressionNamer.h | 281 ------- .../xmlpatternsxqts/lib/ExternalSourceLoader.cpp | 140 ---- .../xmlpatternsxqts/lib/ExternalSourceLoader.h | 137 ---- tests/auto/xmlpatternsxqts/lib/Global.cpp | 83 -- tests/auto/xmlpatternsxqts/lib/Global.h | 128 --- tests/auto/xmlpatternsxqts/lib/ResultThreader.cpp | 76 -- tests/auto/xmlpatternsxqts/lib/ResultThreader.h | 110 --- tests/auto/xmlpatternsxqts/lib/TestBaseLine.cpp | 511 ------------ tests/auto/xmlpatternsxqts/lib/TestBaseLine.h | 212 ----- tests/auto/xmlpatternsxqts/lib/TestCase.cpp | 439 ---------- tests/auto/xmlpatternsxqts/lib/TestCase.h | 256 ------ tests/auto/xmlpatternsxqts/lib/TestContainer.cpp | 151 ---- tests/auto/xmlpatternsxqts/lib/TestContainer.h | 123 --- tests/auto/xmlpatternsxqts/lib/TestGroup.cpp | 143 ---- tests/auto/xmlpatternsxqts/lib/TestGroup.h | 93 --- tests/auto/xmlpatternsxqts/lib/TestItem.h | 133 --- tests/auto/xmlpatternsxqts/lib/TestResult.cpp | 158 ---- tests/auto/xmlpatternsxqts/lib/TestResult.h | 179 ---- .../auto/xmlpatternsxqts/lib/TestResultHandler.cpp | 98 --- tests/auto/xmlpatternsxqts/lib/TestResultHandler.h | 115 --- tests/auto/xmlpatternsxqts/lib/TestSuite.cpp | 269 ------ tests/auto/xmlpatternsxqts/lib/TestSuite.h | 160 ---- .../auto/xmlpatternsxqts/lib/TestSuiteHandler.cpp | 312 ------- tests/auto/xmlpatternsxqts/lib/TestSuiteHandler.h | 169 ---- tests/auto/xmlpatternsxqts/lib/TestSuiteResult.cpp | 173 ---- tests/auto/xmlpatternsxqts/lib/TestSuiteResult.h | 93 --- tests/auto/xmlpatternsxqts/lib/TreeItem.cpp | 62 -- tests/auto/xmlpatternsxqts/lib/TreeItem.h | 114 --- tests/auto/xmlpatternsxqts/lib/TreeModel.cpp | 184 ----- tests/auto/xmlpatternsxqts/lib/TreeModel.h | 110 --- tests/auto/xmlpatternsxqts/lib/Worker.cpp | 258 ------ tests/auto/xmlpatternsxqts/lib/Worker.h | 100 --- tests/auto/xmlpatternsxqts/lib/XMLWriter.cpp | 669 --------------- tests/auto/xmlpatternsxqts/lib/XMLWriter.h | 403 --------- tests/auto/xmlpatternsxqts/lib/XQTSTestCase.cpp | 286 ------- tests/auto/xmlpatternsxqts/lib/XQTSTestCase.h | 149 ---- tests/auto/xmlpatternsxqts/lib/XSDTSTestCase.cpp | 375 --------- tests/auto/xmlpatternsxqts/lib/XSDTSTestCase.h | 161 ---- .../xmlpatternsxqts/lib/XSDTestSuiteHandler.cpp | 910 --------------------- .../auto/xmlpatternsxqts/lib/XSDTestSuiteHandler.h | 121 --- .../xmlpatternsxqts/lib/XSLTTestSuiteHandler.cpp | 234 ------ .../xmlpatternsxqts/lib/XSLTTestSuiteHandler.h | 158 ---- .../lib/docs/XMLIndenterExample.cpp | 63 -- .../lib/docs/XMLIndenterExampleResult.xml | 3 - .../xmlpatternsxqts/lib/docs/XMLWriterExample.cpp | 63 -- .../lib/docs/XMLWriterExampleResult.xml | 3 - tests/auto/xmlpatternsxqts/lib/lib.pro | 88 -- .../xmlpatternsxqts/lib/tests/XMLWriterTest.cpp | 186 ----- .../auto/xmlpatternsxqts/lib/tests/XMLWriterTest.h | 77 -- tests/auto/xmlpatternsxqts/test/test.pro | 26 - tests/auto/xmlpatternsxqts/test/tst_suitetest.cpp | 175 ---- tests/auto/xmlpatternsxqts/test/tst_suitetest.h | 107 --- .../xmlpatternsxqts/test/tst_xmlpatternsxqts.cpp | 106 --- tests/auto/xmlpatternsxqts/tst_suitetest.cpp | 175 ++++ tests/auto/xmlpatternsxqts/tst_suitetest.h | 107 +++ tests/auto/xmlpatternsxqts/tst_xmlpatternsxqts.cpp | 106 +++ tests/auto/xmlpatternsxqts/xmlpatternsxqts.pro | 26 +- tests/auto/xmlpatternsxslts/xmlpatternsxslts.pro | 14 +- 141 files changed, 11906 insertions(+), 11947 deletions(-) delete mode 100644 tests/auto/xmlpatternsdiagnosticsts/test/test.pro delete mode 100644 tests/auto/xmlpatternsdiagnosticsts/test/tst_xmlpatternsdiagnosticsts.cpp create mode 100644 tests/auto/xmlpatternsdiagnosticsts/tst_xmlpatternsdiagnosticsts.cpp create mode 100644 tests/auto/xmlpatternssdk/ASTItem.cpp create mode 100644 tests/auto/xmlpatternssdk/ASTItem.h create mode 100644 tests/auto/xmlpatternssdk/DebugExpressionFactory.cpp create mode 100644 tests/auto/xmlpatternssdk/DebugExpressionFactory.h create mode 100644 tests/auto/xmlpatternssdk/ErrorHandler.cpp create mode 100644 tests/auto/xmlpatternssdk/ErrorHandler.h create mode 100644 tests/auto/xmlpatternssdk/ErrorItem.cpp create mode 100644 tests/auto/xmlpatternssdk/ErrorItem.h create mode 100644 tests/auto/xmlpatternssdk/ExitCode.h create mode 100644 tests/auto/xmlpatternssdk/ExpressionInfo.cpp create mode 100644 tests/auto/xmlpatternssdk/ExpressionInfo.h create mode 100644 tests/auto/xmlpatternssdk/ExpressionNamer.cpp create mode 100644 tests/auto/xmlpatternssdk/ExpressionNamer.h create mode 100644 tests/auto/xmlpatternssdk/ExternalSourceLoader.cpp create mode 100644 tests/auto/xmlpatternssdk/ExternalSourceLoader.h create mode 100644 tests/auto/xmlpatternssdk/Global.cpp create mode 100644 tests/auto/xmlpatternssdk/Global.h create mode 100644 tests/auto/xmlpatternssdk/ResultThreader.cpp create mode 100644 tests/auto/xmlpatternssdk/ResultThreader.h create mode 100644 tests/auto/xmlpatternssdk/TestBaseLine.cpp create mode 100644 tests/auto/xmlpatternssdk/TestBaseLine.h create mode 100644 tests/auto/xmlpatternssdk/TestCase.cpp create mode 100644 tests/auto/xmlpatternssdk/TestCase.h create mode 100644 tests/auto/xmlpatternssdk/TestContainer.cpp create mode 100644 tests/auto/xmlpatternssdk/TestContainer.h create mode 100644 tests/auto/xmlpatternssdk/TestGroup.cpp create mode 100644 tests/auto/xmlpatternssdk/TestGroup.h create mode 100644 tests/auto/xmlpatternssdk/TestItem.h create mode 100644 tests/auto/xmlpatternssdk/TestResult.cpp create mode 100644 tests/auto/xmlpatternssdk/TestResult.h create mode 100644 tests/auto/xmlpatternssdk/TestResultHandler.cpp create mode 100644 tests/auto/xmlpatternssdk/TestResultHandler.h create mode 100644 tests/auto/xmlpatternssdk/TestSuite.cpp create mode 100644 tests/auto/xmlpatternssdk/TestSuite.h create mode 100644 tests/auto/xmlpatternssdk/TestSuiteHandler.cpp create mode 100644 tests/auto/xmlpatternssdk/TestSuiteHandler.h create mode 100644 tests/auto/xmlpatternssdk/TestSuiteResult.cpp create mode 100644 tests/auto/xmlpatternssdk/TestSuiteResult.h create mode 100644 tests/auto/xmlpatternssdk/TreeItem.cpp create mode 100644 tests/auto/xmlpatternssdk/TreeItem.h create mode 100644 tests/auto/xmlpatternssdk/TreeModel.cpp create mode 100644 tests/auto/xmlpatternssdk/TreeModel.h create mode 100644 tests/auto/xmlpatternssdk/Worker.cpp create mode 100644 tests/auto/xmlpatternssdk/Worker.h create mode 100644 tests/auto/xmlpatternssdk/XMLWriter.cpp create mode 100644 tests/auto/xmlpatternssdk/XMLWriter.h create mode 100644 tests/auto/xmlpatternssdk/XQTSTestCase.cpp create mode 100644 tests/auto/xmlpatternssdk/XQTSTestCase.h create mode 100644 tests/auto/xmlpatternssdk/XSDTSTestCase.cpp create mode 100644 tests/auto/xmlpatternssdk/XSDTSTestCase.h create mode 100644 tests/auto/xmlpatternssdk/XSDTestSuiteHandler.cpp create mode 100644 tests/auto/xmlpatternssdk/XSDTestSuiteHandler.h create mode 100644 tests/auto/xmlpatternssdk/XSLTTestSuiteHandler.cpp create mode 100644 tests/auto/xmlpatternssdk/XSLTTestSuiteHandler.h create mode 100644 tests/auto/xmlpatternssdk/docs/XMLIndenterExample.cpp create mode 100644 tests/auto/xmlpatternssdk/docs/XMLIndenterExampleResult.xml create mode 100644 tests/auto/xmlpatternssdk/docs/XMLWriterExample.cpp create mode 100644 tests/auto/xmlpatternssdk/docs/XMLWriterExampleResult.xml create mode 100644 tests/auto/xmlpatternssdk/tests/XMLWriterTest.cpp create mode 100644 tests/auto/xmlpatternssdk/tests/XMLWriterTest.h create mode 100644 tests/auto/xmlpatternssdk/xmlpatternssdk.pro delete mode 100644 tests/auto/xmlpatternsview/test/test.pro delete mode 100644 tests/auto/xmlpatternsview/test/tst_xmlpatternsview.cpp create mode 100644 tests/auto/xmlpatternsview/tst_xmlpatternsview.cpp delete mode 100644 tests/auto/xmlpatternsxqts/lib/ASTItem.cpp delete mode 100644 tests/auto/xmlpatternsxqts/lib/ASTItem.h delete mode 100644 tests/auto/xmlpatternsxqts/lib/DebugExpressionFactory.cpp delete mode 100644 tests/auto/xmlpatternsxqts/lib/DebugExpressionFactory.h delete mode 100644 tests/auto/xmlpatternsxqts/lib/ErrorHandler.cpp delete mode 100644 tests/auto/xmlpatternsxqts/lib/ErrorHandler.h delete mode 100644 tests/auto/xmlpatternsxqts/lib/ErrorItem.cpp delete mode 100644 tests/auto/xmlpatternsxqts/lib/ErrorItem.h delete mode 100644 tests/auto/xmlpatternsxqts/lib/ExitCode.h delete mode 100644 tests/auto/xmlpatternsxqts/lib/ExpressionInfo.cpp delete mode 100644 tests/auto/xmlpatternsxqts/lib/ExpressionInfo.h delete mode 100644 tests/auto/xmlpatternsxqts/lib/ExpressionNamer.cpp delete mode 100644 tests/auto/xmlpatternsxqts/lib/ExpressionNamer.h delete mode 100644 tests/auto/xmlpatternsxqts/lib/ExternalSourceLoader.cpp delete mode 100644 tests/auto/xmlpatternsxqts/lib/ExternalSourceLoader.h delete mode 100644 tests/auto/xmlpatternsxqts/lib/Global.cpp delete mode 100644 tests/auto/xmlpatternsxqts/lib/Global.h delete mode 100644 tests/auto/xmlpatternsxqts/lib/ResultThreader.cpp delete mode 100644 tests/auto/xmlpatternsxqts/lib/ResultThreader.h delete mode 100644 tests/auto/xmlpatternsxqts/lib/TestBaseLine.cpp delete mode 100644 tests/auto/xmlpatternsxqts/lib/TestBaseLine.h delete mode 100644 tests/auto/xmlpatternsxqts/lib/TestCase.cpp delete mode 100644 tests/auto/xmlpatternsxqts/lib/TestCase.h delete mode 100644 tests/auto/xmlpatternsxqts/lib/TestContainer.cpp delete mode 100644 tests/auto/xmlpatternsxqts/lib/TestContainer.h delete mode 100644 tests/auto/xmlpatternsxqts/lib/TestGroup.cpp delete mode 100644 tests/auto/xmlpatternsxqts/lib/TestGroup.h delete mode 100644 tests/auto/xmlpatternsxqts/lib/TestItem.h delete mode 100644 tests/auto/xmlpatternsxqts/lib/TestResult.cpp delete mode 100644 tests/auto/xmlpatternsxqts/lib/TestResult.h delete mode 100644 tests/auto/xmlpatternsxqts/lib/TestResultHandler.cpp delete mode 100644 tests/auto/xmlpatternsxqts/lib/TestResultHandler.h delete mode 100644 tests/auto/xmlpatternsxqts/lib/TestSuite.cpp delete mode 100644 tests/auto/xmlpatternsxqts/lib/TestSuite.h delete mode 100644 tests/auto/xmlpatternsxqts/lib/TestSuiteHandler.cpp delete mode 100644 tests/auto/xmlpatternsxqts/lib/TestSuiteHandler.h delete mode 100644 tests/auto/xmlpatternsxqts/lib/TestSuiteResult.cpp delete mode 100644 tests/auto/xmlpatternsxqts/lib/TestSuiteResult.h delete mode 100644 tests/auto/xmlpatternsxqts/lib/TreeItem.cpp delete mode 100644 tests/auto/xmlpatternsxqts/lib/TreeItem.h delete mode 100644 tests/auto/xmlpatternsxqts/lib/TreeModel.cpp delete mode 100644 tests/auto/xmlpatternsxqts/lib/TreeModel.h delete mode 100644 tests/auto/xmlpatternsxqts/lib/Worker.cpp delete mode 100644 tests/auto/xmlpatternsxqts/lib/Worker.h delete mode 100644 tests/auto/xmlpatternsxqts/lib/XMLWriter.cpp delete mode 100644 tests/auto/xmlpatternsxqts/lib/XMLWriter.h delete mode 100644 tests/auto/xmlpatternsxqts/lib/XQTSTestCase.cpp delete mode 100644 tests/auto/xmlpatternsxqts/lib/XQTSTestCase.h delete mode 100644 tests/auto/xmlpatternsxqts/lib/XSDTSTestCase.cpp delete mode 100644 tests/auto/xmlpatternsxqts/lib/XSDTSTestCase.h delete mode 100644 tests/auto/xmlpatternsxqts/lib/XSDTestSuiteHandler.cpp delete mode 100644 tests/auto/xmlpatternsxqts/lib/XSDTestSuiteHandler.h delete mode 100644 tests/auto/xmlpatternsxqts/lib/XSLTTestSuiteHandler.cpp delete mode 100644 tests/auto/xmlpatternsxqts/lib/XSLTTestSuiteHandler.h delete mode 100644 tests/auto/xmlpatternsxqts/lib/docs/XMLIndenterExample.cpp delete mode 100644 tests/auto/xmlpatternsxqts/lib/docs/XMLIndenterExampleResult.xml delete mode 100644 tests/auto/xmlpatternsxqts/lib/docs/XMLWriterExample.cpp delete mode 100644 tests/auto/xmlpatternsxqts/lib/docs/XMLWriterExampleResult.xml delete mode 100644 tests/auto/xmlpatternsxqts/lib/lib.pro delete mode 100644 tests/auto/xmlpatternsxqts/lib/tests/XMLWriterTest.cpp delete mode 100644 tests/auto/xmlpatternsxqts/lib/tests/XMLWriterTest.h delete mode 100644 tests/auto/xmlpatternsxqts/test/test.pro delete mode 100644 tests/auto/xmlpatternsxqts/test/tst_suitetest.cpp delete mode 100644 tests/auto/xmlpatternsxqts/test/tst_suitetest.h delete mode 100644 tests/auto/xmlpatternsxqts/test/tst_xmlpatternsxqts.cpp create mode 100644 tests/auto/xmlpatternsxqts/tst_suitetest.cpp create mode 100644 tests/auto/xmlpatternsxqts/tst_suitetest.h create mode 100644 tests/auto/xmlpatternsxqts/tst_xmlpatternsxqts.cpp diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro index 9961e25..af9832c 100644 --- a/tests/auto/auto.pro +++ b/tests/auto/auto.pro @@ -518,15 +518,16 @@ SUBDIRS += checkxmlfiles \ xmlpatternsdiagnosticsts \ xmlpatternsschema \ xmlpatternsschemats \ + xmlpatternssdk \ xmlpatternsvalidator \ xmlpatternsview \ xmlpatternsxqts \ xmlpatternsxslts -xmlpatternsdiagnosticsts.depends = xmlpatternsxqts -xmlpatternsview.depends = xmlpatternsxqts -xmlpatternsxslts.depends = xmlpatternsxqts -xmlpatternsschemats.depends = xmlpatternsxqts +xmlpatternsdiagnosticsts.depends = xmlpatternssdk +xmlpatternsview.depends = xmlpatternssdk +xmlpatternsxslts.depends = xmlpatternssdk +xmlpatternsschemats.depends = xmlpatternssdk } unix:!embedded:contains(QT_CONFIG, dbus):SUBDIRS += \ diff --git a/tests/auto/xmlpatternsdiagnosticsts/test/test.pro b/tests/auto/xmlpatternsdiagnosticsts/test/test.pro deleted file mode 100644 index acd71e4..0000000 --- a/tests/auto/xmlpatternsdiagnosticsts/test/test.pro +++ /dev/null @@ -1,32 +0,0 @@ -load(qttest_p4) -SOURCES += tst_xmlpatternsdiagnosticsts.cpp \ - ../../qxmlquery/TestFundament.cpp - -include (../../xmlpatterns.pri) - -TARGET = tst_xmlpatternsdiagnosticsts -DESTDIR = .. -win32 { - CONFIG(debug, debug|release): DESTDIR = ../debug - else: DESTDIR = ../release -} - -contains(QT_CONFIG, xmlpatterns) { -HEADERS += ../../xmlpatternsxqts/test/tst_suitetest.h -SOURCES += ../../xmlpatternsxqts/test/tst_suitetest.cpp -LIBS += -l$$XMLPATTERNS_SDK -} - -QT += xml - -INCLUDEPATH += $$(QTSRCDIR)/tests/auto/xmlpatternsxqts/lib/ \ - $$(QTDIR)/include/QtXmlPatterns/private \ - $$(QTSRCDIR)/tests/auto/xmlpatternsxqts/test \ - ../../xmlpatternsxqts/test \ - ../../xmlpatternsxqts/lib - -wince*|symbian { - catalog.sources = ../TestSuite ../Baseline.xml - catalog.path = . - DEPLOYMENT += catalog -} diff --git a/tests/auto/xmlpatternsdiagnosticsts/test/tst_xmlpatternsdiagnosticsts.cpp b/tests/auto/xmlpatternsdiagnosticsts/test/tst_xmlpatternsdiagnosticsts.cpp deleted file mode 100644 index 4a11404..0000000 --- a/tests/auto/xmlpatternsdiagnosticsts/test/tst_xmlpatternsdiagnosticsts.cpp +++ /dev/null @@ -1,80 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 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 - -#ifdef QTEST_XMLPATTERNS - -#include "tst_suitetest.h" - -/*! - \class tst_XmlPatternsDiagnosticsTS - \internal - \since 4.5 - \brief Test QtXmlPatterns test suite driver in tests/auto/xmlpatternsxqts/lib/. - */ -class tst_XmlPatternsXSLTS : public tst_SuiteTest -{ - Q_OBJECT -public: - tst_XmlPatternsXSLTS(); -protected: - virtual void catalogPath(QString &write) const; -}; - -tst_XmlPatternsXSLTS::tst_XmlPatternsXSLTS() : tst_SuiteTest(tst_SuiteTest::XQuerySuite, true) -{ -} - -void tst_XmlPatternsXSLTS::catalogPath(QString &write) const -{ - write = QLatin1String("TestSuite/DiagnosticsCatalog.xml"); -} - -QTEST_MAIN(tst_XmlPatternsXSLTS) - -#include "tst_xmlpatternsdiagnosticsts.moc" -#else -QTEST_NOOP_MAIN -#endif - -// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternsdiagnosticsts/tst_xmlpatternsdiagnosticsts.cpp b/tests/auto/xmlpatternsdiagnosticsts/tst_xmlpatternsdiagnosticsts.cpp new file mode 100644 index 0000000..4a11404 --- /dev/null +++ b/tests/auto/xmlpatternsdiagnosticsts/tst_xmlpatternsdiagnosticsts.cpp @@ -0,0 +1,80 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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 + +#ifdef QTEST_XMLPATTERNS + +#include "tst_suitetest.h" + +/*! + \class tst_XmlPatternsDiagnosticsTS + \internal + \since 4.5 + \brief Test QtXmlPatterns test suite driver in tests/auto/xmlpatternsxqts/lib/. + */ +class tst_XmlPatternsXSLTS : public tst_SuiteTest +{ + Q_OBJECT +public: + tst_XmlPatternsXSLTS(); +protected: + virtual void catalogPath(QString &write) const; +}; + +tst_XmlPatternsXSLTS::tst_XmlPatternsXSLTS() : tst_SuiteTest(tst_SuiteTest::XQuerySuite, true) +{ +} + +void tst_XmlPatternsXSLTS::catalogPath(QString &write) const +{ + write = QLatin1String("TestSuite/DiagnosticsCatalog.xml"); +} + +QTEST_MAIN(tst_XmlPatternsXSLTS) + +#include "tst_xmlpatternsdiagnosticsts.moc" +#else +QTEST_NOOP_MAIN +#endif + +// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternsdiagnosticsts/xmlpatternsdiagnosticsts.pro b/tests/auto/xmlpatternsdiagnosticsts/xmlpatternsdiagnosticsts.pro index 3d82eaf..981adab 100644 --- a/tests/auto/xmlpatternsdiagnosticsts/xmlpatternsdiagnosticsts.pro +++ b/tests/auto/xmlpatternsdiagnosticsts/xmlpatternsdiagnosticsts.pro @@ -1,5 +1,27 @@ -TEMPLATE = subdirs -CONFIG += ordered +load(qttest_p4) +SOURCES += tst_xmlpatternsdiagnosticsts.cpp \ + ../qxmlquery/TestFundament.cpp -SUBDIRS = ../xmlpatternsxqts test -requires(contains(QT_CONFIG,private_tests)) +include (../xmlpatterns.pri) + +TARGET = tst_xmlpatternsdiagnosticsts + +contains(QT_CONFIG, xmlpatterns) { +HEADERS += ../xmlpatternsxqts/tst_suitetest.h +SOURCES += ../xmlpatternsxqts/tst_suitetest.cpp +LIBS += -l$$XMLPATTERNS_SDK +} + +QT += xml + +INCLUDEPATH += $$(QTSRCDIR)/tests/auto/xmlpatternssdk \ + $$(QTDIR)/include/QtXmlPatterns/private \ + $$(QTSRCDIR)/tests/auto/xmlpatternsxqts \ + ../xmlpatternsxqts \ + ../xmlpatternssdk + +wince*|symbian { + catalog.sources = TestSuite Baseline.xml + catalog.path = . + DEPLOYMENT += catalog +} diff --git a/tests/auto/xmlpatternsschemats/xmlpatternsschemats.pro b/tests/auto/xmlpatternsschemats/xmlpatternsschemats.pro index 0f55078..f36211e 100644 --- a/tests/auto/xmlpatternsschemats/xmlpatternsschemats.pro +++ b/tests/auto/xmlpatternsschemats/xmlpatternsschemats.pro @@ -5,8 +5,8 @@ SOURCES += tst_xmlpatternsschemats.cpp \ include (../xmlpatterns.pri) contains(QT_CONFIG,xmlpatterns) { -HEADERS += ../xmlpatternsxqts/test/tst_suitetest.h -SOURCES += ../xmlpatternsxqts/test/tst_suitetest.cpp +HEADERS += ../xmlpatternsxqts/tst_suitetest.h +SOURCES += ../xmlpatternsxqts/tst_suitetest.cpp } PATTERNIST_SDK = QtXmlPatternsSDK @@ -20,8 +20,8 @@ LIBS += -l$$PATTERNIST_SDK QT += xml -INCLUDEPATH += $$QT_SOURCE_TREE/tests/auto/xmlpatternsxqts/lib/ \ - $$QT_BUILD_TREE/include/QtXmlPatterns/private \ - $$QT_SOURCE_TREE/tests/auto/xmlpatternsxqts/test \ - ../xmlpatternsxqts/test \ - ../xmlpatternsxqts/lib +INCLUDEPATH += $$QT_SOURCE_TREE/tests/auto/xmlpatternssdk/ \ + $$QT_BUILD_TREE/include/QtXmlPatterns/private \ + $$QT_SOURCE_TREE/tests/auto/xmlpatternsxqts \ + ../xmlpatternsxqts \ + ../xmlpatternssdk diff --git a/tests/auto/xmlpatternssdk/ASTItem.cpp b/tests/auto/xmlpatternssdk/ASTItem.cpp new file mode 100644 index 0000000..3b4fbdc --- /dev/null +++ b/tests/auto/xmlpatternssdk/ASTItem.cpp @@ -0,0 +1,161 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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 + +#include "ASTItem.h" + +using namespace QPatternistSDK; + +/** + * This is what the AST rendering is indented with. + */ +static const QLatin1String astIndent(" "); +// STATIC DATA + +ASTItem::ASTItem(ASTItem *p, + const QString &name, + const QString &details, + const QString &staticType, + const QString &reqType) : m_name(name), + m_details(details), + m_reqType(reqType), + m_staticType(staticType), + m_parent(p) +{ +} + +ASTItem::~ASTItem() +{ + qDeleteAll(m_children); +} + +QString ASTItem::toString() const +{ + /* The first ASTItem* is a virtual root node, so skip "this". */ + Q_ASSERT(m_children.count() == 1); + TreeItem *treeChild = m_children.first(); + Q_ASSERT(treeChild); + + ASTItem *astChild = static_cast(treeChild); + + return astChild->toString(QString()); +} + +QString ASTItem::toString(const QString &indent) const +{ + QString retval; + + retval += indent; + retval += m_name; + retval += QLatin1Char('('); + retval += m_details; + retval += QLatin1String(")\n"); + + const TreeItem::List::const_iterator end(m_children.constEnd()); + + for(TreeItem::List::const_iterator it(m_children.constBegin()); it != end; ++it) + { + TreeItem *treeChild = *it; /* Cast away the QPointer with its casting operator. */ + ASTItem *astChild = static_cast(treeChild); + + retval += astChild->toString(indent + astIndent); + } + + return retval; +} + +QVariant ASTItem::data(const Qt::ItemDataRole role, int column) const +{ + if(role != Qt::DisplayRole) + return QVariant(); + + switch(column) + { + case 0: + return m_name; + case 1: + return m_details; + case 2: + return m_staticType; + case 3: + return m_reqType; + default: + { + Q_ASSERT(false); + return QVariant(); + } + } +} + +int ASTItem::columnCount() const +{ + return 4; +} + +TreeItem::List ASTItem::children() const +{ + return m_children; +} + +void ASTItem::appendChild(TreeItem *item) +{ + m_children.append(item); +} + +TreeItem *ASTItem::child(const unsigned int rowP) const +{ + return m_children.value(rowP); +} + +unsigned int ASTItem::childCount() const +{ + return m_children.count(); +} + +TreeItem *ASTItem::parent() const +{ + return m_parent; +} + +// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternssdk/ASTItem.h b/tests/auto/xmlpatternssdk/ASTItem.h new file mode 100644 index 0000000..ca3ac8f --- /dev/null +++ b/tests/auto/xmlpatternssdk/ASTItem.h @@ -0,0 +1,115 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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$ +** +****************************************************************************/ + +#ifndef PatternistSDK_ASTItem_H +#define PatternistSDK_ASTItem_H + +#include +#include + +#include "TreeItem.h" +#include "Global.h" + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +namespace QPatternistSDK +{ + /** + * @short Is a node in a ASTItem tree; each ASTItem contains + * debug information about an QPatternist::Expression. + * + * ASTItem, by implementing TreeItem, leverages debug data about QPatternist::Expression + * instances into Qt's model/view framework. + * + * @ingroup PatternistSDK + * @author Frans Englich + */ + class Q_PATTERNISTSDK_EXPORT ASTItem : public TreeItem + { + public: + virtual ~ASTItem(); + ASTItem(ASTItem *parent, + const QString &name, + const QString &details = QString(), + const QString &staticType = QString(), + const QString &reqType = QString()); + + virtual void appendChild(TreeItem *item); + virtual TreeItem *child(const unsigned int row) const; + virtual unsigned int childCount() const; + virtual QVariant data(const Qt::ItemDataRole role, int column) const; + virtual TreeItem::List children() const; + virtual TreeItem *parent() const; + int columnCount() const; + + /** + * Returns a string representation of this AST node, recursively including + * children. For example, the query 1 eq number() would result in the string: + * +@verbatim +ValueComparison(eq) + xs:integer(0) + FunctionCall(fn:number) + ContextItem +@endverbatim + */ + QString toString() const; + + private: + QString toString(const QString &indent) const; + + const QString m_name; + const QString m_details; + const QString m_reqType; + const QString m_staticType; + TreeItem::List m_children; + TreeItem *m_parent; + }; +} + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif +// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternssdk/DebugExpressionFactory.cpp b/tests/auto/xmlpatternssdk/DebugExpressionFactory.cpp new file mode 100644 index 0000000..1b5121e --- /dev/null +++ b/tests/auto/xmlpatternssdk/DebugExpressionFactory.cpp @@ -0,0 +1,264 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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 +#include + +#include "qfunctionfactorycollection_p.h" + +#include "ASTItem.h" +#include "ExpressionInfo.h" +#include "ExpressionNamer.h" +#include "Global.h" + +#include "DebugExpressionFactory.h" + +using namespace QPatternistSDK; +using namespace QPatternist; + +static const QPatternist::ExpressionVisitor::Ptr namer(new ExpressionNamer()); + +QStringList DebugExpressionFactory::availableFunctionSignatures() +{ + const QPatternist::FunctionFactory::Ptr factory(QPatternist::FunctionFactoryCollection::xpath20Factory(Global::namePool())); + const QPatternist::FunctionSignature::Hash signs(factory->functionSignatures()); + const QPatternist::FunctionSignature::Hash::const_iterator end(signs.constEnd()); + QPatternist::FunctionSignature::Hash::const_iterator it(signs.constBegin()); + QStringList retval; + + while(it != end) + { + retval << it.value()->displayName(Global::namePool()); + ++it; + } + + return retval; +} + +ASTItem *DebugExpressionFactory::buildASTTree(const QPatternist::Expression::Ptr &expr, + ASTItem *parent, + const QPatternist::SequenceType::Ptr &reqType) +{ + Q_ASSERT(expr); + const QPatternist::ExpressionVisitorResult::Ptr exprInfo(expr->accept(namer)); + Q_ASSERT(exprInfo); + const ExpressionInfo *const constExprInfo = static_cast(exprInfo.data()); + const QString name(constExprInfo->first); + const QString details(constExprInfo->second); + const QString rType(reqType ? reqType->displayName(Global::namePool()) : QLatin1String("Not specified")); + + /* ---------- Handle its staticType() -------- */ + const QPatternist::SequenceType::Ptr type(expr->staticType()); + QString seqType; + + if(type) + seqType = type->displayName(Global::namePool()); + else + seqType = QLatin1String("no type, null pointer returned"); + /* ------------------------------------------- */ + + ASTItem *const node = new ASTItem(parent, name, details, seqType, rType); + + /* ------------ Handle child nodes ----------- */ + const QPatternist::Expression::List children(expr->operands()); + QPatternist::Expression::List::const_iterator it(children.constBegin()); + const QPatternist::Expression::List::const_iterator end(children.constEnd()); + + const QPatternist::SequenceType::List reqTypes(expr->expectedOperandTypes()); + const QPatternist::SequenceType::List::const_iterator typeEnd(reqTypes.constEnd()); + QPatternist::SequenceType::List::const_iterator typeIt(reqTypes.constBegin()); + QPatternist::SequenceType::Ptr t; + + for(; it != end; ++it) + { + if(typeIt != typeEnd) + { + t = *typeIt; + ++typeIt; + } + + node->appendChild(buildASTTree(*it, node, t)); + } + /* ------------------------------------------- */ + + return node; +} + +QPatternist::Expression::Ptr +DebugExpressionFactory::createExpression(QIODevice *const expr, + const QPatternist::StaticContext::Ptr &context, + const QXmlQuery::QueryLanguage lang, + const QPatternist::SequenceType::Ptr &requiredType, + const QUrl &baseURI, + const QXmlName &initialTemplateName) +{ + /* Create the root node. */ + m_ast = new ASTItem(0, QString()); + + return ExpressionFactory::createExpression(expr, context, lang, requiredType, baseURI, initialTemplateName); +} + +void DebugExpressionFactory::processTreePass(const QPatternist::Expression::Ptr &expr, + const CompilationStage stage) +{ + ASTItem *newChild = 0; + + switch(stage) + { + case QueryBodyInitial: + { + newChild = new ASTItem(m_ast, QLatin1String("Initial Build")); + break; + } + case QueryBodyTypeCheck: + { + newChild = new ASTItem(m_ast, QLatin1String("Type Check")); + break; + } + case QueryBodyCompression: + { + newChild = new ASTItem(m_ast, QLatin1String("Compression")); + break; + } + case UserFunctionTypeCheck: + { + newChild = new ASTItem(m_ast, QLatin1String("User Function Type Check")); + break; + } + case UserFunctionCompression: + { + newChild = new ASTItem(m_ast, QLatin1String("User Function Compression")); + break; + } + case GlobalVariableTypeCheck: + { + newChild = new ASTItem(m_ast, QLatin1String("Global Variable Type Check")); + break; + } + } + + Q_ASSERT(newChild); + m_ast->appendChild(newChild); + newChild->appendChild(buildASTTree(expr, newChild, QPatternist::SequenceType::Ptr())); +} + +void DebugExpressionFactory::processTemplateRule(const Expression::Ptr &body, + const TemplatePattern::Ptr &pattern, + const QXmlName &mode, + const TemplateCompilationStage stage) +{ + const char * title; + + switch(stage) + { + case TemplateInitial: + { + title = "Initial Build"; + break; + } + case TemplateTypeCheck: + { + title = "Type Check"; + break; + } + case TemplateCompress: + { + title = "Compression"; + break; + } + } + + const QString modeName(Global::namePool()->displayName(mode)); + Q_ASSERT(title); + ASTItem *const newChild = new ASTItem(m_ast, QLatin1String("T-Rule ") + + QLatin1String(title) + + QLatin1String(" mode: ") + + modeName + + QLatin1String(" priority: ") + + QString::number(pattern->priority())); + m_ast->appendChild(newChild); + + newChild->appendChild(buildASTTree(pattern->matchPattern(), newChild, QPatternist::SequenceType::Ptr())); + newChild->appendChild(buildASTTree(body, newChild, QPatternist::SequenceType::Ptr())); +} + +void DebugExpressionFactory::processNamedTemplate(const QXmlName &name, + const Expression::Ptr &body, + const TemplateCompilationStage stage) +{ + const char * title; + + switch(stage) + { + case TemplateInitial: + { + title = "Named Template Initial Build"; + break; + } + case TemplateTypeCheck: + { + title = "Named Template Type Check"; + break; + } + case TemplateCompress: + { + title = "Named Template Compression"; + break; + } + } + + Q_ASSERT(title); + ASTItem *const newChild = new ASTItem(m_ast, QLatin1String(title) + + QLatin1String(": ") + + Global::namePool()->displayName(name)); + + m_ast->appendChild(newChild); + newChild->appendChild(buildASTTree(body, newChild, QPatternist::SequenceType::Ptr())); +} + +ASTItem *DebugExpressionFactory::astTree() const +{ + return m_ast; +} + +// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternssdk/DebugExpressionFactory.h b/tests/auto/xmlpatternssdk/DebugExpressionFactory.h new file mode 100644 index 0000000..d5e676d --- /dev/null +++ b/tests/auto/xmlpatternssdk/DebugExpressionFactory.h @@ -0,0 +1,128 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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$ +** +****************************************************************************/ + +#ifndef PatternistSDK_DebugExpressionFactory_H +#define PatternistSDK_DebugExpressionFactory_H + +#include "Global.h" +#include "qexpressionfactory_p.h" +#include "qfunctionfactory_p.h" + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +namespace QPatternistSDK +{ + class ASTItem; + + /** + * @short Is a QPatternist::ExpressionFactory, with the + * difference that it provides the hooks for building from a tree of + * debug data from the compiled expression. + * + * This tree can be retrieved via astTree(). The astTree() function + * returns the AST built the last time createExpression() was called. + * + * @ingroup PatternistSDK + * @author Frans Englich + */ + class Q_PATTERNISTSDK_EXPORT DebugExpressionFactory : public QPatternist::ExpressionFactory + { + public: + DebugExpressionFactory() : m_ast(0) + { + } + + typedef QExplicitlySharedDataPointer Ptr; + /** + * Identical to ExpressionFactory::createExpression() with the difference + * that it builds an ASTItem tree which can be accessed via astTree(). + */ + virtual QPatternist::Expression::Ptr createExpression(QIODevice *const expr, + const QPatternist::StaticContext::Ptr &context, + const QXmlQuery::QueryLanguage lang, + const QPatternist::SequenceType::Ptr &requiredType, + const QUrl &queryURI, + const QXmlName &initialTemplateName); + + /** + * @returns an ASTItem tree built for the last created expression, + * via createExpression(). + */ + virtual ASTItem *astTree() const; + + /** + * @returns a list containing string representations of all available + * functions in Patternist. Each QString in the returned QStringList + * is a function synopsis for human consumption. + */ + static QStringList availableFunctionSignatures(); + + protected: + /** + * Performs the ASTItem tree building. + */ + virtual void processTreePass(const QPatternist::Expression::Ptr &tree, + const CompilationStage stage); + + void processTemplateRule(const QPatternist::Expression::Ptr &body, + const QPatternist::TemplatePattern::Ptr &pattern, + const QXmlName &mode, + const TemplateCompilationStage stage); + + void processNamedTemplate(const QXmlName &name, + const QPatternist::Expression::Ptr &body, + const TemplateCompilationStage stage); + private: + static ASTItem *buildASTTree(const QPatternist::Expression::Ptr &expr, + ASTItem *const parent, + const QPatternist::SequenceType::Ptr &reqType); + ASTItem *m_ast; + }; +} + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif +// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternssdk/ErrorHandler.cpp b/tests/auto/xmlpatternssdk/ErrorHandler.cpp new file mode 100644 index 0000000..3f07737 --- /dev/null +++ b/tests/auto/xmlpatternssdk/ErrorHandler.cpp @@ -0,0 +1,166 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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 +#include +#include +#include +#include +#include + +#include "ErrorHandler.h" + +using namespace QPatternistSDK; + +ErrorHandler *ErrorHandler::handler = 0; + +void qMessageHandler(QtMsgType type, const char *description) +{ + if(type == QtDebugMsg) + { + std::fprintf(stderr, "%s\n", description); + return; + } + + QtMsgType t; + + switch(type) + { + case QtWarningMsg: + { + t = QtWarningMsg; + break; + } + case QtCriticalMsg: + { + t = QtFatalMsg; + break; + } + case QtFatalMsg: + { + /* We can't swallow Q_ASSERTs, we need to fail the hard way here. + * But maybe not: when run from "patternistrunsingle" it could be an idea + * to actually try to record it(but nevertheless fail somehow) such + * that it gets reported. */ + std::fprintf(stderr, "Fatal error: %s\n", description); + t = QtFatalMsg; /* Dummy, to silence a bogus compiler warning. */ + return; + } + case QtDebugMsg: /* This enum is handled above in the if-clause. */ + /* Fallthrough. */ + default: + { + Q_ASSERT(false); + return; + } + } + + Q_ASSERT(ErrorHandler::handler); + /* This message is hacky. Ideally, we should do it the same way + * ReportContext::error() constructs messages, but this is just testing + * code. */ + ErrorHandler::handler->message(t, QLatin1String("

") + QPatternist::escape(QLatin1String(description)) + QLatin1String("

")); +} + +void ErrorHandler::installQtMessageHandler(ErrorHandler *const h) +{ + handler = h; + + if(h) + qInstallMsgHandler(qMessageHandler); + else + qInstallMsgHandler(0); +} + +void ErrorHandler::handleMessage(QtMsgType type, + const QString &description, + const QUrl &identifier, + const QSourceLocation &) +{ + /* Don't use pDebug() in this function, it results in infinite + * recursion. Talking from experience.. */ + + Message msg; + msg.setType(type); + msg.setIdentifier(identifier); + + /* Let's remove all the XHTML markup. */ + QBuffer buffer; + buffer.setData(description.toLatin1()); + buffer.open(QIODevice::ReadOnly); + + QXmlQuery query; + query.bindVariable(QLatin1String("desc"), &buffer); + query.setQuery(QLatin1String("string(doc($desc))")); + + QStringList result; + const bool success = query.evaluateTo(&result); + + if(!description.startsWith(QLatin1String("\"Test-suite harness error:"))) + { + const QString msg(QString::fromLatin1("Invalid description: %1").arg(description)); + QVERIFY2(success, qPrintable(msg)); + + if(!success) + QTextStream(stderr) << msg; + } + + + if(!result.isEmpty()) + msg.setDescription(result.first()); + + m_messages.append(msg); +} + +ErrorHandler::Message::List ErrorHandler::messages() const +{ + return m_messages; +} + +void ErrorHandler::reset() +{ + m_messages.clear(); +} + +// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternssdk/ErrorHandler.h b/tests/auto/xmlpatternssdk/ErrorHandler.h new file mode 100644 index 0000000..25447a9 --- /dev/null +++ b/tests/auto/xmlpatternssdk/ErrorHandler.h @@ -0,0 +1,149 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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$ +** +****************************************************************************/ + +#ifndef PatternistSDK_ErrorHandler_H +#define PatternistSDK_ErrorHandler_H + +#include "Global.h" +#include "qabstractmessagehandler.h" + + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +template class QList; + +namespace QPatternistSDK +{ + /** + * @short A MessageHandler which + * accumulates all its received ErrorHandler::Message instances + * in a list, retrievable via messages(). + * + * Thus, ErrorHandler does not report errors, but collects them + * and allows easy access to them. + * + * @ingroup PatternistSDK + * @author Frans Englich + */ + class Q_PATTERNISTSDK_EXPORT ErrorHandler : public QAbstractMessageHandler + { + public: + class Message + { + public: + typedef QList List; + + QString description() const + { + return m_description; + } + + void setDescription(const QString &desc) + { + m_description = desc; + } + + void setIdentifier(const QUrl &newId) + { + m_identifier = newId; + } + + QUrl identifier() const + { + return m_identifier; + } + + QtMsgType type() const + { + return m_type; + } + + void setType(const QtMsgType t) + { + m_type = t; + } + + private: + QUrl m_identifier; + QtMsgType m_type; + QString m_description; + }; + + /** + * Clears all accumulated errors. + */ + void reset(); + + Message::List messages() const; + + /** + * Calling this function causes all Qt's internal debug messages to be + * sent to @p handler. If @p handler is @c null, Qt's default message + * handler is re-installed. In other words, via an internal proxy function, + * it installs @p handler as Qt's message handler. + * + * If @p handler is heap allocated, it will be leaked. + * + * @see qInstallMsgHandler() + */ + static void installQtMessageHandler(ErrorHandler *const handler); + + static ErrorHandler *handler; + + protected: + virtual void handleMessage(QtMsgType type, + const QString &description, + const QUrl &identifier = QUrl(), + const QSourceLocation &sourceLocation = QSourceLocation()); + + private: + ErrorHandler::Message::List m_messages; + }; +} + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif +// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternssdk/ErrorItem.cpp b/tests/auto/xmlpatternssdk/ErrorItem.cpp new file mode 100644 index 0000000..57edc1f --- /dev/null +++ b/tests/auto/xmlpatternssdk/ErrorItem.cpp @@ -0,0 +1,142 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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 + +#include "qreportcontext_p.h" +#include "qcommonnamespaces_p.h" + +#include "ErrorItem.h" + +using namespace QPatternistSDK; + +QString ErrorItem::toString(const QtMsgType type) +{ + switch(type) + { + case QtWarningMsg: + return QLatin1String("Warning"); + case QtFatalMsg: + return QLatin1String("Error"); + default: + { + Q_ASSERT(false); + return QString(); + } + } +} + +ErrorItem::ErrorItem(const ErrorHandler::Message &error, + ErrorItem *p) : m_message(error), + m_parent(p) +{ +} + +ErrorItem::~ErrorItem() +{ + qDeleteAll(m_children); +} + +int ErrorItem::columnCount() const +{ + return 3; +} + +QVariant ErrorItem::data(const Qt::ItemDataRole role, int column) const +{ + if(role != Qt::DisplayRole) + return QVariant(); + + switch(column) + { + case 0: + return toString(m_message.type()); + case 1: + { + if(!m_message.type()) /* It's a warning, likely. */ + return QString(); + + QString ns; + const QString code(QPatternist::ReportContext::codeFromURI(m_message.identifier().toString(), ns)); + + if(ns == QPatternist::CommonNamespaces::XPERR) + return code; + else /* Do the full version. */ + return m_message.type(); + } + case 2: + return m_message.description(); + default: + { + Q_ASSERT(false); + return QVariant(); + } + } +} + +TreeItem::List ErrorItem::children() const +{ + return m_children; +} + +void ErrorItem::appendChild(TreeItem *item) +{ + m_children.append(item); +} + +TreeItem *ErrorItem::child(const unsigned int rowP) const +{ + return m_children.value(rowP); +} + +unsigned int ErrorItem::childCount() const +{ + return m_children.count(); +} + +TreeItem *ErrorItem::parent() const +{ + return m_parent; +} + +// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternssdk/ErrorItem.h b/tests/auto/xmlpatternssdk/ErrorItem.h new file mode 100644 index 0000000..1d05872 --- /dev/null +++ b/tests/auto/xmlpatternssdk/ErrorItem.h @@ -0,0 +1,94 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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$ +** +****************************************************************************/ + +#ifndef PatternistSDK_ErrorItem_H +#define PatternistSDK_ErrorItem_H + +#include + +#include "ErrorHandler.h" +#include "Global.h" +#include "TreeItem.h" + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +namespace QPatternistSDK +{ + /** + * @short Delegates a ErrorHandler::Message through the interface + * exposed by TreeItem, such that errors from DOM related code + * can be displayed/used in Qt's model/view framework. + * + * @ingroup PatternistSDK + * @author Frans Englich + */ + class Q_PATTERNISTSDK_EXPORT ErrorItem : public TreeItem + { + public: + ErrorItem(const ErrorHandler::Message &error, ErrorItem *parent); + virtual ~ErrorItem(); + + virtual QVariant data(const Qt::ItemDataRole role, int column) const; + + virtual void appendChild(TreeItem *item); + virtual TreeItem *child(const unsigned int row) const; + virtual unsigned int childCount() const; + virtual TreeItem::List children() const; + virtual TreeItem *parent() const; + int columnCount() const; + + private: + static QString toString(const QtMsgType sev); + + const ErrorHandler::Message m_message; + ErrorItem * m_parent; + TreeItem::List m_children; + }; +} + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif +// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternssdk/ExitCode.h b/tests/auto/xmlpatternssdk/ExitCode.h new file mode 100644 index 0000000..e1810b1 --- /dev/null +++ b/tests/auto/xmlpatternssdk/ExitCode.h @@ -0,0 +1,105 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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$ +** +****************************************************************************/ + +#ifndef PatternistSDK_ExitCode_H +#define PatternistSDK_ExitCode_H + +#include "Global.h" + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +namespace QPatternistSDK +{ + /** + * @short Houses program exit codes for PatternistSDK utilities. + * + * @ingroup PatternistSDK + * @author Frans Englich + */ + class Q_PATTERNISTSDK_EXPORT ExitCode + { + public: + /** + * Exit codes for programs part of PatternistSDK. The values for the enums are specified + * to make it easily understandable what number a symbol corresponds to. + */ + enum Code + { + Success = 0, + InvalidArgCount = 1, + InvalidArgs = 2, + + /** + * Used in @c patternistrunsuite + */ + InvalidCatalogFile = 3, + FileNotExists = 4, + OpenError = 5, + WriteError = 6, + + /** + * Used in the test program used for comparing files on the byte level. + */ + NotEqual = 7, + UnevenTestCount = 8, + InternalError = 9, + Regression = 10 + }; + + private: + /** + * This constructor is private and has no implementation, because this + * class is not supposed to be instantiated. + */ + inline ExitCode(); + + Q_DISABLE_COPY(ExitCode) + }; +} + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif +// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternssdk/ExpressionInfo.cpp b/tests/auto/xmlpatternssdk/ExpressionInfo.cpp new file mode 100644 index 0000000..abbc8b3 --- /dev/null +++ b/tests/auto/xmlpatternssdk/ExpressionInfo.cpp @@ -0,0 +1,54 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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 "ExpressionInfo.h" + +using namespace QPatternistSDK; + +ExpressionInfo::ExpressionInfo(const QString &name, + const QString &details) : QPair(name, details) +{ +} + +// vim: et:ts=4:sw=4:sts=4 + diff --git a/tests/auto/xmlpatternssdk/ExpressionInfo.h b/tests/auto/xmlpatternssdk/ExpressionInfo.h new file mode 100644 index 0000000..2d9d398 --- /dev/null +++ b/tests/auto/xmlpatternssdk/ExpressionInfo.h @@ -0,0 +1,80 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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$ +** +****************************************************************************/ + +#ifndef PatternistSDK_ExpressionInfo_H +#define PatternistSDK_ExpressionInfo_H + +#include "Global.h" +#include "qexpressiondispatch_p.h" + +#include +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +namespace QPatternistSDK +{ + /** + * @short Houses debug information about an QPatternist::Expression instance. + * + * An Expression's name, typically its class name, can be retrieved + * via the member variable first, and additional data, for example its string + * value or operator, can be retrieved via the member variable second. + * + * @ingroup PatternistSDK + * @author Frans Englich + */ + class Q_PATTERNISTSDK_EXPORT ExpressionInfo : public QPatternist::ExpressionVisitorResult + , public QPair + { + public: + ExpressionInfo(const QString &name, const QString &details); + }; +} + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif +// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternssdk/ExpressionNamer.cpp b/tests/auto/xmlpatternssdk/ExpressionNamer.cpp new file mode 100644 index 0000000..605c754 --- /dev/null +++ b/tests/auto/xmlpatternssdk/ExpressionNamer.cpp @@ -0,0 +1,316 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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 "qabstractfloat_p.h" +#include "qandexpression_p.h" +#include "qanyuri_p.h" +#include "qapplytemplate_p.h" +#include "qargumentreference_p.h" +#include "qarithmeticexpression_p.h" +#include "qatomicstring_p.h" +#include "qatomizer_p.h" +#include "qattributeconstructor_p.h" +#include "qattributenamevalidator_p.h" +#include "qaxisstep_p.h" +#include "qbase64binary_p.h" +#include "qboolean_p.h" +#include "qcardinalityverifier_p.h" +#include "qcastableas_p.h" +#include "qcastas_p.h" +#include "qcombinenodes_p.h" +#include "qcontextitem_p.h" +#include "qdate_p.h" +#include "qdecimal_p.h" +#include "qdynamiccontextstore_p.h" +#include "qelementconstructor_p.h" +#include "qemptysequence_p.h" +#include "qevaluationcache_p.h" +#include "qexpressionsequence_p.h" +#include "qexpressionvariablereference_p.h" +#include "qfirstitempredicate_p.h" +#include "qforclause_p.h" +#include "qfunctioncall_p.h" +#include "qgday_p.h" +#include "qgeneralcomparison_p.h" +#include "qgenericpredicate_p.h" +#include "qgmonthday_p.h" +#include "qgmonth_p.h" +#include "qgyearmonth_p.h" +#include "qgyear_p.h" +#include "qhexbinary_p.h" +#include "qifthenclause_p.h" +#include "qinstanceof_p.h" +#include "qinteger_p.h" +#include "qitem_p.h" +#include "qitemverifier_p.h" +#include "qliteral_p.h" +#include "qnamespaceconstructor_p.h" +#include "qncnameconstructor_p.h" +#include "qnodecomparison_p.h" +#include "qorexpression_p.h" +#include "qpath_p.h" +#include "qpositionalvariablereference_p.h" +#include "qqnameconstructor_p.h" +#include "qqnamevalue_p.h" +#include "qquantifiedexpression_p.h" +#include "qrangeexpression_p.h" +#include "qrangevariablereference_p.h" +#include "qschemadatetime_p.h" +#include "qschematime_p.h" +#include "qsimplecontentconstructor_p.h" +#include "qtreatas_p.h" +#include "qtruthpredicate_p.h" +#include "quntypedatomicconverter_p.h" +#include "quntypedatomic_p.h" +#include "quserfunctioncallsite_p.h" +#include "qvalidationerror_p.h" +#include "qvaluecomparison_p.h" + +#include "ExpressionInfo.h" +#include "Global.h" + +#include "ExpressionNamer.h" + +using namespace QPatternistSDK; + +/* Simple ones, they have no additional data. */ +#define implClass(cls) \ +QPatternist::ExpressionVisitorResult::Ptr ExpressionNamer::visit(const QPatternist::cls *) const \ +{ \ + return QPatternist::ExpressionVisitorResult::Ptr \ + (new ExpressionInfo(QLatin1String(#cls), QString())); \ +} + +implClass(AndExpression) +implClass(ArgumentConverter) +implClass(Atomizer) +implClass(AttributeConstructor) +implClass(AttributeNameValidator) +implClass(CallTemplate) +implClass(CardinalityVerifier) +implClass(CollationChecker) +implClass(CommentConstructor) +implClass(ComputedNamespaceConstructor) +implClass(ContextItem) +implClass(CopyOf) +implClass(CurrentItemStore) +implClass(DocumentConstructor) +implClass(DynamicContextStore) +implClass(EBVExtractor) +implClass(ElementConstructor) +implClass(EmptySequence) +implClass(ExpressionSequence) +implClass(ExternalVariableReference) +implClass(FirstItemPredicate) +implClass(ForClause) +implClass(GenericPredicate) +implClass(IfThenClause) +implClass(ItemVerifier) +implClass(LetClause) +implClass(LiteralSequence) +implClass(NCNameConstructor) +implClass(NodeSortExpression) +implClass(OrderBy) +implClass(OrExpression) +implClass(ParentNodeAxis) +implClass(ProcessingInstructionConstructor) +implClass(QNameConstructor) +implClass(RangeExpression) +implClass(ReturnOrderBy) +implClass(SimpleContentConstructor) +implClass(StaticBaseURIStore) +implClass(StaticCompatibilityStore) +implClass(TemplateParameterReference) +implClass(TextNodeConstructor) +implClass(TreatAs) +implClass(TruthPredicate) +implClass(UnresolvedVariableReference) +implClass(UntypedAtomicConverter) +implClass(UserFunctionCallsite) +implClass(ValidationError) +#undef implClass + +/** Variable references. */ +#define implVarRef(name) \ +QPatternist::ExpressionVisitorResult::Ptr ExpressionNamer::visit(const QPatternist::name *i) const \ +{ \ + return QPatternist::ExpressionVisitorResult::Ptr \ + (new ExpressionInfo(QLatin1String(#name), \ + QString(QLatin1String("Slot: %1")).arg(i->slot()))); \ +} +implVarRef(RangeVariableReference) +implVarRef(ArgumentReference) +implVarRef(ExpressionVariableReference) +implVarRef(PositionalVariableReference) +#undef implVarRef + +/* Type related classes which have a targetType() function. */ +#define implTypeClass(cls) \ +QPatternist::ExpressionVisitorResult::Ptr ExpressionNamer::visit(const QPatternist::cls *i) const \ +{ \ + return QPatternist::ExpressionVisitorResult::Ptr(new ExpressionInfo(QLatin1String(#cls), \ + i->targetType()->displayName(Global::namePool()))); \ +} + +implTypeClass(InstanceOf) +implTypeClass(CastableAs) +#undef implTypeClass + +/* Type related classes which have a targetType() function. */ +QPatternist::ExpressionVisitorResult::Ptr ExpressionNamer::visit(const QPatternist::CastAs *i) const +{ + return QPatternist::ExpressionVisitorResult::Ptr(new ExpressionInfo(QLatin1String("CastAs"), + i->targetSequenceType()->displayName(Global::namePool()))); +} + +/* Classes which represent operators. */ +#define implOPClass(cls, compClass) \ +QPatternist::ExpressionVisitorResult::Ptr ExpressionNamer::visit(const QPatternist::cls *i) const \ +{ \ + return QPatternist::ExpressionVisitorResult::Ptr(new ExpressionInfo(QLatin1String(#cls), \ + QPatternist::compClass::displayName(i->operatorID()))); \ +} + +implOPClass(ArithmeticExpression, AtomicMathematician) +implOPClass(NodeComparison, NodeComparison) +implOPClass(QuantifiedExpression, QuantifiedExpression) +implOPClass(CombineNodes, CombineNodes) +#undef implOPClass + +/* Classes which represent operators. */ +#define implCompClass(cls, type) \ +QPatternist::ExpressionVisitorResult::Ptr ExpressionNamer::visit(const QPatternist::cls *i) const \ +{ \ + return QPatternist::ExpressionVisitorResult::Ptr(new ExpressionInfo(QLatin1String(#cls), \ + QPatternist::AtomicComparator::displayName(i->operatorID(), \ + QPatternist::AtomicComparator::type))); \ +} + +implCompClass(GeneralComparison, AsGeneralComparison) +implCompClass(ValueComparison, AsValueComparison) +#undef implCompClass + +QPatternist::ExpressionVisitorResult::Ptr ExpressionNamer::visit(const QPatternist::FunctionCall *i) const +{ + return QPatternist::ExpressionVisitorResult::Ptr + (new ExpressionInfo(QLatin1String("FunctionCall"), + Global::namePool()->displayName(i->signature()->name()))); +} + +QPatternist::ExpressionVisitorResult::Ptr ExpressionNamer::visit(const QPatternist::Literal *i) const +{ + return QPatternist::ExpressionVisitorResult::Ptr(new ExpressionInfo( + i->item().type()->displayName(Global::namePool()), + i->item().stringValue())); +} + +QPatternist::ExpressionVisitorResult::Ptr ExpressionNamer::visit(const QPatternist::AxisStep *i) const +{ + return QPatternist::ExpressionVisitorResult::Ptr(new ExpressionInfo(QLatin1String("AxisStep"), + QPatternist::AxisStep::axisName(i->axis()) + + QLatin1String("::") + + i->nodeTest()->displayName(Global::namePool()))); + +} + + +QPatternist::ExpressionVisitorResult::Ptr ExpressionNamer::visit(const QPatternist::EvaluationCache *i) const +{ + return QPatternist::ExpressionVisitorResult::Ptr(new ExpressionInfo(QLatin1String("EvaluationCache"), + QLatin1String("Slot: ") + QString::number(i->slot()))); + +} + +QPatternist::ExpressionVisitorResult::Ptr ExpressionNamer::visit(const QPatternist::EvaluationCache *i) const +{ + return QPatternist::ExpressionVisitorResult::Ptr(new ExpressionInfo(QLatin1String("EvaluationCache"), + QLatin1String("Slot: ") + QString::number(i->slot()))); + +} + +QPatternist::ExpressionVisitorResult::Ptr ExpressionNamer::visit(const QPatternist::NamespaceConstructor *i) const +{ + return QPatternist::ExpressionVisitorResult::Ptr(new ExpressionInfo(QLatin1String("NamespaceConstructor"), + Global::namePool()->stringForPrefix(i->namespaceBinding().prefix()) + + QLatin1Char('=') + + Global::namePool()->stringForNamespace(i->namespaceBinding().namespaceURI()))); + +} + +QPatternist::ExpressionVisitorResult::Ptr ExpressionNamer::visit(const QPatternist::Path *path) const +{ + + QPatternist::Path::Kind k = path->kind(); + QString type; + + switch(k) + { + case QPatternist::Path::XSLTForEach: + { + type = QLatin1String("XSLTForEach"); + break; + } + case QPatternist::Path::RegularPath: + { + type = QLatin1String("RegularPath"); + break; + } + case QPatternist::Path::ForApplyTemplate: + { + type = QLatin1String("ForApplyTemplate"); + break; + } + } + + return QPatternist::ExpressionVisitorResult::Ptr(new ExpressionInfo(QLatin1String("Path"), type)); +} + +QPatternist::ExpressionVisitorResult::Ptr ExpressionNamer::visit(const QPatternist::ApplyTemplate *path) const +{ + const QPatternist::TemplateMode::Ptr mode(path->mode()); + return QPatternist::ExpressionVisitorResult::Ptr + (new ExpressionInfo(QLatin1String("ApplyTemplate"), mode ? Global::namePool()->displayName(mode->name()) : QString::fromLatin1("#current"))); +} + +// vim: et:ts=4:sw=4:sts=4 + diff --git a/tests/auto/xmlpatternssdk/ExpressionNamer.h b/tests/auto/xmlpatternssdk/ExpressionNamer.h new file mode 100644 index 0000000..129d8d7 --- /dev/null +++ b/tests/auto/xmlpatternssdk/ExpressionNamer.h @@ -0,0 +1,281 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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$ +** +****************************************************************************/ + +#ifndef PatternistSDK_ExpressionNamer_H +#define PatternistSDK_ExpressionNamer_H + +#include "Global.h" +#include "qexpressiondispatch_p.h" + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +namespace QPatternistSDK +{ + /** + * @short Extracts debug information from a QPatternist::Expression tree. + * + * This data is the name of the AST node(typically the class name), + * and additional data such as the value, type of operator, and so forth. The result + * is returned(from visit()), is an ExpressionInfo instance. + * + * @see ExpressionInfo + * @see ASTItem + * @ingroup PatternistSDK + * @author Frans Englich + */ + class Q_PATTERNISTSDK_EXPORT ExpressionNamer : public QPatternist::ExpressionVisitor + { + public: + + virtual QPatternist::ExpressionVisitorResult::Ptr + visit(const QPatternist::AndExpression *) const; + + virtual QPatternist::ExpressionVisitorResult::Ptr + visit(const QPatternist::ApplyTemplate *) const; + + virtual QPatternist::ExpressionVisitorResult::Ptr + visit(const QPatternist::ArgumentReference *) const; + + virtual QPatternist::ExpressionVisitorResult::Ptr + visit(const QPatternist::ArithmeticExpression *) const; + + virtual QPatternist::ExpressionVisitorResult::Ptr + visit(const QPatternist::Atomizer *) const; + + virtual QPatternist::ExpressionVisitorResult::Ptr + visit(const QPatternist::AttributeConstructor *) const; + + virtual QPatternist::ExpressionVisitorResult::Ptr + visit(const QPatternist::AttributeNameValidator *) const; + + virtual QPatternist::ExpressionVisitorResult::Ptr + visit(const QPatternist::CallTemplate *) const; + + virtual QPatternist::ExpressionVisitorResult::Ptr + visit(const QPatternist::CardinalityVerifier *) const; + + virtual QPatternist::ExpressionVisitorResult::Ptr + visit(const QPatternist::CastAs *) const; + + virtual QPatternist::ExpressionVisitorResult::Ptr + visit(const QPatternist::CastableAs *) const; + + virtual QPatternist::ExpressionVisitorResult::Ptr + visit(const QPatternist::CollationChecker *) const; + + virtual QPatternist::ExpressionVisitorResult::Ptr + visit(const QPatternist::CombineNodes *) const; + + virtual QPatternist::ExpressionVisitorResult::Ptr + visit(const QPatternist::ComputedNamespaceConstructor *) const; + + virtual QPatternist::ExpressionVisitorResult::Ptr + visit(const QPatternist::CommentConstructor *) const; + + virtual QPatternist::ExpressionVisitorResult::Ptr + visit(const QPatternist::ContextItem *) const; + + virtual QPatternist::ExpressionVisitorResult::Ptr + visit(const QPatternist::CopyOf *) const; + + virtual QPatternist::ExpressionVisitorResult::Ptr + visit(const QPatternist::CurrentItemStore *) const; + + virtual QPatternist::ExpressionVisitorResult::Ptr + visit(const QPatternist::DocumentConstructor *) const; + + virtual QPatternist::ExpressionVisitorResult::Ptr + visit(const QPatternist::DynamicContextStore *) const; + + virtual QPatternist::ExpressionVisitorResult::Ptr + visit(const QPatternist::EBVExtractor *) const; + + virtual QPatternist::ExpressionVisitorResult::Ptr + visit(const QPatternist::ElementConstructor *) const; + + virtual QPatternist::ExpressionVisitorResult::Ptr + visit(const QPatternist::EmptySequence *) const; + + virtual QPatternist::ExpressionVisitorResult::Ptr + visit(const QPatternist::ExpressionSequence *) const; + + virtual QPatternist::ExpressionVisitorResult::Ptr + visit(const QPatternist::ExpressionVariableReference *) const; + + virtual QPatternist::ExpressionVisitorResult::Ptr + visit(const QPatternist::ExternalVariableReference *) const; + + virtual QPatternist::ExpressionVisitorResult::Ptr + visit(const QPatternist::EvaluationCache *) const; + + virtual QPatternist::ExpressionVisitorResult::Ptr + visit(const QPatternist::EvaluationCache *) const; + + virtual QPatternist::ExpressionVisitorResult::Ptr + visit(const QPatternist::FirstItemPredicate *) const; + + virtual QPatternist::ExpressionVisitorResult::Ptr + visit(const QPatternist::ForClause *) const; + + virtual QPatternist::ExpressionVisitorResult::Ptr + visit(const QPatternist::FunctionCall *) const; + + virtual QPatternist::ExpressionVisitorResult::Ptr + visit(const QPatternist::GeneralComparison *) const; + + virtual QPatternist::ExpressionVisitorResult::Ptr + visit(const QPatternist::GenericPredicate *) const; + + virtual QPatternist::ExpressionVisitorResult::Ptr + visit(const QPatternist::IfThenClause *) const; + + virtual QPatternist::ExpressionVisitorResult::Ptr + visit(const QPatternist::InstanceOf *) const; + + virtual QPatternist::ExpressionVisitorResult::Ptr + visit(const QPatternist::ItemVerifier *) const; + + virtual QPatternist::ExpressionVisitorResult::Ptr + visit(const QPatternist::LetClause *) const; + + virtual QPatternist::ExpressionVisitorResult::Ptr + visit(const QPatternist::Literal *) const; + + virtual QPatternist::ExpressionVisitorResult::Ptr + visit(const QPatternist::LiteralSequence *) const; + + virtual QPatternist::ExpressionVisitorResult::Ptr + visit(const QPatternist::NCNameConstructor *) const; + + virtual QPatternist::ExpressionVisitorResult::Ptr + visit(const QPatternist::NodeComparison *) const; + + virtual QPatternist::ExpressionVisitorResult::Ptr + visit(const QPatternist::NodeSortExpression *) const; + + virtual QPatternist::ExpressionVisitorResult::Ptr + visit(const QPatternist::OrderBy *) const; + + virtual QPatternist::ExpressionVisitorResult::Ptr + visit(const QPatternist::OrExpression *) const; + + virtual QPatternist::ExpressionVisitorResult::Ptr + visit(const QPatternist::ParentNodeAxis *) const; + + virtual QPatternist::ExpressionVisitorResult::Ptr + visit(const QPatternist::Path *) const; + + virtual QPatternist::ExpressionVisitorResult::Ptr + visit(const QPatternist::PositionalVariableReference *) const; + + virtual QPatternist::ExpressionVisitorResult::Ptr + visit(const QPatternist::ProcessingInstructionConstructor *) const; + + virtual QPatternist::ExpressionVisitorResult::Ptr + visit(const QPatternist::QNameConstructor *) const; + + virtual QPatternist::ExpressionVisitorResult::Ptr + visit(const QPatternist::QuantifiedExpression *) const; + + virtual QPatternist::ExpressionVisitorResult::Ptr + visit(const QPatternist::RangeExpression *) const; + + virtual QPatternist::ExpressionVisitorResult::Ptr + visit(const QPatternist::RangeVariableReference *) const; + + virtual QPatternist::ExpressionVisitorResult::Ptr + visit(const QPatternist::ReturnOrderBy *) const; + + virtual QPatternist::ExpressionVisitorResult::Ptr + visit(const QPatternist::SimpleContentConstructor *) const; + + virtual QPatternist::ExpressionVisitorResult::Ptr + visit(const QPatternist::StaticBaseURIStore *) const; + + virtual QPatternist::ExpressionVisitorResult::Ptr + visit(const QPatternist::StaticCompatibilityStore *) const; + + virtual QPatternist::ExpressionVisitorResult::Ptr + visit(const QPatternist::AxisStep *) const; + + virtual QPatternist::ExpressionVisitorResult::Ptr + visit(const QPatternist::TemplateParameterReference *) const; + + virtual QPatternist::ExpressionVisitorResult::Ptr + visit(const QPatternist::TextNodeConstructor *) const; + + virtual QPatternist::ExpressionVisitorResult::Ptr + visit(const QPatternist::TreatAs *) const; + + virtual QPatternist::ExpressionVisitorResult::Ptr + visit(const QPatternist::TruthPredicate *) const; + + virtual QPatternist::ExpressionVisitorResult::Ptr + visit(const QPatternist::UntypedAtomicConverter *) const; + + virtual QPatternist::ExpressionVisitorResult::Ptr + visit(const QPatternist::UnresolvedVariableReference *) const; + + virtual QPatternist::ExpressionVisitorResult::Ptr + visit(const QPatternist::ArgumentConverter *) const; + + virtual QPatternist::ExpressionVisitorResult::Ptr + visit(const QPatternist::UserFunctionCallsite *) const; + + virtual QPatternist::ExpressionVisitorResult::Ptr + visit(const QPatternist::ValidationError *) const; + + virtual QPatternist::ExpressionVisitorResult::Ptr + visit(const QPatternist::ValueComparison *) const; + + virtual QPatternist::ExpressionVisitorResult::Ptr + visit(const QPatternist::NamespaceConstructor *) const; + }; +} + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif +// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternssdk/ExternalSourceLoader.cpp b/tests/auto/xmlpatternssdk/ExternalSourceLoader.cpp new file mode 100644 index 0000000..a83a100 --- /dev/null +++ b/tests/auto/xmlpatternssdk/ExternalSourceLoader.cpp @@ -0,0 +1,140 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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 +#include +#include + +#include "Global.h" + +#include "qcommonsequencetypes_p.h" +#include "qdebug_p.h" +#include "qatomicstring_p.h" + +#include "ExternalSourceLoader.h" + +using namespace QPatternistSDK; +using namespace QPatternist; + +ExternalSourceLoader::ExternalSourceLoader(const VariableMap &varMap, + const QPatternist::ResourceLoader::Ptr &r) : m_variableMap(varMap) + , m_resourceLoader(r) + , m_query(Global::namePoolAsPublic()) +{ + Q_ASSERT(m_resourceLoader); +} + +QPatternist::SequenceType::Ptr +ExternalSourceLoader::announceExternalVariable(const QXmlName name, + const QPatternist::SequenceType::Ptr &declaredType) +{ + pDebug() << "ExternalSourceLoader::announceExternalVariable()"; + Q_ASSERT(!name.isNull()); + Q_ASSERT(declaredType); + Q_UNUSED(declaredType); /* Needed when bulding in release mode. */ + + if(name.namespaceURI() == QPatternist::StandardNamespaces::empty) + { + const VariableValue variable(m_variableMap.value(Global::namePool()->stringForLocalName(name.localName()))); + + if(variable.first.isEmpty()) + return QPatternist::SequenceType::Ptr(); + else + { + /* If announceDocument() can't load a document for uriForVar, it will return + * null, which we will too, which is fine, since we can't supply a value for + * this variable then. */ + if(variable.second == Document) + return m_resourceLoader->announceDocument(variable.first, QPatternist::ResourceLoader::WillUse); + else if(variable.second == URI) + { + return QPatternist::CommonSequenceTypes::ExactlyOneString; + } + else + { + /* The type is Query, and we don't pre-load + * them. No particular reason, just not worth it. */ + return QPatternist::CommonSequenceTypes::ZeroOrMoreItems; + } + } + } + else + return QPatternist::SequenceType::Ptr(); +} + +QPatternist::Item +ExternalSourceLoader::evaluateSingleton(const QXmlName name, + const QPatternist::DynamicContext::Ptr &context) +{ + Q_ASSERT(!name.isNull()); + const VariableValue variable(m_variableMap.value(Global::namePool()->stringForLocalName(name.localName()))); + + if(variable.second == Document) + { + Q_ASSERT_X(QFile::exists(variable.first.toLocalFile()), Q_FUNC_INFO, + qPrintable(QString::fromLatin1("The file %1 doesn't exist").arg(variable.first.toLocalFile()))); + Q_ASSERT_X(m_resourceLoader->openDocument(variable.first, context), Q_FUNC_INFO, + "We're supposed to have the value. If not, an error should have been issued at query compile time."); + + return m_resourceLoader->openDocument(variable.first, context); + } + else if(variable.second == Query) + { + /* Well, here we open the file and execute it. */ + m_query.setQuery(QUrl::fromLocalFile(variable.first.toLocalFile())); + Q_ASSERT(m_query.isValid()); + + QXmlResultItems result; + m_query.evaluateTo(&result); + + return QPatternist::Item::fromPublic(result.next()); + } + else + { + Q_ASSERT(variable.second == URI); + return QPatternist::AtomicString::fromValue(variable.first.toString()); + } +} + +// vim: et:ts=4:sw=4:sts=4 + diff --git a/tests/auto/xmlpatternssdk/ExternalSourceLoader.h b/tests/auto/xmlpatternssdk/ExternalSourceLoader.h new file mode 100644 index 0000000..2d88222 --- /dev/null +++ b/tests/auto/xmlpatternssdk/ExternalSourceLoader.h @@ -0,0 +1,137 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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$ +** +****************************************************************************/ + +#ifndef PatternistSDK_ExternalSourceLoader_H +#define PatternistSDK_ExternalSourceLoader_H + +#include +#include +#include + +#include "qdynamiccontext_p.h" +#include "qresourceloader_p.h" +#include "qexternalvariableloader_p.h" + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +namespace QPatternistSDK +{ + /** + * @short Handles external variables in XQTS queries, such as $input-context, + * by loading appropriate XML source files. + * + * @ingroup PatternistSDK + * @author Frans Englich + */ + class Q_PATTERNISTSDK_EXPORT ExternalSourceLoader : public QPatternist::ExternalVariableLoader + { + public: + enum TargetOfURI + { + /** + * Identifies @c input-file. + */ + Document, + + /** + * Identifies @c input-URI. + */ + URI, + + /** + * Identifies @c input-query. + */ + Query + }; + + /** + * The first is the complete, absolute, final URI to the file to be loaded, + * and the second is the type of source found at that URI. + */ + typedef QPair VariableValue; + + /** + * In the XQTSCatalog.xml each source file in each test is referred to + * by a key, which can be fully looked up in the @c sources element. This QHash + * maps the keys to absolute URIs pointing to the source file. + */ + typedef QHash SourceMap; + + /** + * The first value is the variable name, and the second is the URI identifying + * the XML source file that's supposed to be loaded as a document. + * + * This is one for every test case, except for @c rdb-queries-results-q5, + * @c rdb-queries-results-q17 and @c rdb-queries-results-q18(at least in XQTS 1.0). + */ + typedef QHash VariableMap; + + ExternalSourceLoader(const VariableMap &varMap, + const QPatternist::ResourceLoader::Ptr &resourceLoader); + + virtual QPatternist::SequenceType::Ptr + announceExternalVariable(const QXmlName name, + const QPatternist::SequenceType::Ptr &declaredType); + + virtual QPatternist::Item + evaluateSingleton(const QXmlName name, + const QPatternist::DynamicContext::Ptr &context); + + VariableMap variableMap() const + { + return m_variableMap; + } + + private: + const VariableMap m_variableMap; + const QPatternist::ResourceLoader::Ptr m_resourceLoader; + QXmlQuery m_query; + }; +} + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif +// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternssdk/Global.cpp b/tests/auto/xmlpatternssdk/Global.cpp new file mode 100644 index 0000000..f78e421 --- /dev/null +++ b/tests/auto/xmlpatternssdk/Global.cpp @@ -0,0 +1,83 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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 "Global.h" + +using namespace QPatternistSDK; + +const QString Global::xqtsCatalogNS (QLatin1String("http://www.w3.org/2005/02/query-test-XQTSCatalog")); +const QString Global::xqtsResultNS (QLatin1String("http://www.w3.org/2005/02/query-test-XQTSResult")); +const QString Global::xsltsCatalogNS (QLatin1String("http://www.w3.org/2005/05/xslt20-test-catalog")); +const QString Global::organizationName (QLatin1String("Patternist Team")); +const qint16 Global::versionNumber (0x01); + +static QXmlNamePool s_namePool; + +QPatternist::NamePool::Ptr Global::namePool() +{ + return s_namePool.d; +} + +QXmlNamePool Global::namePoolAsPublic() +{ + return s_namePool; +} + +bool Global::readBoolean(const QString &value) +{ + const QString normd(value.simplified()); + + if(normd == QLatin1String("true") || + normd == QLatin1String("1")) + return true; + else if(normd.isEmpty() || + normd == QLatin1String("false") || + normd == QLatin1String("0")) + return false; + + Q_ASSERT_X(false, Q_FUNC_INFO, + "The lexical representation of xs:boolean was invalid"); + return false; +} + +// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternssdk/Global.h b/tests/auto/xmlpatternssdk/Global.h new file mode 100644 index 0000000..53c32cb --- /dev/null +++ b/tests/auto/xmlpatternssdk/Global.h @@ -0,0 +1,128 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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$ +** +****************************************************************************/ + +#ifndef PatternistSDK_Global_H +#define PatternistSDK_Global_H + +#include + +#include "private/qitem_p.h" +#include "private/qnamepool_p.h" + +#if defined(Q_WS_WIN) || defined(Q_OS_SYMBIAN) +# ifdef Q_PATTERNISTSDK_BUILDING + #define Q_PATTERNISTSDK_EXPORT __declspec(dllexport) + #else + #define Q_PATTERNISTSDK_EXPORT __declspec(dllimport) + #endif +#else + #define Q_PATTERNISTSDK_EXPORT +#endif + +/** + * @short Contains testing utilities for Patternist, interfacing W3C's XQuery Test Suite. + * + * @see XML Query Test Suite + * @author Frans Englich + */ +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +namespace QPatternistSDK +{ + /** + * @short Contains global constants. + * + * @ingroup PatternistSDK + * @author Frans Englich + */ + class Q_PATTERNISTSDK_EXPORT Global + { + public: + + /** + * The namespace which the XQTS test case catalog(specified by Catalog.xsd) + * is in. The namespace is: http://www.w3.org/2005/02/query-test-XQTSCatalog + */ + static const QString xqtsCatalogNS; + + /** + * The namespace which the XQTS test results collection(specified by XQTSResult.xsd) + * is in. The namespace is: http://www.w3.org/2005/02/query-test-XQTSResult + */ + static const QString xqtsResultNS; + + /** + * The organization which created PatternistSDK. It say something + * in the direction of "Patternist Team", and is used for QSettings and the like. + */ + static const QString organizationName; + + /** + * The namespace which W3C's XSL-T test suite resides in. + */ + static const QString xsltsCatalogNS; + + /** + * The version of PatternistSDK. The value has currently no other + * meaning than that larger means older. This version information is supplied to + * QMainWindow::restoreState() and QMainWindow::saveState(). + */ + static const qint16 versionNumber; + + /** + * Parses the lexical space of @c xs:boolean, + * with the exception that the empty string is considered @c false. + */ + static bool readBoolean(const QString &lexicalSpace); + + static QPatternist::NamePool::Ptr namePool(); + static QXmlNamePool namePoolAsPublic(); + }; +} + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif +// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternssdk/ResultThreader.cpp b/tests/auto/xmlpatternssdk/ResultThreader.cpp new file mode 100644 index 0000000..3296854 --- /dev/null +++ b/tests/auto/xmlpatternssdk/ResultThreader.cpp @@ -0,0 +1,76 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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 "ResultThreader.h" + +using namespace QPatternistSDK; + +ResultThreader::ResultThreader(QEventLoop &ev, + QFile *file, + const Type t, + QObject *p) : QThread(p) + , m_file(file) + , m_type(t) + , m_eventLoop(ev) +{ + Q_ASSERT_X(p, Q_FUNC_INFO, "Should have a parent"); + Q_ASSERT_X(file, Q_FUNC_INFO, "Should have a valid file"); + Q_ASSERT(m_type == Baseline || m_type == Result); +} + +void ResultThreader::run() +{ + QXmlSimpleReader reader; + reader.setContentHandler(this); + + QXmlInputSource source(m_file); + reader.parse(source); + m_file->close(); +} + +ResultThreader::Type ResultThreader::type() const +{ + return m_type; +} + +// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternssdk/ResultThreader.h b/tests/auto/xmlpatternssdk/ResultThreader.h new file mode 100644 index 0000000..19749f0 --- /dev/null +++ b/tests/auto/xmlpatternssdk/ResultThreader.h @@ -0,0 +1,110 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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$ +** +****************************************************************************/ + +#ifndef PatternistSDK_ResultThreader_H +#define PatternistSDK_ResultThreader_H + +#include +#include +#include + +#include "TestResultHandler.h" + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +class QEventLoop; + +namespace QPatternistSDK +{ + /** + * @short Reads XML in the @c XQTSResult.xsd format, as a thread, allowing + * multiple parses to be done simultaneously. + * + * @author Frans Englich + * @ingroup PatternistSDK + */ + class Q_PATTERNISTSDK_EXPORT ResultThreader : public QThread + , public TestResultHandler + { + public: + enum Type + { + Baseline = 1, + Result + }; + + /** + * Creates a ResultThreader that will read @p file when run() is called. + */ + ResultThreader(QEventLoop &ev, + QFile *file, + const Type type, + QObject *parent); + + /** + * Parses the file passed in this class's constructor with this ResultHandlerTH::Item::LisT + * as the QXmlContentHandler, and returns. + */ + virtual void run(); + + /** + * @note Do not reimplement this function. + * @returns whether this ResultThreader handles the baseline or the result. + */ + Type type() const; + + private: + Q_DISABLE_COPY(ResultThreader) + + QFile *const m_file; + const Type m_type; + QEventLoop & m_eventLoop; + }; +} + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif +// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternssdk/TestBaseLine.cpp b/tests/auto/xmlpatternssdk/TestBaseLine.cpp new file mode 100644 index 0000000..6a46bcc --- /dev/null +++ b/tests/auto/xmlpatternssdk/TestBaseLine.cpp @@ -0,0 +1,511 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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 +#include +#include +#include +#include +#include + +#include "qdebug_p.h" +#include "XMLWriter.h" + +#include "TestBaseLine.h" + +using namespace QPatternistSDK; +using namespace QPatternist; + +Q_GLOBAL_STATIC_WITH_ARGS(QRegExp, errorRegExp, (QLatin1String("[A-Z]{4}[0-9]{4}"))) + +TestBaseLine::TestBaseLine(const Type t) : m_type(t) +{ + Q_ASSERT(errorRegExp()->isValid()); +} + +TestResult::Status TestBaseLine::scan(const QString &serialized, + const TestBaseLine::List &lines) +{ + Q_ASSERT_X(lines.count() >= 1, Q_FUNC_INFO, + "At least one base line must be passed, otherwise there's nothing " + "to compare to."); + + const TestBaseLine::List::const_iterator end(lines.constEnd()); + TestBaseLine::List::const_iterator it(lines.constBegin()); + for(; it != end; ++it) + { + const TestResult::Status retval((*it)->verify(serialized)); + + if(retval == TestResult::Pass || retval == TestResult::NotTested) + return retval; + } + + return TestResult::Fail; +} + +TestResult::Status TestBaseLine::scanErrors(const ErrorHandler::Message::List &errors, + const TestBaseLine::List &lines) +{ + pDebug() << "TestBaseLine::scanErrors()"; + + /* 1. Find the first error in @p errors that's a Patternist + * error(not warning and not from Qt) and extract the error code. */ + QString errorCode; + + const ErrorHandler::Message::List::const_iterator end(errors.constEnd()); + ErrorHandler::Message::List::const_iterator it(errors.constBegin()); + for(; it != end; ++it) + { + if((*it).type() != QtFatalMsg) + continue; + + errorCode = QUrl((*it).identifier()).fragment(); + + pDebug() << "ERR:" << (*it).description(); + /* This is hackish. We have no way of determining whether a Message + * is actually issued from Patternist, so we try to narrow it down like this. */ + if(errorRegExp()->exactMatch(errorCode)) + break; /* It's an error code. */ + else + errorCode.clear(); + } + + pDebug() << "Got error code: " << errorCode; + /* 2. Loop through @p lines, and for the first base line + * which is of type ExpectedError and which matches @p errorCode + * return Pass, otherwise Fail. */ + const TestBaseLine::List::const_iterator blend(lines.constEnd()); + TestBaseLine::List::const_iterator blit(lines.constBegin()); + for(; blit != blend; ++blit) + { + const Type t = (*blit)->type(); + + if(t == TestBaseLine::ExpectedError) + { + const QString d((*blit)->details()); + if(d == errorCode || d == QChar::fromLatin1('*')) + return TestResult::Pass; + } + } + + return TestResult::Fail; +} + +void TestBaseLine::toXML(XMLWriter &receiver) const +{ + switch(m_type) + { + case XML: /* Fallthrough. */ + case Fragment: /* Fallthrough. */ + case SchemaIsValid: /* Fallthrough. */ + case Text: + { + QXmlAttributes inspectAtts; + inspectAtts.append(QLatin1String("role"), QString(), + QLatin1String("role"), QLatin1String("principal")); + inspectAtts.append(QLatin1String("compare"), QString(), + QLatin1String("compare"), displayName(m_type)); + receiver.startElement(QLatin1String("output-file"), inspectAtts); + receiver.characters(m_details); + receiver.endElement(QLatin1String("output-file")); + return; + } + case Ignore: + { + Q_ASSERT_X(false, Q_FUNC_INFO, "Serializing 'Ignore' is not implemented."); + return; + } + case Inspect: + { + QXmlAttributes inspectAtts; + inspectAtts.append(QLatin1String("role"), QString(), + QLatin1String("role"), QLatin1String("principal")); + inspectAtts.append(QLatin1String("compare"), QString(), + QLatin1String("compare"), QLatin1String("Inspect")); + receiver.startElement(QLatin1String("output-file"), inspectAtts); + receiver.characters(m_details); + receiver.endElement(QLatin1String("output-file")); + return; + } + case ExpectedError: + { + receiver.startElement(QLatin1String("expected-error")); + receiver.characters(m_details); + receiver.endElement(QLatin1String("expected-error")); + return; + } + } +} + +bool TestBaseLine::isChildrenDeepEqual(const QDomNodeList &cl1, const QDomNodeList &cl2) +{ + const unsigned int len = cl1.length(); + + if(len == cl2.length()) + { + for(unsigned int i = 0; i < len; ++i) + { + if(!isDeepEqual(cl1.at(i), cl2.at(i))) + return false; + } + + return true; + } + else + return false; +} + +bool TestBaseLine::isAttributesEqual(const QDomNamedNodeMap &cl1, const QDomNamedNodeMap &cl2) +{ + const unsigned int len = cl1.length(); + pDebug() << "LEN:" << len; + + if(len == cl2.length()) + { + for(unsigned int i1 = 0; i1 < len; ++i1) + { + const QDomNode attr1(cl1.item(i1)); + Q_ASSERT(!attr1.isNull()); + + /* This is set if attr1 cannot be found at all in cl2. */ + bool earlyExit = false; + + for(unsigned int i2 = 0; i2 < len; ++i2) + { + const QDomNode attr2(cl2.item(i2)); + Q_ASSERT(!attr2.isNull()); + pDebug() << "ATTR1:" << attr1.localName() << attr1.namespaceURI() << attr1.prefix() << attr1.nodeName(); + pDebug() << "ATTR2:" << attr2.localName() << attr2.namespaceURI() << attr2.prefix() << attr2.nodeName(); + + if(attr1.localName() == attr2.localName() && + attr1.namespaceURI() == attr2.namespaceURI() && + attr1.prefix() == attr2.prefix() && + attr1.nodeName() == attr2.nodeName() && /* Yes, needed in addition to all the other. */ + attr1.nodeValue() == attr2.nodeValue()) + { + earlyExit = true; + break; + } + } + + if(!earlyExit) + { + /* An attribute was found that doesn't exist in the other list so exit. */ + return false; + } + } + + return true; + } + else + return false; +} + +bool TestBaseLine::isDeepEqual(const QDomNode &n1, const QDomNode &n2) +{ + if(n1.nodeType() != n2.nodeType()) + return false; + + switch(n1.nodeType()) + { + case QDomNode::CommentNode: + /* Fallthrough. */ + case QDomNode::TextNode: + { + return static_cast(n1).data() == + static_cast(n2).data(); + } + case QDomNode::ProcessingInstructionNode: + { + return n1.nodeName() == n2.nodeName() && + n1.nodeValue() == n2.nodeValue(); + } + case QDomNode::DocumentNode: + return isChildrenDeepEqual(n1.childNodes(), n2.childNodes()); + case QDomNode::ElementNode: + { + return n1.localName() == n2.localName() && + n1.namespaceURI() == n2.namespaceURI() && + n1.nodeName() == n2.nodeName() && /* Yes, this one is needed in addition to localName(). */ + isAttributesEqual(n1.attributes(), n2.attributes()) && + isChildrenDeepEqual(n1.childNodes(), n2.childNodes()); + } + /* Fallthrough all these. */ + case QDomNode::EntityReferenceNode: + case QDomNode::CDATASectionNode: + case QDomNode::EntityNode: + case QDomNode::DocumentTypeNode: + case QDomNode::DocumentFragmentNode: + case QDomNode::NotationNode: + case QDomNode::BaseNode: + case QDomNode::CharacterDataNode: + { + Q_ASSERT_X(false, Q_FUNC_INFO, + "An unsupported node type was encountered."); + return false; + } + case QDomNode::AttributeNode: + { + Q_ASSERT_X(false, Q_FUNC_INFO, + "This should never happen. QDom doesn't allow us to compare DOM attributes " + "properly."); + return false; + } + default: + { + Q_ASSERT_X(false, Q_FUNC_INFO, "Unhandled QDom::NodeType value."); + return false; + } + } +} + +TestResult::Status TestBaseLine::verify(const QString &serializedInput) const +{ + switch(m_type) + { + case SchemaIsValid: + /* Fall through. */ + case Text: + { + if(serializedInput == details()) + return TestResult::Pass; + else + return TestResult::Fail; + } + case Fragment: + /* Fall through. */ + case XML: + { + /* Read the baseline and the serialized input into two QDomDocuments, and compare + * them deeply. We wrap fragments in a root node such that it is well-formed XML. + */ + + QDomDocument output; + { + /* The reason we put things into a QByteArray and then parse it through QXmlSimpleReader, is that + * QDomDocument does whitespace stripping when calling setContent(QString). In other words, + * this workarounds a bug. */ + + QXmlInputSource source; + source.setData((m_type == XML ? serializedInput : QLatin1String("") + + serializedInput + + QLatin1String("")).toUtf8()); + + QString outputReadingError; + + QXmlSimpleReader reader; + reader.setFeature(QLatin1String("http://xml.org/sax/features/namespace-prefixes"), true); + + const bool success = output.setContent(&source, + &reader, + &outputReadingError); + + if(!success) + return TestResult::Fail; + + Q_ASSERT(success); + } + + QDomDocument baseline; + { + QXmlInputSource source; + source.setData((m_type == XML ? details() : QLatin1String("") + + details() + + QLatin1String("")).toUtf8()); + QString baselineReadingError; + + QXmlSimpleReader reader; + reader.setFeature(QLatin1String("http://xml.org/sax/features/namespace-prefixes"), true); + + const bool success = baseline.setContent(&source, + &reader, + &baselineReadingError); + + if(!success) + return TestResult::Fail; + + /* This piece of code workaround a bug in QDom, which treats XML prologs as processing + * instructions and make them available in the tree as so. */ + if(m_type == XML) + { + /* $doc/r/node() */ + const QDomNodeList children(baseline.childNodes()); + const int len = children.length(); + + for(int i = 0; i < len; ++i) + { + const QDomNode &child = children.at(i); + if(child.isProcessingInstruction() && child.nodeName() == QLatin1String("xml")) + { + baseline.removeChild(child); + break; + } + } + } + + Q_ASSERT_X(baselineReadingError.isNull(), Q_FUNC_INFO, + qPrintable((QLatin1String("Reading the baseline failed: ") + baselineReadingError))); + } + + if(isDeepEqual(output, baseline)) + return TestResult::Pass; + else + { + pDebug() << "FAILURE:" << output.toString() << "is NOT IDENTICAL to(baseline):" << baseline.toString(); + return TestResult::Fail; + } + } + case Ignore: + return TestResult::Pass; + case Inspect: + return TestResult::NotTested; + case ExpectedError: + { + /* This function is only called for Text/XML/Fragment tests. */ + return TestResult::Fail; + } + } + Q_ASSERT(false); + return TestResult::Fail; +} + +TestBaseLine::Type TestBaseLine::identifierFromString(const QString &string) +{ + /* "html-output: Using an ad hoc tool, it must assert that the document obeys the HTML + * Output Method as defined in the Serialization specification and section + * 20 of the XSLT 2.0 specification." We treat it as XML for now, same with + * xhtml-output. */ + if(string.compare(QLatin1String("XML"), Qt::CaseInsensitive) == 0 || + string == QLatin1String("html-output") || + string == QLatin1String("xml-output") || + string == QLatin1String("xhtml-output")) + return XML; + else if(string == QLatin1String("Fragment") || string == QLatin1String("xml-frag")) + return Fragment; + else if(string.compare(QLatin1String("Text"), Qt::CaseInsensitive) == 0) + return Text; + else if(string == QLatin1String("Ignore")) + return Ignore; + else if(string.compare(QLatin1String("Inspect"), Qt::CaseInsensitive) == 0) + return Inspect; + else + { + Q_ASSERT_X(false, Q_FUNC_INFO, + qPrintable(QString::fromLatin1("Invalid string representation for a comparation type: %1").arg(string))); + + return Ignore; /* Silence GCC. */ + } +} + +QString TestBaseLine::displayName(const Type id) +{ + switch(id) + { + case XML: + return QLatin1String("XML"); + case Fragment: + return QLatin1String("Fragment"); + case Text: + return QLatin1String("Text"); + case Ignore: + return QLatin1String("Ignore"); + case Inspect: + return QLatin1String("Inspect"); + case ExpectedError: + return QLatin1String("ExpectedError"); + case SchemaIsValid: + return QLatin1String("SchemaIsValid"); + } + + Q_ASSERT(false); + return QString(); +} + +QString TestBaseLine::details() const +{ + if(m_type == Ignore) /* We're an error code. */ + return QString(); + if(m_type == ExpectedError) /* We're an error code. */ + return m_details; + if(m_type == SchemaIsValid) /* We're a schema validation information . */ + return m_details; + + if(m_details.isEmpty()) + return m_details; + + /* m_details is a file name, we open it and return the result. */ + QFile file(QUrl(m_details).toLocalFile()); + + QString retval; + if(!file.exists()) + retval = QString::fromLatin1("%1 does not exist.").arg(file.fileName()); + else if(!QFileInfo(file.fileName()).isFile()) + retval = QString::fromLatin1("%1 is not a file, cannot display it.").arg(file.fileName()); + else if(!file.open(QIODevice::ReadOnly | QIODevice::Text)) + retval = QString::fromLatin1("Could not open %1. Likely a permission error.").arg(file.fileName()); + + if(retval.isNull()) + { + /* Scary, we assume the query/baseline is in UTF-8. */ + return QString::fromUtf8(file.readAll()); + } + else + { + /* We had a file error. */ + retval.prepend(QLatin1String("Test-suite harness error: ")); + qCritical() << retval; + return retval; + } +} + +TestBaseLine::Type TestBaseLine::type() const +{ + return m_type; +} + +void TestBaseLine::setDetails(const QString &detailsP) +{ + m_details = detailsP; +} + +// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternssdk/TestBaseLine.h b/tests/auto/xmlpatternssdk/TestBaseLine.h new file mode 100644 index 0000000..e297128 --- /dev/null +++ b/tests/auto/xmlpatternssdk/TestBaseLine.h @@ -0,0 +1,212 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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$ +** +****************************************************************************/ + +#ifndef PatternistSDK_TestBaseLine_H +#define PatternistSDK_TestBaseLine_H + +#include + +#include "Global.h" +#include "TestResult.h" + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +class QDomNamedNodeMap; +class QDomNode; +class QDomNodeList; +template class QList; + +namespace QPatternistSDK +{ + /** + * @short Represents an expected test result for a test case. + * + * TestBaseLine represents a valid outcome for a test case, + * the "base line". A XQTS test case can have many different valid + * base lines, and one TestBaseLine instance represents on of them. + * + * Of highest interest, TestBaseLine have the function scan() and + * scanErrors(), which allows serialized output to be + * compared to the base line. + * + * @ingroup PatternistSDK + * @author Frans Englich + */ + class Q_PATTERNISTSDK_EXPORT TestBaseLine + { + public: + typedef QList List; + + /** + * Identifies what kind of comparator to use. The documentation + * for each enumerator is copied from + * Guidelines + * for Running the XML Query Test Suite + */ + enum Type + { + /** + * The test harness must canonicalize both, the actual result + * and the expected result according to the "Canonical XML" recommendation [2], + * which refers to a number of open-source implementations. Byte-comparison can + * then be applied to the resulting XML documents. If the test harness does + * this process in a different manner, it must be documented. + */ + XML, + + /** + * For XML fragments, the same root node must be created for both, + * implementation result and test suite result. The resulting XML + * can be compared using XML comparison. + */ + Fragment, + + /** + * Text (that has been produced by XML serialization) is compared + * using byte-comparison. + */ + Text, + + /** + * No comparison needs to be applied; the result is always @c true if + * the implementation successfully executes the test case. + */ + Ignore, + + /** + * A human is required to make the call about correctness of the result + * according to the description in the test case. + */ + Inspect, + + /** + * The expected result of the test case is an error, identified as an + * eight-character error code (e.g., XPST0003). The result of a test is + * @c true, if the implementation raises an error. However, raising an error + * because an implementation does not support the feature is not + * considered a correct result. + */ + ExpectedError, + + /** + * A special comparison for the schema validation tests. The details + * can only be 'true' or 'false' depending on whether it is a valid + * schema or not. + */ + SchemaIsValid + }; + + /** + * Takes a string identifying a comparator either in the XSL-T or the + * XQuery test suite, and returns an enum value for it. + * + * If the value is unknown, the code asserts. + */ + static Type identifierFromString(const QString &string); + + /** + * @returns a display name for @p id. For example, if Inspect was passed, "Inspect" + * would be returned. + */ + static QString displayName(const Type id); + + /** + * Compares @p items(typically the result of an evaluation) against + * the base lines @p lines. + * + * @returns the status of the first base line which passes, + * otherwise TestResult::Fail. + */ + static TestResult::Status scan(const QString &serialized, + const TestBaseLine::List &lines); + + static TestResult::Status scanErrors(const ErrorHandler::Message::List &errors, + const TestBaseLine::List &lines); + + /** + * Constructs a TestBaseLine of type @p type. + */ + TestBaseLine(const Type type); + + /** + * What @p details contains depends on the type(). If the type() is ExpectedError, + * @p details contains the relevant error code. If the type() is one which compares + * result against a base line, it is a filename locating the baseline. + */ + void setDetails(const QString &details); + + Type type() const; + + QString details() const; + + void toXML(XMLWriter &receiver) const; + + protected: + TestResult::Status verify(const QString &serializedInput) const; + + private: + static bool isDeepEqual(const QDomNode &n1, const QDomNode &n2); + + /** + * @returns @c true if the nodes in @p cl1 are equal to @p cl2, by calling isDeepEqual() + * for each pair. + */ + static bool isChildrenDeepEqual(const QDomNodeList &cl1, const QDomNodeList &cl2); + + /** + * Considers @p cl1 and @p cl2 to be lists containing attributes. The list are equal + * if they contain attributes by same value and name, but regardless of order. + */ + static bool isAttributesEqual(const QDomNamedNodeMap &cl1, const QDomNamedNodeMap &cl2); + const Type m_type; + QString m_details; + }; +} + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif +// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternssdk/TestCase.cpp b/tests/auto/xmlpatternssdk/TestCase.cpp new file mode 100644 index 0000000..7b424d2 --- /dev/null +++ b/tests/auto/xmlpatternssdk/TestCase.cpp @@ -0,0 +1,439 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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 +#include +#include +#include +#include + +#include "DebugExpressionFactory.h" +#include "ExternalSourceLoader.h" +#include "Global.h" +#include "TestSuite.h" +#include "XMLWriter.h" + +#include "TestCase.h" + +using namespace QPatternistSDK; +using namespace QPatternist; + +// STATIC DATA +static const DebugExpressionFactory::Ptr s_exprFact(new DebugExpressionFactory()); + +TestCase::TestCase() : m_result(0) +{ +} + +TestCase::~TestCase() +{ + delete m_result; +} + +TestResult::List TestCase::execute(const ExecutionStage stage, + TestSuite *) +{ + if(name() == QLatin1String("Constr-cont-document-3")) + { + TestResult::List result; + result.append(createTestResult(TestResult::Fail, QLatin1String("Skipped this test, because we loop infinitely on it."))); + return result; + } + else if(name() == QLatin1String("Axes089")) + { + TestResult::List result; + result.append(createTestResult(TestResult::Fail, QLatin1String("Skipped this test, we crash on it."))); + return result; + } + + qDebug() << "Running test case: " << name(); + + return execute(stage); + + Q_ASSERT(false); + return TestResult::List(); +} + +TestResult *TestCase::createTestResult(const TestResult::Status status, + const QString &comment) const +{ + TestResult *const result = new TestResult(name(), + status, + 0 /* We don't have an AST. */, + ErrorHandler::Message::List(), + QPatternist::Item::List(), + QString()); + result->setComment(comment); + return result; +} + +TestResult::List TestCase::execute(const ExecutionStage stage) +{ + ErrorHandler errHandler; + ErrorHandler::installQtMessageHandler(&errHandler); + + pDebug() << "TestCase::execute()"; + delete m_result; + + QXmlQuery query(language(), Global::namePoolAsPublic()); + + query.d->setExpressionFactory(s_exprFact); + query.setInitialTemplateName(initialTemplateName()); + + QXmlQuery openDoc(query.namePool()); + + if(contextItemSource().isValid()) + { + openDoc.setQuery(QString::fromLatin1("doc('") + contextItemSource().toString() + QLatin1String("')")); + Q_ASSERT(openDoc.isValid()); + QXmlResultItems result; + + openDoc.evaluateTo(&result); + const QXmlItem item(result.next()); + Q_ASSERT(!item.isNull()); + query.setFocus(item); + } + + TestResult::List retval; + + const Scenario scen(scenario()); + TestResult::Status resultStatus = TestResult::Unknown; + + bool ok = false; + const QString queryString(sourceCode(ok)); + + if(!ok) + { + /* Loading the query file failed, or similar. */ + resultStatus = TestResult::Fail; + + m_result = new TestResult(name(), resultStatus, s_exprFact->astTree(), + errHandler.messages(), QPatternist::Item::List(), QString()); + retval.append(m_result); + ErrorHandler::installQtMessageHandler(0); + changed(this); + return retval; + } + + query.setMessageHandler(&errHandler); + QXmlNamePool namePool(query.namePool()); + + /* Bind variables. */ + QPatternist::ExternalVariableLoader::Ptr loader(externalVariableLoader()); + if(loader) + { + Q_ASSERT(loader); + const ExternalSourceLoader::VariableMap vMap(static_cast(loader.data())->variableMap()); + const QStringList variables(vMap.keys()); + + for(int i = 0; i < variables.count(); ++i) + { + const QXmlName name(namePool, variables.at(i)); + const QXmlItem val(QPatternist::Item::toPublic(loader->evaluateSingleton(name, QPatternist::DynamicContext::Ptr()))); + query.bindVariable(name, val); + } + } + + /* We pass in the testCasePath(), such that the base URI is correct fort + * XSL-T stylesheets. */ + query.setQuery(queryString, testCasePath()); + + if(!query.isValid()) + { + pDebug() << "Got compilation exception."; + resultStatus = TestBaseLine::scanErrors(errHandler.messages(), baseLines()); + + Q_ASSERT(resultStatus != TestResult::Unknown); + m_result = new TestResult(name(), resultStatus, s_exprFact->astTree(), + errHandler.messages(), QPatternist::Item::List(), QString()); + retval.append(m_result); + ErrorHandler::installQtMessageHandler(0); + changed(this); + return retval; + } + + if(stage == CompileOnly) + { + m_result = new TestResult(name(), TestResult::Fail, s_exprFact->astTree(), + errHandler.messages(), QPatternist::Item::List(), QString()); + retval.append(m_result); + return retval; + } + + Q_ASSERT(stage == CompileAndRun); + + if(scen == ParseError) /* We're supposed to have received an error + at this point. */ + { + m_result = new TestResult(name(), TestResult::Fail, s_exprFact->astTree(), + errHandler.messages(), QPatternist::Item::List(), QString()); + ErrorHandler::installQtMessageHandler(0); + retval.append(m_result); + changed(this); + return retval; + } + + QPatternist::Item::List itemList; + + QByteArray output; + QBuffer buffer(&output); + buffer.open(QIODevice::WriteOnly); + + QXmlSerializer serializer(query, &buffer); + + pDebug() << "-------------------------- evaluateToPushCallback() ---------------------------- "; + const bool success = query.evaluateTo(&serializer); + pDebug() << "------------------------------------------------------------------------------------ "; + + buffer.close(); + + const QString serialized(QString::fromUtf8(output.constData(), output.size())); + + if(!success) + { + resultStatus = TestBaseLine::scanErrors(errHandler.messages(), baseLines()); + + Q_ASSERT(resultStatus != TestResult::Unknown); + m_result = new TestResult(name(), resultStatus, s_exprFact->astTree(), + errHandler.messages(), QPatternist::Item::List(), serialized); + retval.append(m_result); + ErrorHandler::installQtMessageHandler(0); + changed(this); + return retval; + } + + /* It's a regular test. */ + Q_ASSERT(scen == Standard || scen == RuntimeError); + + resultStatus = TestBaseLine::scan(serialized, baseLines()); + Q_ASSERT(resultStatus != TestResult::Unknown); + + /* Check that errHandler()->messages() at most only contains + * warnings, since it shouldn't have errors at this point. */ + const ErrorHandler::Message::List errors (errHandler.messages()); + const ErrorHandler::Message::List::const_iterator end(errors.constEnd()); + ErrorHandler::Message::List::const_iterator it(errors.constBegin()); + + for(; it != end; ++it) + { + const QtMsgType type = (*it).type(); + if(type == QtFatalMsg) + { + m_result = new TestResult(name(), TestResult::Fail, s_exprFact->astTree(), + errHandler.messages(), itemList, serialized); + retval.append(m_result); + ErrorHandler::installQtMessageHandler(0); + changed(this); + return retval; + } + } + + m_result = new TestResult(name(), resultStatus, s_exprFact->astTree(), + errHandler.messages(), itemList, serialized); + retval.append(m_result); + ErrorHandler::installQtMessageHandler(0); + changed(this); + return retval; +} + +TestCase::Scenario TestCase::scenarioFromString(const QString &string) +{ + if(string == QLatin1String("standard")) + return Standard; + else if(string == QLatin1String("parse-error")) + return ParseError; + else if(string == QLatin1String("runtime-error")) + return RuntimeError; + else if(string == QLatin1String("trivial")) + return Trivial; + else + { + Q_ASSERT_X(false, Q_FUNC_INFO, + qPrintable(QString::fromLatin1("Invalid string representation for the scenario-enum: %1").arg(string))); + return ParseError; /* Silence GCC. */ + } +} + +void TestCase::toXML(XMLWriter &receiver) const +{ + /* */ + QXmlAttributes test_caseAtts; + test_caseAtts.append(QLatin1String("is-XPath2"), QString(), + QLatin1String("is-XPath2"), isXPath() ? QLatin1String("true") + : QLatin1String("false")); + test_caseAtts.append(QLatin1String("name"), QString(), QLatin1String("name"), name()); + test_caseAtts.append(QLatin1String("creator"), QString(), QLatin1String("creator"), creator()); + QString scen; + switch(scenario()) + { + case Standard: + { + scen = QLatin1String("standard"); + break; + } + case ParseError: + { + scen = QLatin1String("parse-error"); + break; + } + case RuntimeError: + { + scen = QLatin1String("runtime-error"); + break; + } + case Trivial: + { + scen = QLatin1String("trivial"); + break; + } + default: /* includes 'AnyError' */ + Q_ASSERT(false); + } + test_caseAtts.append(QLatin1String("scenario"), QString(), QLatin1String("scenario"), scen); + test_caseAtts.append(QLatin1String(QLatin1String("FilePath")), QString(), + QLatin1String("FilePath"), QString()); + receiver.startElement(QLatin1String("test-case"), test_caseAtts); + + /* */ + receiver.startElement(QLatin1String("description"), test_caseAtts); + receiver.characters(description()); + + /* */ + receiver.endElement(QLatin1String("description")); + + /* */ + QXmlAttributes queryAtts; + queryAtts.append(QLatin1String("date"), QString(), QLatin1String("date"), /* This date is a dummy. */ + QDate::currentDate().toString(Qt::ISODate)); + queryAtts.append(QLatin1String("name"), QString(), QLatin1String("name"), testCasePath().toString()); + receiver.startElement(QLatin1String("query"), queryAtts); + + /* */ + receiver.endElement(QLatin1String("query")); + + /* Note: this is invalid, we don't add spec-citation. */ + TestBaseLine::List bls(baseLines()); + const TestBaseLine::List::const_iterator end(bls.constEnd()); + TestBaseLine::List::const_iterator it(bls.constBegin()); + + for(; it != end; ++it) + (*it)->toXML(receiver); + + /* */ + receiver.endElement(QLatin1String("test-case")); +} + +QString TestCase::displayName(const Scenario scen) +{ + switch(scen) + { + case Standard: + return QLatin1String("Standard"); + case ParseError: + return QLatin1String("Parse Error"); + case RuntimeError: + return QLatin1String("Runtime Error"); + case Trivial: + return QLatin1String("Trivial"); + case AnyError: + { + Q_ASSERT(false); + return QString(); + } + } + + Q_ASSERT(false); + return QString(); +} + +TestItem::ResultSummary TestCase::resultSummary() const +{ + if(m_result) + return ResultSummary(m_result->status() == TestResult::Pass ? 1 : 0, + 1); + + return ResultSummary(0, 1); +} + +void TestCase::appendChild(TreeItem *) +{ + Q_ASSERT_X(false, Q_FUNC_INFO, "Makes no sense to call appendChild() for TestCase."); +} + +TreeItem *TestCase::child(const unsigned int) const +{ + return 0; /* Silence GCC */ +} + +TreeItem::List TestCase::children() const +{ + return TreeItem::List(); +} + +unsigned int TestCase::childCount() const +{ + return 0; +} + +TestResult *TestCase::testResult() const +{ + return m_result; +} + +bool TestCase::isFinalNode() const +{ + return true; +} + +QXmlQuery::QueryLanguage TestCase::language() const +{ + return QXmlQuery::XQuery10; +} + +QXmlName TestCase::initialTemplateName() const +{ + return QXmlName(); +} + +// vim: et:ts=4:sw=4:sts=4 + diff --git a/tests/auto/xmlpatternssdk/TestCase.h b/tests/auto/xmlpatternssdk/TestCase.h new file mode 100644 index 0000000..28df5f1 --- /dev/null +++ b/tests/auto/xmlpatternssdk/TestCase.h @@ -0,0 +1,256 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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$ +** +****************************************************************************/ + +#ifndef PatternistSDK_TestCase_H +#define PatternistSDK_TestCase_H + +#include + +#include "qexternalvariableloader_p.h" + +#include "ErrorHandler.h" +#include "TestBaseLine.h" +#include "Global.h" + +#include "TestItem.h" + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +class QDate; +class QString; +class QUrl; + +namespace QPatternistSDK +{ + class XMLWriter; + + /** + * @short A generic abstract base class for test cases. + * + * @ingroup PatternistSDK + * @author Frans Englich + */ + class Q_PATTERNISTSDK_EXPORT TestCase : public TestItem + { + public: + /** + * Corresponds to the simpleType test:scenarios-enum + */ + enum Scenario + { + /** + * The test case should evaluate normally and that the output + * should match the supplied base line. + */ + Standard = 1, + + /** + * The test case should result in a static error, a parser error. + */ + ParseError = 2, + + /** + * The test case should result in a dynamic error, a runtime error. + */ + RuntimeError = 4, + + Trivial = 8, + + /** + * ParseError and RuntimeError OR'd. + */ + AnyError = RuntimeError | ParseError + + }; + + TestCase(); + virtual ~TestCase(); + + /** + * Executes the test, and returns the result. The returned list + * will always contain exactly one TestResult. + * + * @p stage is ignored when running out-of-process. + */ + virtual TestResult::List execute(const ExecutionStage stage, + TestSuite *ts); + + /** + * Determines the corresponding Scenario enumerator from the string + * representation @p string. + * + * The following mappings are in effect: + * @arg @c Standard "standard" + * @arg @c ParseError "parse-error" + * @arg @c RuntimeError "runtime-error" + */ + static Scenario scenarioFromString(const QString &string); + + /** + * @return always @c true + */ + virtual bool isFinalNode() const; + + /** + * Calling this function makes no sense, so it always + * performs an Q_ASSERT check. + */ + virtual void appendChild(TreeItem *); + + /** + * Calling this function makes no sense, so it always + * performs an Q_ASSERT check. + */ + virtual TreeItem *child(const unsigned int) const; + + /** + * @return always zero + */ + virtual unsigned int childCount() const; + + /** + * @return always an empty list. + */ + virtual TreeItem::List children() const; + + /** + * A description of the test case for human consumption. + */ + virtual QString description() const = 0; + + /** + * The title of the test. This can be the identifier of the test, for example. + */ + virtual QString title() const = 0; + + /** + * Whether this test case only make use of XPath features. + * + * @returns @c false if the test case exercises any XQuery feature + * which is not available in XPath 2.0. + */ + virtual bool isXPath() const = 0; + + /** + * The full name of the creator of the test case. For example, "Frans Englich". + */ + virtual QString creator() const = 0; + + /** + * The date of when the test case was created or last modified. + */ + virtual QDate lastModified() const = 0; + + /** + * The test's source code. That is, the XPath/XQuery code for the test. + * + * @param ok the function sets this value to @c false if loading the query + * failed, and returns a description of the error for human consumption. If + * everything went ok, @p ok is set to @c true, and the query is returned. + */ + virtual QString sourceCode(bool &ok) const = 0; + + /** + * The path to the file containing the code of the test case. + */ + virtual QUrl testCasePath() const = 0; + + /** + * The test case's identifier. For example, "Literals001". + */ + virtual QString name() const = 0; + + /** + * What kind of test this is. For example, whether the test case + * should result in a parser error or should evaluate without errors. + * + * The vast common case is that one Scenario is returned; the bit signifiance + * is for the TestCase sub-class UserTestCase. + */ + virtual Scenario scenario() const = 0; + + static QString displayName(const Scenario scen); + + /** + * @returns the valid test baselines for this test case. If only + * one outcome is valid, the returned list only contains + * that baseline. + */ + virtual TestBaseLine::List baseLines() const = 0; + + virtual TestResult *testResult() const; + + virtual ResultSummary resultSummary() const; + + void toXML(XMLWriter &receiver) const; + + virtual QPatternist::ExternalVariableLoader::Ptr externalVariableLoader() const = 0; + + /** + * @short The XML document that should be used as focus. If none should + * be used, and hence the focus be undefined, a default constructed + * QUrl is returned. + */ + virtual QUrl contextItemSource() const = 0; + + /** + * Returns by default QXmlQuery::XQuery10. + */ + virtual QXmlQuery::QueryLanguage language() const; + + virtual QXmlName initialTemplateName() const; + private: + TestResult::List execute(const ExecutionStage stage); + TestResult *createTestResult(const TestResult::Status status, + const QString &comment) const; + + QPointer m_result; + }; +} + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif +// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternssdk/TestContainer.cpp b/tests/auto/xmlpatternssdk/TestContainer.cpp new file mode 100644 index 0000000..ec6196c --- /dev/null +++ b/tests/auto/xmlpatternssdk/TestContainer.cpp @@ -0,0 +1,151 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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 "TestContainer.h" + +using namespace QPatternistSDK; + +TestContainer::TestContainer() : m_deleteChildren(true) +{ +} + +TestContainer::~TestContainer() +{ + if(m_deleteChildren) + qDeleteAll(m_children); +} + +TestResult::List TestContainer::execute(const ExecutionStage stage, + TestSuite *ts) +{ + Q_ASSERT(ts); + const unsigned int c = m_children.count(); + TestResult::List result; + + for(unsigned int i = 0; i != c; ++i) + result += static_cast(child(i))->execute(stage, ts); + + return result; +} + +TestItem::ResultSummary TestContainer::resultSummary() const +{ + const int c = childCount(); + int total = 0; + int pass = 0; + + for(int i = 0; i != c; ++i) + { + TestItem *t = static_cast(child(i)); + const ResultSummary sum(t->resultSummary()); + pass += sum.first; + total += sum.second; + } + + return ResultSummary(pass, total); +} + +TreeItem::List TestContainer::children() const +{ + return m_children; +} + +void TestContainer::appendChild(TreeItem *item) +{ + /* When one of our children changes, we changes. */ + connect(item, SIGNAL(changed(TreeItem *)), SIGNAL(changed(TreeItem *))); + m_children.append(item); +} + +TreeItem *TestContainer::child(const unsigned int rowP) const +{ + return m_children.value(rowP); +} + +unsigned int TestContainer::childCount() const +{ + return m_children.count(); +} + +void TestContainer::setTitle(const QString &titleP) +{ + m_title = titleP; +} + +QString TestContainer::title() const +{ + return m_title; +} + +bool TestContainer::isFinalNode() const +{ + return false; +} + +int TestContainer::columnCount() const +{ + return 4; +} + +QString TestContainer::description() const +{ + return m_description; +} + +void TestContainer::setDescription(const QString &desc) +{ + m_description = desc; +} + +void TestContainer::setDeleteChildren(const bool val) +{ + m_deleteChildren = val; +} + +void TestContainer::removeLast() +{ + m_children.removeLast(); +} + +// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternssdk/TestContainer.h b/tests/auto/xmlpatternssdk/TestContainer.h new file mode 100644 index 0000000..5b93491 --- /dev/null +++ b/tests/auto/xmlpatternssdk/TestContainer.h @@ -0,0 +1,123 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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$ +** +****************************************************************************/ + +#ifndef PatternistSDK_TestContainer_H +#define PatternistSDK_TestContainer_H + +#include "Global.h" +#include "TestItem.h" + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +namespace QPatternistSDK +{ + /** + * @short an abstract base class, containing + * an appropriate implementation of TestItem for sub-classes + * which can contain other TestItem instances. + * + * @ingroup PatternistSDK + * @author Frans Englich + */ + class Q_PATTERNISTSDK_EXPORT TestContainer : public TestItem + { + public: + virtual ~TestContainer(); + virtual void appendChild(TreeItem *item); + virtual TreeItem *child(const unsigned int row) const; + virtual unsigned int childCount() const; + + /** + * @returns the TestResults of this TestContainer's children. + */ + virtual TestResult::List execute(const ExecutionStage stage, + TestSuite *ts); + + QString title() const; + void setTitle(const QString &title); + + virtual TreeItem::List children() const; + + /** + * @return always 2 + */ + virtual int columnCount() const; + + virtual bool isFinalNode() const; + + virtual ResultSummary resultSummary() const; + virtual QString description() const; + virtual void setDescription(const QString &desc); + + /** + * Determines whether TestContainer will delete its children upon + * destruction. By default, it will. + */ + void setDeleteChildren(const bool val); + + /** + * Removes the last appended child. + */ + void removeLast(); + + protected: + /** + * Constructor, protected. TestContainer is an abstract class, + * and is not ment to be instantiated, but sub classed. + */ + TestContainer(); + + private: + TreeItem::List m_children; + QString m_title; + QString m_description; + bool m_deleteChildren; + }; +} + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif +// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternssdk/TestGroup.cpp b/tests/auto/xmlpatternssdk/TestGroup.cpp new file mode 100644 index 0000000..f2cd2bd --- /dev/null +++ b/tests/auto/xmlpatternssdk/TestGroup.cpp @@ -0,0 +1,143 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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 + +#include "TestGroup.h" + +using namespace QPatternistSDK; + +TestGroup::TestGroup(TreeItem *p) : m_parent(p) +{ +} + +QVariant TestGroup::data(const Qt::ItemDataRole role, int column) const +{ + if(role != Qt::DisplayRole && role != Qt::BackgroundRole && role != Qt::ToolTipRole) + return QVariant(); + + /* In ResultSummary, the first is the amount of passes and the second is the total. */ + const ResultSummary sum(resultSummary()); + const int failures = sum.second - sum.first; + + switch(role) + { + case Qt::DisplayRole: + { + + switch(column) + { + case 0: + return title(); + case 1: + /* Passes. */ + return QString::number(sum.first); + case 2: + /* Failures. */ + return QString::number(failures); + case 3: + /* Total. */ + return QString::number(sum.second); + default: + { + Q_ASSERT(false); + return QString(); + } + } + } + case Qt::BackgroundRole: + { + switch(column) + { + case 1: + { + if(sum.first) + { + /* Pass. */ + return Qt::green; + } + else + return QVariant(); + } + case 2: + { + if(failures) + { + /* Failure. */ + return Qt::red; + } + else + return QVariant(); + } + default: + return QVariant(); + } + } + case Qt::ToolTipRole: + { + return description(); + } + default: + { + Q_ASSERT_X(false, Q_FUNC_INFO, "This shouldn't be reached"); + return QVariant(); + } + } +} + +void TestGroup::setNote(const QString &n) +{ + m_note = n; +} + +QString TestGroup::note() const +{ + return m_note; +} + +TreeItem *TestGroup::parent() const +{ + return m_parent; +} + +// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternssdk/TestGroup.h b/tests/auto/xmlpatternssdk/TestGroup.h new file mode 100644 index 0000000..5f4798f --- /dev/null +++ b/tests/auto/xmlpatternssdk/TestGroup.h @@ -0,0 +1,93 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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$ +** +****************************************************************************/ + +#ifndef PatternistSDK_TestGroup_H +#define PatternistSDK_TestGroup_H + +#include + +#include "TestContainer.h" + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +namespace QPatternistSDK +{ + /** + * @short Groups test groups and test cases into a group. + * + * TestGroup corresponds to the @c test-group element in XQTSCatalog.xsd. + * + * @ingroup PatternistSDK + * @author Frans Englich + */ + class Q_PATTERNISTSDK_EXPORT TestGroup : public TestContainer + { + public: + TestGroup(TreeItem *parent); + + /** + * @returns the parent of this group. Is either another group, or + * the TestSuite instance governing this tree. + */ + virtual TreeItem *parent() const; + + virtual QVariant data(const Qt::ItemDataRole role, int column) const; + + QString note() const; + + void setName(const QString &name); + void setNote(const QString ¬e); + + private: + QString m_name; + QString m_note; + TreeItem *m_parent; + }; +} + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif +// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternssdk/TestItem.h b/tests/auto/xmlpatternssdk/TestItem.h new file mode 100644 index 0000000..0b3c606 --- /dev/null +++ b/tests/auto/xmlpatternssdk/TestItem.h @@ -0,0 +1,133 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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$ +** +****************************************************************************/ + +#ifndef PatternistSDK_TestItem_H +#define PatternistSDK_TestItem_H + +#include "TestResult.h" +#include "TreeItem.h" + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +template struct QPair; + +namespace QPatternistSDK +{ + class XMLWriter; + class TestSuite; + + /** + * @short base class for all classes which + * represent an element in an XQuery Test Suite catalog. + * + * @ingroup PatternistSDK + * @author Frans Englich + */ + class Q_PATTERNISTSDK_EXPORT TestItem : public TreeItem + { + public: + + /** + * Determines how far an test case execution should go. + */ + enum ExecutionStage + { + /** + * The query will not be run. It will only go through the (whole) compilation stage. + */ + CompileOnly = 1, + + /** + * The query will be compiled and run, as ordinary. + */ + CompileAndRun + }; + + /** + * Represents a summary of test results for a collection + * of tests. QPair::first contains the amount of + * passed tests; QPair::second contains the count of + * all tests. For example TestCase::summary() returns + * ResultSummary(0, 1) or ResultSummary(1, 1) depending + * on whether the TestCase have succeeded or not. + */ + typedef QPair ResultSummary; + + /** + * Executes the test case(s) this TestItem represents, + * and return the TestResult. For example, the TestGroup + * returns the result of its children concatenated, while + * TestCase always returns a list containing one + * TestResult(what it evaluated to). + */ + virtual TestResult::List execute(const ExecutionStage stage, + TestSuite *ts) = 0; + + /** + * @todo Rename this function. Perhaps create a type() hierarchy + * instead. + */ + virtual bool isFinalNode() const = 0; + + /** + * @returns a ResultSummary for this TestItem. + */ + virtual ResultSummary resultSummary() const = 0; + + /** + * Serializes into the corresponding elements attributes + * specified in XQTSCatalog.xsd. + * + * @note Sub-classes must assume the XQTSCatalog namespace + * is the default namespace, and not add any namespace declarations. + */ + //virtual void toXML(XMLWriter &receiver) const = 0; + }; +} + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif +// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternssdk/TestResult.cpp b/tests/auto/xmlpatternssdk/TestResult.cpp new file mode 100644 index 0000000..2374bc0 --- /dev/null +++ b/tests/auto/xmlpatternssdk/TestResult.cpp @@ -0,0 +1,158 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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 "qdebug_p.h" +#include "Global.h" +#include "XMLWriter.h" + +#include "TestResult.h" + +using namespace QPatternistSDK; +using namespace QPatternist; + +QString TestResult::displayName(const TestResult::Status stat) +{ + switch(stat) + { + case Pass: + return QLatin1String("pass"); + case Fail: + return QLatin1String("fail"); + case NotTested: + return QLatin1String("not tested"); + case Unknown: + Q_ASSERT(false); + } + + Q_ASSERT(false); + return QString(); +} + +TestResult::Status TestResult::statusFromString(const QString &string) +{ + if(string == QLatin1String("pass")) + return Pass; + else if(string == QLatin1String("fail")) + return Fail; + else if(string == QLatin1String("not tested")) + return NotTested; + else + { + Q_ASSERT(false); + return Fail; + } +} + +TestResult::TestResult(const QString &n, + const Status s, + ASTItem *tree, + const ErrorHandler::Message::List &ers, + const QPatternist::Item::List &itemsP, + const QString &serialized) : m_status(s), + m_messages(ers), + m_astTree(tree), + m_testName(n), + m_items(itemsP), + m_asSerialized(serialized) +{ + Q_ASSERT(!n.isEmpty()); + Q_ASSERT(s != 0); +} + +TestResult::~TestResult() +{ + delete m_astTree; +} + +void TestResult::toXML(XMLWriter &receiver) const +{ + QXmlAttributes atts; + atts.append(QLatin1String("name"), QString(), QLatin1String("name"), m_testName); + atts.append(QLatin1String("result"), QString(), QLatin1String("result"), displayName(m_status)); + + if(!m_comment.isEmpty()) + atts.append(QLatin1String("comment"), QString(), QLatin1String("comment"), m_comment); + + receiver.startElement(QLatin1String("test-case"), atts); + receiver.endElement(QLatin1String("test-case")); +} + +void TestResult::setComment(const QString &comm) +{ + m_comment = comm; +} + +TestResult::Status TestResult::status() const +{ + return m_status; +} + +QString TestResult::comment() const +{ + return m_comment; +} + +ASTItem *TestResult::astTree() const +{ + return m_astTree; +} + +ErrorHandler::Message::List TestResult::messages() const +{ + return m_messages; +} + +QPatternist::Item::List TestResult::items() const +{ + return m_items; +} + +QString TestResult::asSerialized() const +{ + pDebug() << "asSerialized: " << m_asSerialized; + return m_asSerialized; +} + +// vim: et:ts=4:sw=4:sts=4 + diff --git a/tests/auto/xmlpatternssdk/TestResult.h b/tests/auto/xmlpatternssdk/TestResult.h new file mode 100644 index 0000000..6951f90 --- /dev/null +++ b/tests/auto/xmlpatternssdk/TestResult.h @@ -0,0 +1,179 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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$ +** +****************************************************************************/ + +#ifndef PatternistSDK_TestResult_H +#define PatternistSDK_TestResult_H + +#include +#include +#include +#include + +#include +#include "ErrorHandler.h" + +#include "ASTItem.h" + + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +namespace QPatternistSDK +{ + class ASTItem; + class XMLWriter; + + /** + * @short represents the result produced by running a test case. + * + * This information TestResult houses is: + * + * - The result status() of the run. Whether the test case succeeded or not, for example. + * - The astTree() which reflects the compiled test case + * - The messages issued when compiling and running the test case, retrievable via messages() + * - The data -- XPath Data Model items() -- the test case evaluated to, if any. + * + * @ingroup PatternistSDK + * @author Frans Englich + */ + class Q_PATTERNISTSDK_EXPORT TestResult : public QObject + { + Q_OBJECT + + public: + enum Status + { + /** + * Used when the status is unknown. + */ + Unknown = 0, + + /** + * The test case passed. + */ + Pass, + + /** + * The test case failed. + */ + Fail, + + /** + * The test was not run. Similar to "SKIP". + */ + NotTested + }; + + /** + * A list of TestResult instances. + */ + typedef QList > List; + + /** + * Constructs a TestResult. + * + * @param testName the name of the test. For example, @c Literal-001. + * @param astTree may be @c null, signalling no AST being available, or point to one. + * @param status the result status of running the test-case. Whether the test-case + * passed or failed, and so forth. + * @param errors the errors and warnings that were reported while running the test-case + * @param items the XDM items that were outputted, if any + * @param serialized the output when serialized + */ + TestResult(const QString &testName, + const Status status, + ASTItem *astTree, + const ErrorHandler::Message::List &errors, + const QPatternist::Item::List &items, + const QString &serialized); + + virtual ~TestResult(); + + Status status() const; + + QString comment() const; + void setComment(const QString &comment); + + QPatternist::Item::List items() const; + + ErrorHandler::Message::List messages() const; + + /** + * Serializes itself to @p receiver, into a test-case element, + * as per @c XQTSResult.xsd. + */ + void toXML(XMLWriter &receiver) const; + + ASTItem *astTree() const; + + /** + * @returns a string representation for @p status, as per the anonymous + * type inside the type test-case, in @c XQTSResult.xsd. For example, if @p status + * is NotTested, is "not tested" returned. + */ + static QString displayName(const TestResult::Status status); + + static Status statusFromString(const QString &string); + + /** + * @returns the output of this test result(if any) as when + * being serialized. + */ + QString asSerialized() const; + + private: + const Status m_status; + QString m_comment; + const ErrorHandler::Message::List m_messages; + QPointer m_astTree; + QString m_testName; + const QPatternist::Item::List m_items; + const QString m_asSerialized; + }; +} + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif +// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternssdk/TestResultHandler.cpp b/tests/auto/xmlpatternssdk/TestResultHandler.cpp new file mode 100644 index 0000000..b87d481 --- /dev/null +++ b/tests/auto/xmlpatternssdk/TestResultHandler.cpp @@ -0,0 +1,98 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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 "Global.h" + +#include "TestResultHandler.h" + +using namespace QPatternistSDK; + +TestResultHandler::TestResultHandler() +{ + /* Fifteen thousand. When finished, we squeeze them. */ + m_result.reserve(15000); + m_comments.reserve(1000); /* Comments are only used for stuff that crash, more or less. */ +} + +bool TestResultHandler::startElement(const QString &namespaceURI, + const QString &localName, + const QString &, + const QXmlAttributes &atts) +{ + /* We only care about 'test-case', ignore everything else. */ + if(localName != QLatin1String("test-case") || + namespaceURI != Global::xqtsResultNS) + return true; + + /* The 'comments' attribute is optional. */ + Q_ASSERT_X(atts.count() == 2 || atts.count() == 3, Q_FUNC_INFO, + "The input appears to not conform to XQTSResult.xsd"); + + Q_ASSERT_X(!m_result.contains(atts.value(QLatin1String("name"))), + Q_FUNC_INFO, + qPrintable(QString::fromLatin1("A test result for test case %1 has " + "already been read(duplicate entry it seems).").arg(atts.value(QLatin1String("name"))))); + + m_result.insert(atts.value(0), TestResult::statusFromString(atts.value(QLatin1String("result")))); + + return true; +} + +bool TestResultHandler::endDocument() +{ + m_result.squeeze(); + m_comments.squeeze(); + return true; +} + +TestResultHandler::Hash TestResultHandler::result() const +{ + return m_result; +} + +TestResultHandler::CommentHash TestResultHandler::comments() const +{ + return m_comments; +} + +// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternssdk/TestResultHandler.h b/tests/auto/xmlpatternssdk/TestResultHandler.h new file mode 100644 index 0000000..a786ac4 --- /dev/null +++ b/tests/auto/xmlpatternssdk/TestResultHandler.h @@ -0,0 +1,115 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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$ +** +****************************************************************************/ + +#ifndef PatternistSDK_TestResultHandler_H +#define PatternistSDK_TestResultHandler_H + +#include +#include +#include + +#include "TestResult.h" + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +namespace QPatternistSDK +{ + /** + * @short Reads XML in the @c XQTSResult.xsd format, and provides access to + * the reported results. + * + * @author Frans Englich + * @ingroup PatternistSDK + */ + class Q_PATTERNISTSDK_EXPORT TestResultHandler : public QXmlDefaultHandler + { + public: + /** + * A hash where the key is the class's name, that is test-case/@@name, + * and the value the test's result status. + */ + typedef QHash Hash; + + /** + * A hash mapping test-case names to their' comments. + */ + typedef QHash CommentHash; + + /** + * Creates a TestResultHandler that will read @p file when run() is called. + */ + TestResultHandler(); + + /** + * Performs finalization. + */ + virtual bool endDocument(); + + /** + * Reads the test-case element and its attributes, everything else is ignored. + */ + virtual bool startElement(const QString &namespaceURI, + const QString &localName, + const QString &qName, + const QXmlAttributes &atts); + /** + * @note Do not reimplement this function. + * @returns the result obtained from reading the XML file. + */ + Hash result() const; + + CommentHash comments() const; + + private: + Q_DISABLE_COPY(TestResultHandler) + Hash m_result; + CommentHash m_comments; + }; +} + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif +// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternssdk/TestSuite.cpp b/tests/auto/xmlpatternssdk/TestSuite.cpp new file mode 100644 index 0000000..2c3e49c --- /dev/null +++ b/tests/auto/xmlpatternssdk/TestSuite.cpp @@ -0,0 +1,269 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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 +#include +#include + +#include "Global.h" +#include "TestSuiteHandler.h" +#include "TestSuiteResult.h" +#include "XMLWriter.h" +#include "XSLTTestSuiteHandler.h" +#include "XSDTestSuiteHandler.h" +#include "qdebug_p.h" + +#include "TestSuite.h" + +using namespace QPatternistSDK; +using namespace QPatternist; + +TestSuite::TestSuite() +{ +} + +QVariant TestSuite::data(const Qt::ItemDataRole role, int column) const +{ + if(role != Qt::DisplayRole) + return QVariant(); + + switch(column) + { + case 0: + return title(); + case 1: + return QString(); + default: + { + Q_ASSERT(false); + return QString(); + } + } +} + +TestSuiteResult *TestSuite::runSuite() +{ + const QDate date(QDate::currentDate()); + TestResult::List result(execute(CompileAndRun, this)); + + return new TestSuiteResult(version(), date, result); +} + +TestSuite *TestSuite::openCatalog(const QUrl &catalogURI, + QString &errorMsg, + const bool useExclusionList, + SuiteType suiteType) +{ + pDebug() << "Opening catalog:" << catalogURI.toString(); + QFile ts(catalogURI.toLocalFile()); + Q_ASSERT(catalogURI.isValid()); + + if(!ts.exists()) + { + errorMsg = QString::fromLatin1("The test suite catalog \"%1\" could not be found.\n") + .arg(ts.fileName()); + return 0; + } + + const QFileInfo info(ts); + + if(!info.isReadable()) + { + errorMsg = QString::fromLatin1("Cannot read the test suite catalog.\n"); + return 0; + } + else if(!info.isFile()) + { + errorMsg = QString::fromLatin1("The specified test suite catalog \"%1\" is not a file. " + "The test suite catalog must be a file, it cannot be " + "a directory, for example.\n") + .arg(ts.fileName()); + return 0; + } + else if(!ts.open(QIODevice::ReadOnly | QIODevice::Text)) + { + errorMsg = QString::fromLatin1("Failed to open the test suite catalog, \"%1\".\n") + .arg(ts.fileName()); + return 0; + } + + return openCatalog(&ts, errorMsg, catalogURI, useExclusionList, suiteType); +} + +TestSuite *TestSuite::openCatalog(QIODevice *input, + QString &errorMsg, + const QUrl &fileName, + const bool useExclusionList, + SuiteType suiteType) +{ + Q_ASSERT(input); + + QXmlSimpleReader reader; + typedef QPatternist::AutoPtr HandlerPtr; + + HandlerPtr loader; + + switch (suiteType) { + case XQuerySuite: loader = HandlerPtr(new TestSuiteHandler(fileName, useExclusionList)); break; + case XsltSuite: loader = HandlerPtr(new XSLTTestSuiteHandler(fileName)); break; + case XsdSuite: loader = HandlerPtr(new XSDTestSuiteHandler(fileName)); break; + default: Q_ASSERT(false); break; + } + + reader.setContentHandler(loader.data()); + + QXmlInputSource source(input); + + if(!reader.parse(source)) + { + errorMsg = QString::fromLatin1("Couldn't parse %1").arg(fileName.toString()); + return 0; + } + + TestSuite *suite = 0; + switch (suiteType) { + case XQuerySuite: suite = static_cast(loader.data())->testSuite(); break; + case XsltSuite: suite = static_cast(loader.data())->testSuite(); break; + case XsdSuite: suite = static_cast(loader.data())->testSuite(); break; + default: Q_ASSERT(false); break; + } + + if(suite) + return suite; + + errorMsg = QString::fromLatin1("Failed to load \"%1\". " + "It appears to have no test-suite element.\n").arg(fileName.toString()); + return 0; +} + +void TestSuite::toXML(XMLWriter &receiver, TestCase *const tc) const +{ + // TODO startElement() endElement() calls can be simplified. + + Q_ASSERT(tc); + + receiver.startDocument(); + /* */ + QXmlAttributes test_suiteAtts; + test_suiteAtts.append(QLatin1String("CatalogDesignDate"), QString(), + QLatin1String("CatalogDesignDate"), m_designDate.toString(Qt::ISODate)); + test_suiteAtts.append(QLatin1String("version"), QString(), + QLatin1String("version"), m_version); + test_suiteAtts.append(QLatin1String("SourceOffsetPath"), QString(), + QLatin1String("SourceOffsetPath"), QString()); + test_suiteAtts.append(QLatin1String("ResultOffsetPath"), QString(), + QLatin1String("ResultOffsetPath"), QString()); + test_suiteAtts.append(QLatin1String("XQueryQueryOffsetPath"), QString(), + QLatin1String("XQueryQueryOffsetPath"), QString()); + test_suiteAtts.append(QLatin1String("QueryXQueryOffsetPath"), QString(), + QLatin1String("QueryXQueryOffsetPath"), QString()); + test_suiteAtts.append(QLatin1String("XQueryFileExtension"), QString(), + QLatin1String("XQueryFileExtension"), QString()); + test_suiteAtts.append(QLatin1String("XQueryXFileExtension"), QString(), + QLatin1String("XQueryXFileExtension"), QString()); + + receiver.startPrefixMapping(QString(), Global::xqtsCatalogNS); + receiver.startElement(QLatin1String("test-suite"), test_suiteAtts); + receiver.endPrefixMapping(QString()); + + /* */ + QXmlAttributes test_groupAtts; + test_groupAtts.append(QLatin1String("GeneratedGroupByPatternistSDKRunSuite"), QString(), + QLatin1String("GeneratedGroupByPatternistSDKRunSuite"), QString()); + receiver.startElement(QLatin1String("test-group"), test_groupAtts); + + /* */ + receiver.startElement(QLatin1String("GroupInfo"), test_groupAtts); + + /* */ + receiver.startElement(QLatin1String("title"), test_groupAtts); + receiver.characters(QLatin1String("Contains the test case generated by PatternistSDKRunSuite.")); + + /* */ + receiver.endElement(QLatin1String("title")); + + /* */ + receiver.startElement(QLatin1String("description"), test_groupAtts); + /* */ + receiver.endElement(QLatin1String("description")); + + /* */ + receiver.endElement(QLatin1String("GroupInfo")); + + /* */ + tc->toXML(receiver); + /* */ + + /* */ + receiver.endElement(QLatin1String("test-group")); + + /* */ + receiver.endElement(QLatin1String("test-suite")); +} + +QString TestSuite::version() const +{ + return m_version; +} + +QDate TestSuite::designDate() const +{ + return m_designDate; +} + +void TestSuite::setVersion(const QString &ver) +{ + m_version = ver; +} + +void TestSuite::setDesignDate(const QDate &date) +{ + m_designDate = date; +} + +TestContainer *TestSuite::parent() const +{ + return 0; +} + +// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternssdk/TestSuite.h b/tests/auto/xmlpatternssdk/TestSuite.h new file mode 100644 index 0000000..d14dc62 --- /dev/null +++ b/tests/auto/xmlpatternssdk/TestSuite.h @@ -0,0 +1,160 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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$ +** +****************************************************************************/ + +#ifndef PatternistSDK_TestSuite_H +#define PatternistSDK_TestSuite_H + +#include +#include + +#include "TestContainer.h" + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +class QIODevice; +class QUrl; +class QVariant; + +namespace QPatternistSDK +{ + class TestCase; + class TestSuiteResult; + + /** + * @short Represents a test suite in the W3C XML Query Test Suite format. + * + * TestSuite contains the test suite's test cases and meta data. + * + * @ingroup PatternistSDK + * @author Frans Englich + */ + class Q_PATTERNISTSDK_EXPORT TestSuite : public TestContainer + { + public: + /** + * Describes the type of test suite. + */ + enum SuiteType + { + XQuerySuite, ///< The test suite for XQuery + XsltSuite, ///< The test suite for XSLT + XsdSuite ///< The test suite for XML Schema + }; + + TestSuite(); + + virtual QVariant data(const Qt::ItemDataRole role, int column) const; + + /** + * The version of the catalog test suite. For example, "0.8.0". + */ + QString version() const; + + /** + * When the catalog was designed, last modified. + */ + QDate designDate() const; + + void setVersion(const QString &version); + void setDesignDate(const QDate &version); + + /** + * @return always @c null + */ + virtual TestContainer *parent() const; + + /** + * Creates and returns a pointer to a TestSuite instance, which + * was instantiated from the XQuery Test Suite catalog file @p catalogFile. + * + * If loading went wrong, @c null is returned and @p errorMsg is set with a + * human readable message string. However, @p catalogFile is not validated; + * if the XML file is not valid against the XQTS task force's W3C XML Schema, the + * behavior and result for this function is undefined. + * + * This function blocks. Currently is only local files supported. + */ + static TestSuite *openCatalog(const QUrl &catalogFile, + QString &errorMsg, + const bool useExclusionList, + SuiteType type); + + void toXML(XMLWriter &receiver, TestCase *const tc) const; + + /** + * Evaluates all the test cases in this TestSuite, and returns + * it all in a TestSuiteResult. + */ + TestSuiteResult *runSuite(); + + private: + /** + * Essentially similar to open(const QUrl &, QString &errorMsg), + * with the difference that it takes directly a QIODevice as input, + * as opposed to a file name locating the catalog file to read. + * + * @param input the test suite catalog + * @param fileName this URI is used for resolving relative paths inside + * the catalog file into absolute. + * @param errorMsg if an error occurs, this QString is set to contain the message. + * Whether an error occurred can therefore be determined by checking if this variable + * still is @c null after the call + * @param useExclusionList whether the excludeTestGroups.txt file should be used + * to exclude test groups for this catalog + */ + static TestSuite *openCatalog(QIODevice *input, + QString &errorMsg, + const QUrl &fileName, + const bool useExclusionList, + SuiteType type); + QString m_version; + QDate m_designDate; + }; +} + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif +// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternssdk/TestSuiteHandler.cpp b/tests/auto/xmlpatternssdk/TestSuiteHandler.cpp new file mode 100644 index 0000000..7c687f3 --- /dev/null +++ b/tests/auto/xmlpatternssdk/TestSuiteHandler.cpp @@ -0,0 +1,312 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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 "qacceltreeresourceloader_p.h" +#include "qnetworkaccessdelegator_p.h" + +#include "Global.h" +#include "TestBaseLine.h" +#include "TestGroup.h" + +#include "TestSuiteHandler.h" + +using namespace QPatternistSDK; + +QNetworkAccessManager s_networkManager; + +TestSuiteHandler::TestSuiteHandler(const QUrl &catalogFile, + const bool useEList) : m_ts(0) + , m_container(0) + , m_tc(0) + , m_baseLine(0) + , m_catalogFile(catalogFile) + , m_exclusionList(readExclusionList(useEList)) + , m_isExcluding(false) +{ + Q_ASSERT(!m_catalogFile.isRelative()); +} + +QStringList TestSuiteHandler::readExclusionList(const bool useExclusionList) const +{ + if(!useExclusionList) + return QStringList(); + + QStringList avoid; + + /* These test groups are for features we don't support. + * + * Originally these were stored in a text file pulled in with Qt resources, but + * it was not possible to get it to link on some HP-UX and Intel-icc platforms. */ + + avoid << "SchemaImport"; // The schema import feature + avoid << "SchemaValidation"; // The validate expression(requires schema import) + avoid << "StaticTyping"; // Pessimistic static typing checking + avoid << "TrivialEmbedding"; // XQueryX inside XQuery + avoid << "XMark"; // We're currently too buggy for running these tests. + + return avoid; +} + +bool TestSuiteHandler::startElement(const QString &namespaceURI, + const QString &localName, + const QString &/*qName*/, + const QXmlAttributes &atts) +{ + if(namespaceURI != Global::xqtsCatalogNS) + return true; + else if(m_isExcluding) + { + if(localName == QLatin1String("test-group")) + { + m_testGroupName.push(atts.value(QLatin1String("name"))); + return true; + } + else + return true; + } + + /* The elements are handled roughly in the order of highest occurrence in the catalog file. */ + if(localName == QLatin1String("test-case")) + { + XQTSTestCase *const c = new XQTSTestCase( + TestCase::scenarioFromString(atts.value(QLatin1String("scenario"))), m_container); + + c->setName(atts.value(QLatin1String("name"))); + c->setCreator(atts.value(QLatin1String("Creator"))); + c->setIsXPath(Global::readBoolean(atts.value(QLatin1String("is-XPath2")))); + c->setLastModified(QDate::fromString(atts.value(QLatin1String("version-drop")), Qt::ISODate)); + Q_ASSERT(c->lastModified().isNull() || c->lastModified().isValid()); + + m_currentQueryPath = m_queryOffset.resolved(QUrl(atts.value(QLatin1String("FilePath")))); + m_currentBaselinePath = m_baselineOffset.resolved(QUrl(atts.value(QLatin1String("FilePath")))); + + m_container->appendChild(c); + m_tc = c; + } + else if(localName == QLatin1String("query")) + { + m_tc->setQueryPath(m_currentQueryPath.resolved(atts.value(QLatin1String("name")) + + m_xqueryFileExtension)); + } + else if(localName == QLatin1String("input-file") || + localName == QLatin1String("input-URI")) + { + m_currentInputVariable = atts.value(QLatin1String("variable")); + } + else if(localName == QLatin1String("output-file")) + { + m_baseLine = new TestBaseLine(TestBaseLine::identifierFromString(atts.value(QLatin1String("compare")))); + } + else if(localName == QLatin1String("expected-error")) + { + m_baseLine = new TestBaseLine(TestBaseLine::ExpectedError); + } + else if(localName == QLatin1String("test-group")) + { + m_testGroupName.push(atts.value(QLatin1String("name"))); + + if(m_exclusionList.contains(m_testGroupName.top())) + { + /* Ok, this group is supposed to be excluded, we don't + * insert it into the tree. */ + m_isExcluding = true; + return true; + } + else + { + Q_ASSERT(m_container); + TestGroup *const newGroup = new TestGroup(m_container); + m_container->appendChild(newGroup); + m_container = newGroup; + } + } + else if(localName == QLatin1String("source")) + { + m_sourceMap.insert(atts.value(QLatin1String("ID")), + m_sourceOffset.resolved(QUrl(atts.value(QLatin1String("FileName"))))); + } + else if(localName == QLatin1String("test-suite")) + { + m_ts = new TestSuite(); + m_ts->setVersion(atts.value(QLatin1String("version"))); + m_ts->setDesignDate(QDate::fromString(atts.value(QLatin1String("CatalogDesignDate")), Qt::ISODate)); + Q_ASSERT(m_ts->designDate().isValid()); + m_container = m_ts; + + m_xqueryFileExtension = atts.value(QLatin1String("XQueryFileExtension")); + m_queryOffset = m_catalogFile.resolved(atts.value(QLatin1String("XQueryQueryOffsetPath"))); + m_baselineOffset = m_catalogFile.resolved(atts.value(QLatin1String("ResultOffsetPath"))); + m_sourceOffset = m_catalogFile.resolved(atts.value(QLatin1String("SourceOffsetPath"))); + } + else if(localName == QLatin1String("input-query")) + { + m_tcSourceInputs.insert(atts.value(QLatin1String("variable")), + ExternalSourceLoader::VariableValue(m_currentQueryPath.resolved(atts.value(QLatin1String("name")) + m_xqueryFileExtension), + ExternalSourceLoader::Query)); + } + + return true; +} + +bool TestSuiteHandler::endElement(const QString &namespaceURI, + const QString &localName, + const QString &/*qName*/) +{ + if(namespaceURI != Global::xqtsCatalogNS) + return true; + + if(m_isExcluding) + { + if(localName == QLatin1String("test-group")) + { + const QString myName(m_testGroupName.pop()); + + if(m_exclusionList.contains(myName)) + { + /* This test-group is being excluded and now we're exiting from it. */ + m_isExcluding = false; + } + } + + return true; + } + + /* The elements are handled roughly in the order of highest occurrence in the catalog file. */ + if(localName == QLatin1String("description")) + { + if(m_tc) + { + /* We're inside a , so the belongs + * to the test-case. */ + m_tc->setDescription(m_ch.simplified()); + } + else + m_container->setDescription(m_ch.simplified()); + } + else if(localName == QLatin1String("test-case")) + { + Q_ASSERT(m_tc->baseLines().count() >= 1); + Q_ASSERT(m_resourceLoader); + m_tc->setExternalVariableLoader(QPatternist::ExternalVariableLoader::Ptr + (new ExternalSourceLoader(m_tcSourceInputs, + m_resourceLoader))); + m_tcSourceInputs.clear(); + + if(!m_contextItemSource.isEmpty()) + { + m_tc->setContextItemSource(QUrl(m_sourceMap.value(m_contextItemSource))); + m_contextItemSource.clear(); + } + + m_tc = 0; + } + else if(localName == QLatin1String("output-file")) + { + m_baseLine->setDetails(m_currentBaselinePath.resolved(m_ch).toString()); + m_tc->addBaseLine(m_baseLine); + } + else if(localName == QLatin1String("input-file")) + { + m_tcSourceInputs.insert(m_currentInputVariable, ExternalSourceLoader::VariableValue(m_sourceMap.value(m_ch), + ExternalSourceLoader::Document)); + } + else if(localName == QLatin1String("expected-error")) + { + m_baseLine->setDetails(m_ch); + m_tc->addBaseLine(m_baseLine); + } + else if(localName == QLatin1String("title")) + { + /* A bit dangerous, the only element with name title in the vocabulary + * is the the child of GroupInfo */ + m_container->setTitle(m_ch.simplified()); + } + else if(localName == QLatin1String("test-group")) + { + m_testGroupName.pop(); + Q_ASSERT(m_container); + m_container = static_cast(m_container->parent()); + Q_ASSERT(m_container); + } + else if(localName == QLatin1String("test-suite")) + { + Q_ASSERT(m_container); + m_container = static_cast(m_container->parent()); + } + else if(localName == QLatin1String("sources")) + { + const QPatternist::NetworkAccessDelegator::Ptr networkDelegator(new QPatternist::NetworkAccessDelegator(&s_networkManager, &s_networkManager)); + + m_resourceLoader = QPatternist::ResourceLoader::Ptr(new QPatternist::AccelTreeResourceLoader(Global::namePool(), + networkDelegator)); + + const ExternalSourceLoader::SourceMap::const_iterator end(m_sourceMap.constEnd()); + ExternalSourceLoader::SourceMap::const_iterator it(m_sourceMap.constBegin()); + + for(; it != end; ++it) + m_resourceLoader->announceDocument(it.value(), QPatternist::ResourceLoader::WillUse); + } + else if(localName == QLatin1String("input-URI")) + { + m_tcSourceInputs.insert(m_currentInputVariable, ExternalSourceLoader::VariableValue(m_sourceMap.value(m_ch), + ExternalSourceLoader::URI)); + } + else if(localName == QLatin1String("contextItem")) + m_contextItemSource = m_ch; + + return true; +} + +bool TestSuiteHandler::characters(const QString &ch) +{ + m_ch = ch; + return true; +} + +TestSuite *TestSuiteHandler::testSuite() const +{ + return m_ts; +} + +// vim: et:ts=4:sw=4:sts=4 + diff --git a/tests/auto/xmlpatternssdk/TestSuiteHandler.h b/tests/auto/xmlpatternssdk/TestSuiteHandler.h new file mode 100644 index 0000000..76156c0 --- /dev/null +++ b/tests/auto/xmlpatternssdk/TestSuiteHandler.h @@ -0,0 +1,169 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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$ +** +****************************************************************************/ + +#ifndef PatternistSDK_TestSuiteHandler_H +#define PatternistSDK_TestSuiteHandler_H + +#include +#include +#include + +#include "ExternalSourceLoader.h" +#include "TestSuite.h" +#include "XQTSTestCase.h" + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +namespace QPatternistSDK +{ + class TestBaseLine; + + /** + * @short Creates a TestSuite from the XQuery Test Suite catalog, + * represented as a SAX stream. + * + * The created TestSuite can be retrieved via testSuite(). + * + * @note TestSuiteHandler assumes the XML is valid by having been validated + * against the W3C XML Schema. It have no safety checks for that the XML format + * is correct but is hard coded for it. Thus, the behavior is undefined if + * the XML is invalid. + * + * @ingroup PatternistSDK + * @author Frans Englich + */ + class Q_PATTERNISTSDK_EXPORT TestSuiteHandler : public QXmlDefaultHandler + { + public: + /** + * @param catalogFile the URI for the catalog file being parsed. This + * URI is used for creating absolute URIs for files mentioned in + * the catalog with relative URIs. + * @param useExclusionList whether excludeTestGroups.txt should be used to ignore + * test groups when loading + */ + TestSuiteHandler(const QUrl &catalogFile, + const bool useExclusionList); + virtual bool characters(const QString &ch); + + virtual bool endElement(const QString &namespaceURI, + const QString &localName, + const QString &qName); + virtual bool startElement(const QString &namespaceURI, + const QString &localName, + const QString &qName, + const QXmlAttributes &atts); + + virtual TestSuite *testSuite() const; + + private: + QStringList readExclusionList(const bool useExclusionList) const; + + TestSuite * m_ts; + TestContainer * m_container; + XQTSTestCase * m_tc; + TestBaseLine * m_baseLine; + QString m_ch; + const QUrl m_catalogFile; + + /** + * The extension of XQuery files. For example, ".xq" + */ + QString m_xqueryFileExtension; + + /** + * The base URI for where the XQuery query files are found. + * It is absolute, resolved against catalogFile. + */ + QUrl m_queryOffset; + + QUrl m_baselineOffset; + QUrl m_sourceOffset; + QUrl m_currentQueryPath; + QUrl m_currentBaselinePath; + + /** + * In the XQTSCatalog.xml, each source file in each test is referred to + * by a key, which can be fully looked up in the @c sources element. This QHash + * maps the keys to absolute URIs pointing to the source files. + */ + ExternalSourceLoader::SourceMap m_sourceMap; + + ExternalSourceLoader::VariableMap m_tcSourceInputs; + + QPatternist::ResourceLoader::Ptr m_resourceLoader; + + /** + * The current value of input-file/\@variable/. + */ + QString m_currentInputVariable; + + /** + * The names of the test groups we're excluding. + */ + const QStringList m_exclusionList; + + /** + * This is set when we're inside a test-group that we're excluding. + */ + bool m_isExcluding; + + /** + * The names of the test groups. + */ + QStack m_testGroupName; + + /** + * Holds the content of the current input-URI element. + */ + QString m_inputURI; + QString m_contextItemSource; + }; +} + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif +// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternssdk/TestSuiteResult.cpp b/tests/auto/xmlpatternssdk/TestSuiteResult.cpp new file mode 100644 index 0000000..4e81859 --- /dev/null +++ b/tests/auto/xmlpatternssdk/TestSuiteResult.cpp @@ -0,0 +1,173 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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 "Global.h" +#include "XMLWriter.h" + +#include "TestSuiteResult.h" + +using namespace QPatternistSDK; + +TestSuiteResult::TestSuiteResult(const QString &testSuiteVersion, + const QDate &runDate, + const TestResult::List &results) : m_testSuiteVersion(testSuiteVersion), + m_runDate(runDate), + m_results(results) +{ +} + +TestSuiteResult::~TestSuiteResult() +{ + qDeleteAll(m_results); +} + +void TestSuiteResult::toXML(XMLWriter &receiver) const +{ + /* If this data needs to be configurable in someway(say, another + * XML format is supported), then break out the info into getters(alternatively, combined + * with setters, or that the class is subclassed), and access the getters instead. + */ + const QString organizationName (QLatin1String("K Desktop Environment(KDE)")); + const QString organizationWebsite (QLatin1String("http://www.kde.org/")); + const QString submittorName (QLatin1String("Frans Englich")); + const QString submittorEmail (QLatin1String("frans.englich@nokia.com")); + const QString implementationVersion (QLatin1String("0.1")); + const QString implementationName (QLatin1String("Patternist")); + const QString implementationDescription (QLatin1String( + "Patternist is an implementation written in C++ " + "and with the Qt/KDE libraries. " + "It is licensed under GNU LGPL and part of KDE, " + "the K Desktop Environment.")); + + /* Not currently serialized: + * - + * - + * - + */ + + receiver.startDocument(); + /* */ + receiver.startPrefixMapping(QString(), Global::xqtsResultNS); + receiver.startElement(QLatin1String("test-suite-result")); + receiver.endPrefixMapping(QString()); + + /* */ + QXmlAttributes implementationAtts; + implementationAtts.append(QLatin1String("name"), QString(), + QLatin1String("name"), implementationName); + implementationAtts.append(QLatin1String("version"), QString(), + QLatin1String("version"), implementationVersion); + receiver.startElement(QLatin1String("implementation"), implementationAtts); + + /* */ + QXmlAttributes organizationAtts; + organizationAtts.append(QLatin1String("name"), QString(), + QLatin1String("name"), organizationName); + organizationAtts.append(QLatin1String("website"), QString(), + QLatin1String("website"), organizationWebsite); + receiver.startElement(QLatin1String("organization"), organizationAtts); + + /* */ + receiver.endElement(QLatin1String("organization")); + + /* */ + QXmlAttributes submittorAtts; + submittorAtts.append(QLatin1String("name"), QString(), QLatin1String("name"), submittorName); + submittorAtts.append(QLatin1String("email"), QString(), QLatin1String("email"), submittorEmail); + receiver.startElement(QLatin1String("submittor"), submittorAtts); + + /* */ + receiver.endElement(QLatin1String("submittor")); + + /* */ + receiver.startElement(QLatin1String("description")); + + /*

*/ + receiver.startElement(QLatin1String("p")); + receiver.characters(implementationDescription); + + /*

*/ + receiver.endElement(QLatin1String("p")); + /*
*/ + receiver.endElement(QLatin1String("description")); + + /*
*/ + receiver.endElement(QLatin1String("implementation")); + + /* */ + receiver.startElement(QLatin1String("syntax")); + receiver.characters(QLatin1String(QLatin1String("XQuery"))); + + /* */ + receiver.endElement(QLatin1String("syntax")); + + /* */ + QXmlAttributes test_runAtts; + test_runAtts.append(QLatin1String("dateRun"), QString(), QLatin1String("dateRun"), m_runDate.toString(QLatin1String("yyyy-MM-dd"))); + receiver.startElement(QLatin1String("test-run"), test_runAtts); + + /* */ + QXmlAttributes test_suiteAtts; + test_suiteAtts.append(QLatin1String("version"), QString(), QLatin1String("version"), m_testSuiteVersion); + receiver.startElement(QLatin1String("test-suite"), test_suiteAtts); + + /* */ + receiver.endElement(QLatin1String("test-suite")); + + /* */ + receiver.endElement(QLatin1String("test-run")); + + /* Serialize the TestResults: tons of test-case elements. */ + const TestResult::List::const_iterator end(m_results.constEnd()); + TestResult::List::const_iterator it(m_results.constBegin()); + + for(; it != end; ++it) + (*it)->toXML(receiver); + + /*
*/ + receiver.endElement(QLatin1String("test-suite-result")); + receiver.endDocument(); +} + +// vim: et:ts=4:sw=4:sts=4 + diff --git a/tests/auto/xmlpatternssdk/TestSuiteResult.h b/tests/auto/xmlpatternssdk/TestSuiteResult.h new file mode 100644 index 0000000..491c2b2 --- /dev/null +++ b/tests/auto/xmlpatternssdk/TestSuiteResult.h @@ -0,0 +1,93 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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$ +** +****************************************************************************/ + +#ifndef PatternistSDK_TestSuiteResult_H +#define PatternistSDK_TestSuiteResult_H + +#include +#include + +#include "TestResult.h" + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +namespace QPatternistSDK +{ + /** + * @short A collection of TestResult instances. + * + * A TestSuiteResult gathers all TestResult instances, and provides + * the toXML() function which serializes it all into a XQuery Test Suite + * result file, conforming to XQTSResult.xsd. + * + * @ingroup PatternistSDK + * @author Frans Englich + */ + class Q_PATTERNISTSDK_EXPORT TestSuiteResult + { + public: + ~TestSuiteResult(); + + TestSuiteResult(const QString &testSuiteVersion, + const QDate &runDate, + const TestResult::List &results); + + /** + * Serializes the test results this TestSuiteResult represents, + * into XQTS test-suite-result document, conformant to XQTSCatalog.xsd. + */ + void toXML(XMLWriter &receiver) const; + + private: + const QString m_testSuiteVersion; + const QDate m_runDate; + const TestResult::List m_results; + }; +} + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif +// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternssdk/TreeItem.cpp b/tests/auto/xmlpatternssdk/TreeItem.cpp new file mode 100644 index 0000000..b34262d --- /dev/null +++ b/tests/auto/xmlpatternssdk/TreeItem.cpp @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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 "TestContainer.h" + +#include "TreeItem.h" + +using namespace QPatternistSDK; + +int TreeItem::row() const +{ + const TreeItem *const p = parent(); + + if(p) + { + /* The const_cast makes it possible for QPointer's constructor + * to implicitly kick in. */ + return p->children().indexOf(const_cast(this)); + } + else + return -1; +} + +// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternssdk/TreeItem.h b/tests/auto/xmlpatternssdk/TreeItem.h new file mode 100644 index 0000000..f5e051f --- /dev/null +++ b/tests/auto/xmlpatternssdk/TreeItem.h @@ -0,0 +1,114 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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$ +** +****************************************************************************/ + +#ifndef PatternistSDK_TreeItem_H +#define PatternistSDK_TreeItem_H + +#include + +#include "Global.h" + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +class QVariant; +template class QList; +template class QPointer; + +namespace QPatternistSDK +{ + /** + * @short TreeItem is a node in a hierachial structure and is used together + * with TreeModel. + * + * TreeItem is abstract base class. Instances of sub-classes of TreeItem + * can be used with TreeModel in order to use hierarchial data in Qt's + * model/view framework. + * + * TreeItem is a QObject in order to be able to be used with QPointer. + * + * @author Frans Englich + * @see TreeModel + * @ingroup PatternistSDK + */ + class Q_PATTERNISTSDK_EXPORT TreeItem : public QObject + { + Q_OBJECT + public: + typedef QList > List; + + virtual ~TreeItem() {} + virtual void appendChild(TreeItem *item) = 0; + virtual TreeItem *child(const unsigned int row) const = 0; + virtual unsigned int childCount() const = 0; + virtual TreeItem *parent() const = 0; + + virtual TreeItem::List children() const = 0; + virtual int columnCount() const = 0; + + /** + * Determines the position among the children of + * this TreeItem's parent. This is done by introspecting the result + * of children(). + */ + int row() const; + + virtual QVariant data(const Qt::ItemDataRole role, int column) const = 0; + + Q_SIGNALS: + /** + * Emitted whenever this item changed. This is used for keeping + * views in synchronization with the item model which houses + * this item. + * + * @param item the item which changed. That is, this TreeItem. + */ + void changed(TreeItem *item); + }; +} + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif +// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternssdk/TreeModel.cpp b/tests/auto/xmlpatternssdk/TreeModel.cpp new file mode 100644 index 0000000..e27f8e0 --- /dev/null +++ b/tests/auto/xmlpatternssdk/TreeModel.cpp @@ -0,0 +1,184 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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 "TestContainer.h" + +#include "TreeModel.h" + +using namespace QPatternistSDK; + +TreeModel::TreeModel(const QStringList columnData, + QObject *p) : QAbstractItemModel(p), + m_root(0), + m_columnData(columnData) +{ +} + +TreeModel::~TreeModel() +{ +} + +QVariant TreeModel::data(const QModelIndex &idx, int role) const +{ + if(!idx.isValid()) + return QVariant(); + + TreeItem *item = static_cast(idx.internalPointer()); + Q_ASSERT(item); + + return item->data(static_cast(role), idx.column()); +} + +QVariant TreeModel::headerData(int section, Qt::Orientation orientation, int role) const +{ + if(orientation == Qt::Horizontal && role == Qt::DisplayRole) + return m_columnData.value(section); + + return QVariant(); +} + +void TreeModel::childChanged(TreeItem *item) +{ + if (item) { + const QModelIndex index = createIndex(item->row(), 0, item); + dataChanged(index, index); + } else { + layoutChanged(); + } +} + +QModelIndex TreeModel::index(int row, int column, const QModelIndex &p) const +{ + const int c = columnCount(p); + + if(row < 0 || column < 0 || column >= c) + return QModelIndex(); + + TreeItem *parentItem; + + if(p.isValid()) + parentItem = static_cast(p.internalPointer()); + else + parentItem = m_root; + + if(!parentItem) + return QModelIndex(); + + TreeItem *childItem = parentItem->child(row); + + if(childItem) + return createIndex(row, column, childItem); + else + return QModelIndex(); +} + +QModelIndex TreeModel::parent(const QModelIndex &idx) const +{ + if(!idx.isValid()) + return QModelIndex(); + + TreeItem *childItem = static_cast(idx.internalPointer()); + Q_ASSERT(childItem); + TreeItem *parentItem = childItem->parent(); + + if(!parentItem || parentItem == m_root) + return QModelIndex(); + + Q_ASSERT(parentItem); + return createIndex(parentItem->row(), 0, parentItem); +} + +Qt::ItemFlags TreeModel::flags(const QModelIndex &idx) const +{ + /* Not sure about this code. */ + if(!idx.isValid()) + return Qt::ItemFlags(); + + return Qt::ItemIsEnabled | Qt::ItemIsSelectable; +} + +int TreeModel::rowCount(const QModelIndex &p) const +{ + if(p.column() > 0) + return 0; + + const TreeItem *parentItem; + + if(p.isValid()) + parentItem = static_cast(p.internalPointer()); + else + { + if(m_root) + parentItem = m_root; + else + return 0; + } + + return parentItem->childCount(); +} + +int TreeModel::columnCount(const QModelIndex &p) const +{ + if(p.isValid()) + return static_cast(p.internalPointer())->columnCount(); + else + return m_columnData.count(); +} + +TreeItem *TreeModel::root() const +{ + return m_root; +} + +void TreeModel::setRoot(TreeItem *r) +{ + TreeItem *const oldRoot = m_root; + m_root = r; + + if(m_root) + connect(r, SIGNAL(changed(TreeItem *)), SLOT(childChanged(TreeItem *))); + reset(); /* Notify views that we have radically changed. */ + delete oldRoot; +} + +// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternssdk/TreeModel.h b/tests/auto/xmlpatternssdk/TreeModel.h new file mode 100644 index 0000000..1d8ea72 --- /dev/null +++ b/tests/auto/xmlpatternssdk/TreeModel.h @@ -0,0 +1,110 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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$ +** +****************************************************************************/ + +#ifndef PatternistSDK_TreeModel_H +#define PatternistSDK_TreeModel_H + +#include +#include +#include +#include + +#include "Global.h" + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +namespace QPatternistSDK +{ + class TreeItem; + + /** + * @short TreeItem is a generic QAbstractItemModel tailored for + * representing hierarchial data. + * + * TreeModel is an item model in Qt's model/view framework. Its + * data consists of TreeItem instances. + * + * @see TreeItem + * @ingroup PatternistSDK + * @author Frans Englich + */ + class Q_PATTERNISTSDK_EXPORT TreeModel : public QAbstractItemModel + { + Q_OBJECT + public: + TreeModel(const QStringList columnData, QObject *parent); + virtual ~TreeModel(); + + virtual QVariant data(const QModelIndex &index, int role) const; + virtual Qt::ItemFlags flags(const QModelIndex &index) const; + virtual QVariant headerData(int section, + Qt::Orientation orientation, + int role = Qt::DisplayRole) const; + virtual QModelIndex index(int row, + int column, + const QModelIndex &parent = QModelIndex()) const; + virtual QModelIndex parent(const QModelIndex &index) const; + virtual int rowCount(const QModelIndex &parent = QModelIndex()) const; + virtual int columnCount(const QModelIndex &parent = QModelIndex()) const; + + TreeItem *root() const; + /** + * Sets @p root to the new root, and deletes the old. + */ + void setRoot(TreeItem *root); + + protected Q_SLOTS: + void childChanged(TreeItem *child); + + private: + QPointer m_root; + const QStringList m_columnData; + }; +} + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif +// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternssdk/Worker.cpp b/tests/auto/xmlpatternssdk/Worker.cpp new file mode 100644 index 0000000..0121099 --- /dev/null +++ b/tests/auto/xmlpatternssdk/Worker.cpp @@ -0,0 +1,258 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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 +#include + +#include "ExitCode.h" + +#include "Worker.h" + +using namespace QPatternistSDK; + +const char *const Worker::m_indent = " "; + +Worker::Worker(QEventLoop &ev, + const QFileInfo &baseline, + const QFileInfo &result) : m_finishedCount(0) + , m_baselineFile(baseline) + , m_resultFile(result) + , m_eventLoop(ev) +{ +} + +void Worker::list(QTextStream &out, const QString &msg, QStringList &list) +{ + Q_ASSERT(!msg.isEmpty()); + + if(list.isEmpty()) + return; + + list.sort(); /* Make it pretty, and easy to read. */ + + out << msg << ":\n"; + + const QStringList::const_iterator end(list.constEnd()); + QStringList::const_iterator it(list.constBegin()); + + for(; it != end; ++it) + out << m_indent << qPrintable(*it) << '\n'; +} + +static inline int count(const ResultThreader::Hash &list, const TestResult::Status stat) +{ + const ResultThreader::Hash::const_iterator end(list.constEnd()); + ResultThreader::Hash::const_iterator it(list.constBegin()); + int result = 0; + + for(; it != end; ++it) + { + if(it.value() == stat) + ++result; + } + + return result; +} + +void Worker::threadFinished() +{ + ++m_finishedCount; + Q_ASSERT(m_finishedCount == 1 || m_finishedCount == 2); + + const ResultThreader *const handler = static_cast(sender()); + Q_ASSERT(handler); + + switch(handler->type()) + { + case ResultThreader::Baseline: + { + m_baseline = handler->result(); + break; + } + case ResultThreader::Result: + m_result = handler->result(); + } + + if(m_finishedCount == 1) /* One thread's missing. */ + return; + + /* Ok, both threads have now finished, and we got their results in m_result and m_baseline. */ + + /* No matter how this function exits, we want to delete this Worker. */ + deleteLater(); + + ResultThreader::Hash::const_iterator itA(m_result.constBegin()); + ResultThreader::Hash::const_iterator itB(m_baseline.constBegin()); + const ResultThreader::Hash::const_iterator endA(m_result.constEnd()); + const ResultThreader::Hash::const_iterator endB(m_baseline.constEnd()); + const int baselineCount = m_baseline.count(); + const int resultCount = m_result.count(); + + /* If you want useful output, change the QTextStream to use stderr. */ + //QTextStream err(stderr); + QByteArray out; + QTextStream err(&out); + + if(resultCount < baselineCount) + { + err << qPrintable(QString(QLatin1String("WARNING: Test result contains %1 reports, " + "but the baseline contains %2, a DECREASE " + "of %3 tests.\n")) + .arg(resultCount) + .arg(baselineCount) + .arg(resultCount - baselineCount)); + } + else if(resultCount > baselineCount) + { + err << qPrintable(QString(QLatin1String("NOTE: The number of tests run is more than what " + "the baseline specifies. Run was %1 test cases, the " + "baseline specifies %2; an increase of %3 tests.\n")) + .arg(resultCount) + .arg(baselineCount) + .arg(resultCount - baselineCount)); + } + + for(; itA != endA; ++itA) + { + const TestResult::Status result = itA.value(); + const TestResult::Status baseline = m_baseline.value(itA.key()); + + if(result == baseline) /* We have no change. */ + { + if(result == TestResult::NotTested) + m_notTested.append(itA.key()); + else + continue; + } + else if(baseline == TestResult::Pass && result == TestResult::Fail) + m_unexpectedFailures.append(itA.key()); + else if(baseline == TestResult::Fail && result == TestResult::Pass) + m_unexpectedPasses.append(itA.key()); + } + + list(err, QLatin1String("Not tested"), m_notTested); + list(err, QLatin1String("Unexpected failures"), m_unexpectedFailures); + list(err, QLatin1String("Unexpected passes"), m_unexpectedPasses); + + err << "SUMMARY:\n"; + typedef QPair Info; + typedef QList InfoList; + InfoList info; + + const int totFail = count(m_result, TestResult::Fail); + const int totPass = count(m_result, TestResult::Pass); + const int total = resultCount; + const int notTested = m_notTested.count(); + const int percentage = int((static_cast(totPass) / total) * 100); + + Q_ASSERT_X(percentage >= 0 && percentage <= 100, Q_FUNC_INFO, + qPrintable(QString(QLatin1String("Percentage was: %1")).arg(percentage))); + + info.append(Info(QLatin1String("Total"), total)); + info.append(Info(QLatin1String("Failures"), totFail)); + info.append(Info(QLatin1String("Passes"), totPass)); + info.append(Info(QLatin1String("Not tested"), notTested)); + info.append(Info(QLatin1String("Pass percentage(%)"), percentage)); + info.append(Info(QLatin1String("Unexpected failures"), m_unexpectedFailures.count())); + info.append(Info(QLatin1String("Unexpected passes"), m_unexpectedPasses.count())); + + const InfoList::const_iterator end(info.constEnd()); + InfoList::const_iterator it(info.constBegin()); + + /* List the statistics nicely in a row with padded columns. */ + for(; it != end; ++it) + { + const QString result((((*it).first) + QLatin1Char(':')).leftJustified(22, QLatin1Char(' '))); + err << m_indent << qPrintable(result) << (*it).second << '\n'; + } + + if(!m_unexpectedFailures.isEmpty()) + { + err << "FAILURE: Regressions discovered, baseline was not updated.\n"; + err.flush(); + QTextStream(stderr) << out; + m_eventLoop.exit(ExitCode::Regression); + return; + } + else if(m_unexpectedPasses.isEmpty() && baselineCount == resultCount) + { + err << "Result was identical to the baseline, baseline was not updated.\n"; + m_eventLoop.exit(ExitCode::Success); + return; + } + + /* Ok, we got unexpected successes and no regressions: let's update the baseline. */ + + QFile resultFile(m_resultFile.absoluteFilePath()); + + /* Remove the old file, otherwise QFile::copy() will fail. */ + QDir baselineDir(m_baselineFile.absolutePath()); + baselineDir.remove(m_baselineFile.fileName()); + + if(resultFile.copy(m_baselineFile.absoluteFilePath())) + { + /* Give a detailed message of what's going on. */ + if(resultCount > baselineCount) + err << "More tests was run than specified in the baseline, updating the baseline.\n"; + else + err << "Improvement, the baseline was updated.\n"; + + /* We actually flag this as an error, because the new baseline must be submitted. */ + err.flush(); + QTextStream(stderr) << out; + m_eventLoop.exit(ExitCode::Regression); + return; + } + else + { + err << qPrintable(QString(QLatin1String("Encountered error when updating " + "the baseline: %1\n")) + .arg(resultFile.errorString())); + err.flush(); + QTextStream(stderr) << out; + m_eventLoop.exit(ExitCode::WriteError); + return; + } +} + +// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternssdk/Worker.h b/tests/auto/xmlpatternssdk/Worker.h new file mode 100644 index 0000000..b3d7ae2 --- /dev/null +++ b/tests/auto/xmlpatternssdk/Worker.h @@ -0,0 +1,100 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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$ +** +****************************************************************************/ + +#ifndef PatternistSDK_Worker_H +#define PatternistSDK_Worker_H + +#include +#include +#include +#include + +#include "ResultThreader.h" + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +class QEventLoop; + +namespace QPatternistSDK +{ + /** + * @short Gets notified when the ResultThreader threads are + * finished, and output summaries and adjusts a baseline. + * + * @author Frans Englich + * @ingroup PatternistSDK + */ + class Q_PATTERNISTSDK_EXPORT Worker : public QObject + { + Q_OBJECT + public: + Worker(QEventLoop &e, + const QFileInfo &baseline, + const QFileInfo &result); + + public Q_SLOTS: + void threadFinished(); + + private: + static inline void list(QTextStream &out, const QString &msg, QStringList &list); + + qint8 m_finishedCount; + const QFileInfo m_baselineFile; + const QFileInfo m_resultFile; + ResultThreader::Hash m_result; + ResultThreader::Hash m_baseline; + ResultThreader::Hash m_summary; + QStringList m_unexpectedPasses; + QStringList m_unexpectedFailures; + QStringList m_notTested; + QEventLoop & m_eventLoop; + static const char *const m_indent; + }; +} + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif +// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternssdk/XMLWriter.cpp b/tests/auto/xmlpatternssdk/XMLWriter.cpp new file mode 100644 index 0000000..60a5344 --- /dev/null +++ b/tests/auto/xmlpatternssdk/XMLWriter.cpp @@ -0,0 +1,669 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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 +#include +#include +#include +#include + +#include "XMLWriter.h" + +/* Issues: + * - Switch to Qt's d-pointer semantics, if in Qt. + * - Remove namespace(PatternistSDK), and change name, if in Qt. + * - Is it really necessary to pass the tag name to endElement()? + * - Could it be of interest to let the user control the encoding? Are those cases common + * enough to justify support in Qt? Using anything but UTF-8 or UTF-16 + * means asking for trouble, from an interoperability perspective. + */ + +/* Design rationalis, comments: + * + * - The class is called XMLWriter to harvest familarity by being consistent with + * Java's XMLWriter class. If XMLWriter is moved to Qt, the name QXmlWriter is perhaps suitable. + * - The class does not handle indentation because the "do one thing well"-principle is + * in use. XMLWriter should be fast and not assume a certain idea of indentation. Indentation + * should be implemented in a standalone QXmlContentHandler that performs the indentation and + * "has a" QXmlContentHandler which it in addition calls, and by that proxying/piping another + * QXmlContentHandler(which most likely is an XMLWriter). Thus, achieving a modularized, + * flexibly approach to indentation. A reason is also that indentation is very subjective. + * The indenter class should probably be called XMLIndenter/QXmlIndenter. + * - It could be of interest to implement QXmlDTDHandler such that it would be possible to serialize + * DTDs. Must be done before BC becomes significant. + * - I think the most valuable of this class is its Q_ASSERT tests. Many programmers have severe problems + * producing XML, and the tests helps them catching their mistakes. They therefore promote + * interoperability. Do not remove them. If any are wrong, fix them instead. + */ + +using namespace QPatternistSDK; + +/** + * A namespace binding, prefix/namespace URI. + */ +typedef QPair NSBinding; +typedef QList NSBindingList; + +#ifdef QT_NO_DEBUG +# define DEBUG_CODE(code) +#else +# define DEBUG_CODE(code) code +#endif + +class XMLWriter::Private +{ +public: + inline Private(QIODevice *devP) : insideCDATA(false), + addModificationNote(false), + dev(devP) + { + hasContentStack.push(true); + } + +#ifdef QT_NO_DEBUG + inline void validateQName(const QString &) const + { + } + + inline void verifyNS(const QString &) const + { + } +#else + /** + * Simple test of that @p name is an acceptable QName. + */ + inline void validateQName(const QString &name) + { + Q_ASSERT_X(!name.isEmpty(), Q_FUNC_INFO, + "An XML name cannot be empty."); + Q_ASSERT_X(!name.endsWith(QLatin1Char(':')), Q_FUNC_INFO, + "An XML name cannot end with a colon(QLatin1Char(':'))."); + Q_ASSERT_X(!name.contains(QRegExp(QLatin1String("[ \t\n]"))), Q_FUNC_INFO, + "An XML name cannot contain whitespace."); + } + + /** + * Ensures that the prefix of @p qName is declared. + */ + inline void verifyNS(const QString &qName) const + { + const QString prefix(qName.left(qName.indexOf(QLatin1Char(':')))); + + if(qName.contains(QLatin1Char(':')) && prefix != QLatin1String("xml")) + { + bool foundPrefix = false; + const QStack::const_iterator end(namespaceTracker.constEnd()); + QStack::const_iterator it(namespaceTracker.constBegin()); + + for(; it != end; ++it) + { + const NSBindingList::const_iterator lend((*it).constEnd()); + NSBindingList::const_iterator lit((*it).constBegin()); + + for(; lit != lend; ++it) + { + if((*lit).first == prefix) + { + foundPrefix = true; + break; + } + } + if(foundPrefix) + break; + } + + Q_ASSERT_X(foundPrefix, "XMLWriter::startElement()", + qPrintable(QString::fromLatin1("The prefix %1 is not declared. All prefixes " + "except 'xml' must be declared.").arg(prefix))); + } + } +#endif + + inline QString escapeElementContent(const QString &ch) + { + const int l = ch.length(); + QString retval; + + for(int i = 0; i != l; ++i) + { + const QChar c(ch.at(i)); + + if(c == QLatin1Char(QLatin1Char('&'))) + retval += QLatin1String("&"); + else if(c == QLatin1Char(QLatin1Char('<'))) + retval += QLatin1String("<"); + else + retval += c; + } + + return retval; + } + + inline QString escapeAttributeContent(const QString &ch) + { + const int l = ch.length(); + QString retval; + + for(int i = 0; i != l; ++i) + { + const QChar c(ch.at(i)); + + /* We don't have to escape '\'' because we use '\"' as attribute delimiter. */ + if(c == QLatin1Char('&')) + retval += QLatin1String("&"); + else if(c == QLatin1Char('<')) + retval += QLatin1String("<"); + else if(c == QLatin1Char('"')) + retval += QLatin1String("""); + else + retval += c; + } + + return retval; + } + + inline QString escapeCDATAContent(const QString &ch) + { + const int l = ch.length(); + QString retval; + qint8 atEnd = 0; + + for(int i = 0; i != l; ++i) + { + const QChar c(ch.at(i)); + + /* Escape '>' if in "]]>" */ + if(c == QLatin1Char(']')) + { + if(atEnd == 0 || atEnd == 1) + ++atEnd; + else + atEnd = 0; + + retval += QLatin1Char(']'); + } + else if(c == QLatin1Char('>')) + { + if(atEnd == 2) + retval += QLatin1String(">"); + else + { + atEnd = 0; + retval += QLatin1Char('>'); + } + } + else + retval += c; + } + + return retval; + } + + /** + * We wrap dev in this function such that we can deploy the Q_ASSERT_X + * macro in each place it's used. + */ + inline QIODevice *device() const + { + Q_ASSERT_X(dev, Q_FUNC_INFO, + "No device specified for XMLWriter; one must be specified with " + "setDevice() or via the constructor before XMLWriter can be used."); + return dev; + } + + /** + * @returns true on success, otherwise false + */ + inline bool serialize(const QString &data) + { + const QByteArray utf8(data.toUtf8()); + + return device()->write(utf8) == utf8.size(); + } + + /** + * @returns true on success, otherwise false + */ + inline bool serialize(const char data) + { + return device()->putChar(data); + } + + /** + * @returns true on success, otherwise false + */ + inline bool serialize(const char *data) + { + return device()->write(data) == qstrlen(data); + } + + inline bool hasElementContent() const + { + return hasContentStack.top(); + } + + inline void handleElement() + { + if(!hasElementContent()) + serialize('>'); + + /* This element is content for the parent. */ + hasContentStack.top() = true; + } + + NSBindingList namespaces; + bool insideCDATA; + bool addModificationNote; + QString msg; + QIODevice *dev; + QStack hasContentStack; + QString errorString; + DEBUG_CODE(QStack tags;) + DEBUG_CODE(QStack namespaceTracker;) +}; + +/** + * Reduces complexity. The empty else clause is for avoiding mess when macro + * is used in the 'then' branch of an if clause, which is followed by an else clause. + */ +#define serialize(string) if(!d->serialize(string)) \ + { \ + d->errorString = d->device()->errorString(); \ + return false; \ + } \ + else do {} while (false) + +XMLWriter::XMLWriter(QIODevice *outStream) : d(new Private(outStream)) +{ +} + +XMLWriter::~XMLWriter() +{ + delete d; +} + +bool XMLWriter::startDocument() +{ + if(!device()->isOpen() && !device()->open(QIODevice::WriteOnly)) + return false; + + if(d->addModificationNote) + { + if(d->msg.isNull()) + { + d->msg = QString::fromLatin1("NOTE: This file was automatically generated " + "by %1 at %2. All changes to this file will be lost.") + .arg(QCoreApplication::instance()->applicationName(), + QDateTime::currentDateTime().toString()); + } + if(!comment(d->msg)) + return false; + + serialize('\n'); + } + + serialize(QLatin1String("\n")); + + return true; +} + +bool XMLWriter::startElement(const QString &/*namespaceURI*/, + const QString &/*localName*/, + const QString &qName, + const QXmlAttributes &atts) +{ + return startElement(qName, atts); +} + +bool XMLWriter::startElement(const QString &qName, + const QXmlAttributes &atts) +{ + Q_ASSERT_X(!d->insideCDATA, Q_FUNC_INFO, + "Only characters() can be received when inside CDATA."); + Q_ASSERT_X(!qName.startsWith(QLatin1String("xmlns")), Q_FUNC_INFO, + "startElement should not be used for declaring prefixes, " + "use startPrefixMapping() for that."); + + d->validateQName(qName); + d->verifyNS(qName); + + d->handleElement(); + + serialize('<'); + serialize(qName); + + DEBUG_CODE(d->tags.push(qName)); + DEBUG_CODE(d->namespaceTracker.push(d->namespaces)); + + /* Add namespace declarations. */ + const NSBindingList::const_iterator end(d->namespaces.constEnd()); + NSBindingList::const_iterator it(d->namespaces.constBegin()); + + for(; it != end; ++it) + { + if((*it).first.isEmpty()) + serialize(" xmlns="); + else + { + serialize(" xmlns:"); + serialize((*it).first); + serialize('='); + } + + serialize('"'); + serialize(d->escapeElementContent((*it).second)); + serialize('"'); + } + d->namespaces.clear(); + + const int c = atts.count(); + + /* Serialize attributes. */ + for(int i = 0; i != c; ++i) + { + d->validateQName(atts.qName(i)); + d->verifyNS(atts.qName(i)); + + serialize(' '); + serialize(atts.qName(i)); + serialize("=\""); + serialize(d->escapeAttributeContent(atts.value(i))); + serialize('"'); + } + + d->hasContentStack.push(false); + return true; +} + +bool XMLWriter::endElement(const QString &/*namespaceURI*/, + const QString &/*localName*/, + const QString &qName) +{ + return endElement(qName); +} + +bool XMLWriter::endElement(const QString &qName) +{ + Q_ASSERT_X(!d->insideCDATA, Q_FUNC_INFO, + "Only characters() can be received when inside CDATA."); + Q_ASSERT_X(d->tags.pop() == qName, Q_FUNC_INFO, + "The element tags are not balanced, the produced XML is invalid."); + + DEBUG_CODE(d->namespaceTracker.pop()); + + /* "this" element is content for our parent, so ensure hasElementContent is true. */ + + if(d->hasElementContent()) + { + serialize(QLatin1String("'); + } + else + serialize(QLatin1String("/>")); + + d->hasContentStack.pop(); + + return true; +} + +bool XMLWriter::startPrefixMapping(const QString &prefix, const QString &uri) +{ + Q_ASSERT_X(!d->insideCDATA, Q_FUNC_INFO, + "Only characters() can be received when inside CDATA."); + Q_ASSERT_X(prefix.toLower() != QLatin1String("xml") || + (prefix.toLower() == QLatin1String("xml") && + (uri == QLatin1String("http://www.w3.org/TR/REC-xml-names/") || + uri.isEmpty())), + Q_FUNC_INFO, + "The prefix 'xml' can only be bound to the namespace " + "\"http://www.w3.org/TR/REC-xml-names/\"."); + Q_ASSERT_X(prefix.toLower() != QLatin1String("xml") && + uri != QLatin1String("http://www.w3.org/TR/REC-xml-names/"), + Q_FUNC_INFO, + "The namespace \"http://www.w3.org/TR/REC-xml-names/\" can only be bound to the " + "\"xml\" prefix."); + + d->namespaces.append(qMakePair(prefix, uri)); + return true; +} + +bool XMLWriter::processingInstruction(const QString &target, + const QString &data) +{ + Q_ASSERT_X(target.toLower() != QLatin1String("xml"), Q_FUNC_INFO, + "A processing instruction cannot have the name xml in any " + "capitalization, because it is reserved."); + Q_ASSERT_X(!data.contains(QLatin1String("?>")), Q_FUNC_INFO, + "The content of a processing instruction cannot contain the string \"?>\"."); + Q_ASSERT_X(!d->insideCDATA, "XMLWriter::processingInstruction()", + "Only characters() can be received when inside CDATA."); + + d->handleElement(); + + serialize(QLatin1String("")); + return true; +} + +bool XMLWriter::characters(const QString &ch) +{ + Q_ASSERT_X(d->tags.count() >= 1, Q_FUNC_INFO, + "Text nodes can only appear inside elements(no elements sent)."); + d->handleElement(); + + if(d->insideCDATA) + serialize(d->escapeCDATAContent(ch)); + else + serialize(d->escapeElementContent(ch)); + + return true; +} + +bool XMLWriter::comment(const QString &ch) +{ + Q_ASSERT_X(!d->insideCDATA, Q_FUNC_INFO, + "Only characters() can be received when inside CDATA."); + Q_ASSERT_X(!ch.contains(QLatin1String("--")), Q_FUNC_INFO, + "XML comments may not contain double-hyphens(\"--\")."); + Q_ASSERT_X(!ch.endsWith(QLatin1Char('-')), Q_FUNC_INFO, + "XML comments cannot end with a hyphen, \"-\"(add a space, for example)."); + /* A comment starting with "")); + + return true; +} + +bool XMLWriter::startCDATA() +{ + Q_ASSERT_X(d->insideCDATA, Q_FUNC_INFO, + "startCDATA() has already been called."); + Q_ASSERT_X(d->tags.count() >= 1, Q_FUNC_INFO, + "CDATA sections can only appear inside elements(no elements sent)."); + d->insideCDATA = true; + serialize(QLatin1String("insideCDATA = false; + serialize("]]>"); + return true; +} + +bool XMLWriter::startDTD(const QString &name, + const QString &publicId, + const QString &systemId) +{ + Q_ASSERT_X(!d->insideCDATA, Q_FUNC_INFO, + "Only characters() can be received when inside CDATA."); + Q_ASSERT_X(!name.isEmpty(), Q_FUNC_INFO, + "The DOCTYPE name cannot be empty."); + Q_ASSERT_X(d->tags.isEmpty() && d->namespaces.isEmpty(), Q_FUNC_INFO, + "No content such as namespace declarations or elements can be serialized " + "before the DOCTYPE declaration, the XML is invalid."); + Q_ASSERT_X(!publicId.contains(QLatin1Char('"')), Q_FUNC_INFO, + "The PUBLIC ID cannot contain quotes('\"')."); + Q_ASSERT_X(!systemId.contains(QLatin1Char('"')), Q_FUNC_INFO, + "The SYSTEM ID cannot contain quotes('\"')."); + + serialize(QLatin1String("tags.isEmpty() && d->namespaces.isEmpty(), Q_FUNC_INFO, + "Content such as namespace declarations or elements cannot occur inside " + "the DOCTYPE declaration, the XML is invalid."); + serialize(QLatin1String(">\n")); + return true; +} + +bool XMLWriter::startEntity(const QString &) +{ + return true; +} + +bool XMLWriter::endEntity(const QString &) +{ + return true; +} + +void XMLWriter::setMessage(const QString &msg) +{ + d->msg = msg; +} + +QString XMLWriter::modificationMessage() const +{ + return d->msg; +} + +bool XMLWriter::endDocument() +{ + Q_ASSERT_X(d->tags.isEmpty(), Q_FUNC_INFO, + "endDocument() called before all elements were closed with endElement()."); + d->device()->close(); + return true; +} + +QString XMLWriter::errorString() const +{ + return d->errorString; +} + +bool XMLWriter::ignorableWhitespace(const QString &ch) +{ + return characters(ch); +} + +bool XMLWriter::endPrefixMapping(const QString &) +{ + /* Again, should we do something with this? */ + return true; +} + +bool XMLWriter::skippedEntity(const QString &) +{ + return true; +} + +void XMLWriter::setDocumentLocator(QXmlLocator *) +{ +} + +QIODevice *XMLWriter::device() const +{ + return d->dev; +} + +void XMLWriter::setDevice(QIODevice *dev) +{ + d->dev = dev; +} + +void XMLWriter::setAddMessage(const bool toggle) +{ + d->addModificationNote = toggle; +} + +bool XMLWriter::addModificationMessage() const +{ + return d->addModificationNote; +} + +#undef serialize +// vim: et:ts=4:sw=4:sts=4 + diff --git a/tests/auto/xmlpatternssdk/XMLWriter.h b/tests/auto/xmlpatternssdk/XMLWriter.h new file mode 100644 index 0000000..2b629bb --- /dev/null +++ b/tests/auto/xmlpatternssdk/XMLWriter.h @@ -0,0 +1,403 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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$ +** +****************************************************************************/ + +#ifndef PatternistSDK_XMLWriter_H +#define PatternistSDK_XMLWriter_H + +#include "Global.h" + +#include +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +class QIODevice; + +namespace QPatternistSDK +{ + /** + * @short Serializes a stream of SAX events into XML, sent to a QIODevice. + * + * XMLWriter is a fast and simple XML serializer which takes care of + * all the low level details of well-formedness and character escaping, allowing + * the user to focus on higher level issues and increasing the chances of producing + * valid, interoperable XML. + * + * The content XMLWriter produces is sent to a QIODevice, which is either + * specified in XMLWriter's constructor or via setDevice(). If writing to + * the device fails, the content functions such as startElement() returns @c false. + * + * XMLWriter sub-classes QXmlContentHandler meaning it can serialize content + * from any code that produces SAX events. The class can also be used manually, + * by calling startElement(), endCDATA(), and so forth. + * + * XMLWriter cannot be used to serialize multiple documents. One instance per + * document must be used. + * + * XMLWriter takes care of escaping content into character references as necessary. Thus, + * it should not be done manually. In fact, it would most likely + * result in invalid XML or an unintended result. XMLWriter always serializes into UTF-8. + * + * When compiled in debug mode, XMLWriter contains several tests that helps + * ensuring that XMLWriter produces valid XML. Some of these tests ensures that: + * + * - The @c xmlns and @c xml prefixes are used properly + * - Content of comments and processing instructions is valid + * - Element, attribute and DOCTYPE names are sensible + * - Elements are properly nested and balanced + * - To some extent that things occur in the proper order. For example, that + * the document type definition isn't added inside an element + * - That namespaces prefixes are declared + * + * Not triggering XMLWriter's tests does not guarantee valid XML is produced, + * but they do help catching common mistakes and some of the corner cases in the + * specifications. When XMLWriter is compiled in release mode, these tests are not enabled + * and the error handling in effect is concerning writing to the QIODevice. + * + * Often it is of interest to add a note at the beginning of the file communicating + * it is auto-generated. setMessage() and setAddMessage() provides + * a convenient way of doing that. + * + * Namespace declarations are added with startPrefixMapping(), not by sending attributes + * with name xmlns:* to startElement(). + * + * @see HOWTO Avoid Being + * Called a Bozo When Producing XML + * @see Extensible Markup + * Language (XML) 1.0 (Third Edition) + * @see Namespaces in XML + * @todo Replace this class with QXmlStreamWriter + * @author Frans Englich + * @ingroup PatternistSDK + */ + class Q_PATTERNISTSDK_EXPORT XMLWriter : public QXmlContentHandler + , public QXmlLexicalHandler + { + public: + /** + * Creates a XMLWriter which serializes its received events + * to @p outStream. + * + * @note XMLWriter does not claim ownership of @p outStream. Thus, + * @p outStream may not be destroyed as long as + * this XMLWriter instance uses it. + */ + XMLWriter(QIODevice *outStream = 0); + + virtual ~XMLWriter(); + + /** + * @returns @c true if opening the output device succeeds, otherwise @c false + */ + virtual bool startDocument(); + + /** + * @returns @c false if failure occurs in writing to the QIODevice, otherwise + * @c true + */ + virtual bool characters(const QString &ch); + + /** + * Starts an element with name @p qName and attributes @p atts. The prefix + * in @p qName must first be declared with startPrefixMapping(), if it has one. + * + * A call to startElement() must always at some point be balanced with a call + * to endElement(). + * + * To declare namespaces, don't put attributes with name xmlns:* in @p atts, + * but use startPrefixMapping(). + */ + virtual bool startElement(const QString &qName, const QXmlAttributes &atts = QXmlAttributes()); + + /** + * + * Behaves essentially as startElement(const QString &qName, const QXmlAttributes &atts). This + * function is used in conjunction with other SAX classes. + * + * The call: + * + * @code + * startElement(QString(), QString(), qName, atts); + * @endcode + * + * is equivalent to: + * + * @code + * startElement(qName, atts); + * @endcode + * + * @p namespaceURI and @p localName are not used. This function is + * used in conjunction with other SAX classes. + * + * @returns @c false if failure occurs in writing to the QIODevice, otherwise + * @c true + */ + virtual bool startElement(const QString &namespaceURI, + const QString &localName, + const QString &qName, + const QXmlAttributes &atts); + + /** + * Signals the end of an element with name @p qName. @p qName must + * be supplied. + * + * Calls to startElement() and endElement() must always be balanced. + * + * @returns @c false if failure occurs in writing to the QIODevice, otherwise + * @c true + */ + virtual bool endElement(const QString &qName); + + /** + * Behaves essentially as endElement(const QString &qName). This function + * is used when XMLWriter is used in SAX code. + * + * @p namespaceURI and @p localName are not used. + * + * The call: + * + * @code + * endElement(QString(), QString(), qName); + * @endcode + * + * is equivalent to: + * + * @code + * endElement(qName); + * @endcode + * + * @returns @c false if failure occurs in writing to the QIODevice, otherwise + * @c true + */ + virtual bool endElement(const QString &namespaceURI, + const QString &localName, + const QString &qName); + + /** + * A description of an error if it occurred. This is typically + * QIODevice::errorString(). If no error has occurred, an empty + * string is returned. + */ + virtual QString errorString() const; + + /** + * Starts a CDATA section. Content sent with characters() will not be escaped + * except for ">" if occurring in "]]>". + * + * @returns @c false if failure occurs in writing to the QIODevice, otherwise + * @c true + */ + virtual bool startCDATA(); + + /** + * @returns @c false if failure occurs in writing to the QIODevice, otherwise + * @c true + */ + virtual bool endCDATA(); + + /** + * Creates a document type definition. + * + * For example, the code snippet: + * + * @code + * writer.startDTD("html", "-//W3C//DTD XHTML 1.0 Strict//EN", + * "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"); + * writer.endDTD(); + * @endcode + * + * would create: + * @verbatim + +@endverbatim + * + * @note A system identifier must always be specified, but a public identifier may + * be left out. + * + * A call to startDTD() must be followed by a call to endDTD(). + */ + virtual bool startDTD(const QString &name, + const QString &publicId, + const QString &systemId); + + /** + * Apart from closing the DTD, an new line is also added at end. + */ + virtual bool endDTD(); + + /** + * Creates a processing instruction by name @p target, and content + * @p data. + * + * @returns @c false if failure occurs in writing to the QIODevice, otherwise + * @c true + */ + virtual bool processingInstruction(const QString &target, + const QString &data); + + /** + * Declares a namespace which maps @p prefix to @p namespaceURI. For example, the call: + * + * @code + * startPrefixMapping("xhtml", "http://www.w3.org/1999/xhtml"); + * @endcode + * + * would result in: + * + * @code + * xmlns="http://www.w3.org/1999/xhtml" + * @endcode + */ + virtual bool startPrefixMapping(const QString &prefix, + const QString &namespaceURI); + + /** + * Creates a comment with content @p ch. @p ch is escaped, there's + * no need to do it manually. For example, calling comment() with @p ch + * set to "my comment", results in "" in the output. + * + * @note if @p ch contains double hyphen("--"), the produced XML will + * not be well formed. + * + * @returns @c false if failure occurs in writing to the QIODevice, otherwise + * @c true + */ + virtual bool comment(const QString &ch); + + virtual bool startEntity(const QString &name); + virtual bool endEntity(const QString &name); + + /** + * Sets the message which is added as a comment if addModificationMessage() + * is set to @c true. If no message is specified and addModificationMessage() + * is set to @c true, a default message is used. + * + * @see modificationMessage(), setAddMessage() + */ + virtual void setMessage(const QString &msg); + + /** + * The message that is added at the beginning of the XML events + * in a comment node. If no modificationMessage is set via modificationMessage(), + * and addModificationMessage is set to @c true, this message will be used: + * "NOTE: This file was automatically generated by [the application name] at + * [the current date time]. All changes to this file will be lost." + * + * @see setMessage() + */ + virtual QString modificationMessage() const; + + /** + * Closes the QIODevice XMLWriter writes to. + */ + virtual bool endDocument(); + + /** + * Serializes @p ch as if it was sent to characters(). + * + * @returns @c false if failure occurs in writing to the QIODevice, otherwise + * @c true + */ + virtual bool ignorableWhitespace(const QString &ch); + + /** + * This function is not used by XMLWriter, but is implemented + * in order to satisfy QXmlContentHandler's interface. + */ + virtual bool endPrefixMapping(const QString &prefix); + + /** + * This function is not used by XMLWriter, but is implemented + * in order to satisfy QXmlContentHandler's interface. + */ + virtual bool skippedEntity(const QString &name); + + /** + * This function is not used by XMLWriter, but is implemented + * in order to satisfy QXmlContentHandler's interface. + */ + virtual void setDocumentLocator(QXmlLocator *); + + /** + * @returns the device XMLWriter writes its output to. + * XMLWriter does not own the device. + */ + virtual QIODevice *device() const; + + /** + * Sets the QIODevice XMLWriter writes to, to @p device. A device must be specified + * either via this function or in the constructor before XMLWriter is used. + * + * XMLWriter does not claim ownership of @p device. + */ + virtual void setDevice(QIODevice *device); + + /** + * Determines whether the modification message should be inserted as a comment + * before the document element. The message returned by modificationMessage() is used. + * + * If @p toggle is @c true, the message will be added, otherwise not. + */ + virtual void setAddMessage(const bool toggle); + + /** + * Tells whether a modification message will be added. + * + * @see setAddMessage(), modificationMessage() + */ + virtual bool addModificationMessage() const; + + private: + Q_DISABLE_COPY(XMLWriter) + + class Private; + Private *d; + }; +} + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif +// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternssdk/XQTSTestCase.cpp b/tests/auto/xmlpatternssdk/XQTSTestCase.cpp new file mode 100644 index 0000000..6a8645b --- /dev/null +++ b/tests/auto/xmlpatternssdk/XQTSTestCase.cpp @@ -0,0 +1,286 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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 +#include +#include + +#include "XQTSTestCase.h" + +using namespace QPatternistSDK; +using namespace QPatternist; + +XQTSTestCase::XQTSTestCase(const Scenario scen, + TreeItem *p, + const QXmlQuery::QueryLanguage lang) : m_isXPath(false) + , m_scenario(scen) + , m_parent(p) + , m_lang(lang) +{ +} + +XQTSTestCase::~XQTSTestCase() +{ + qDeleteAll(m_baseLines); +} + +QVariant XQTSTestCase::data(const Qt::ItemDataRole role, int column) const +{ + if(role == Qt::DisplayRole) + { + if(column == 0) + return title(); + + const TestResult *const tr = testResult(); + if(!tr) + { + if(column == 1) + return TestResult::displayName(TestResult::NotTested); + else + return QString(); + } + const TestResult::Status status = tr->status(); + + switch(column) + { + case 1: + return status == TestResult::Pass ? QString(QChar::fromLatin1('1')) + : QString(QChar::fromLatin1('0')); + case 2: + return status == TestResult::Fail ? QString(QChar::fromLatin1('1')) + : QString(QChar::fromLatin1('0')); + default: + return QString(); + } + } + + if(role != Qt::BackgroundRole) + return QVariant(); + + const TestResult *const tr = testResult(); + + if(!tr) + { + if(column == 0) + return Qt::yellow; + else + return QVariant(); + } + + const TestResult::Status status = tr->status(); + + if(status == TestResult::NotTested || status == TestResult::Unknown) + return Qt::yellow; + + switch(column) + { + case 1: + return status == TestResult::Pass ? Qt::green : QVariant(); + case 2: + return status == TestResult::Fail ? Qt::red : QVariant(); + default: + return QVariant(); + } +} + +QString XQTSTestCase::sourceCode(bool &ok) const +{ + QFile file(m_queryPath.toLocalFile()); + + QString err; + + if(!file.exists()) + err = QString::fromLatin1("Error: %1 does not exist.").arg(file.fileName()); + else if(!QFileInfo(file.fileName()).isFile()) + err = QString::fromLatin1("Error: %1 is not a file, cannot display it.").arg(file.fileName()); + else if(!file.open(QIODevice::ReadOnly)) + err = QString::fromLatin1("Error: Could not open %1. Likely a permission error.") + .arg(file.fileName()); + + if(err.isNull()) /* No errors. */ + { + ok = true; + /* Scary, we assume the query is stored in UTF-8. */ + return QString::fromUtf8(file.readAll()); + } + else + { + ok = false; + return err; + } +} + +int XQTSTestCase::columnCount() const +{ + return 2; +} + +void XQTSTestCase::addBaseLine(TestBaseLine *line) +{ + m_baseLines.append(line); +} + +QString XQTSTestCase::name() const +{ + return m_name; +} + +QString XQTSTestCase::creator() const +{ + return m_creator; +} + +QString XQTSTestCase::description() const +{ + return m_description; +} + +QDate XQTSTestCase::lastModified() const +{ + return m_lastModified; +} + +bool XQTSTestCase::isXPath() const +{ + return m_isXPath; +} + +TestCase::Scenario XQTSTestCase::scenario() const +{ + return m_scenario; +} + +void XQTSTestCase::setName(const QString &n) +{ + m_name = n; +} + +void XQTSTestCase::setCreator(const QString &ctor) +{ + m_creator = ctor; +} + +void XQTSTestCase::setDescription(const QString &descriptionP) +{ + m_description = descriptionP; +} + +void XQTSTestCase::setLastModified(const QDate &date) +{ + m_lastModified = date; +} + +void XQTSTestCase::setIsXPath(const bool isXPathP) +{ + m_isXPath = isXPathP; +} + +void XQTSTestCase::setQueryPath(const QUrl &uri) +{ + m_queryPath = uri; +} + +TreeItem *XQTSTestCase::parent() const +{ + return m_parent; +} + +QString XQTSTestCase::title() const +{ + return m_name; +} + +TestBaseLine::List XQTSTestCase::baseLines() const +{ + Q_ASSERT_X(!m_baseLines.isEmpty(), Q_FUNC_INFO, + qPrintable(QString::fromLatin1("The test %1 has no base lines, it should have at least one.").arg(name()))); + return m_baseLines; +} + +QUrl XQTSTestCase::testCasePath() const +{ + return m_queryPath; +} + +void XQTSTestCase::setExternalVariableLoader(const QPatternist::ExternalVariableLoader::Ptr &loader) +{ + m_externalVariableLoader = loader; +} + +QPatternist::ExternalVariableLoader::Ptr XQTSTestCase::externalVariableLoader() const +{ + return m_externalVariableLoader; +} + +void XQTSTestCase::setContextItemSource(const QUrl &uri) +{ + m_contextItemSource = uri; +} + +QUrl XQTSTestCase::contextItemSource() const +{ + return m_contextItemSource; +} + +QXmlQuery::QueryLanguage XQTSTestCase::language() const +{ + return m_lang; +} + +void XQTSTestCase::setParent(TreeItem *const p) +{ + m_parent = p; +} + +void XQTSTestCase::setInitialTemplateName(const QXmlName &name) +{ + m_initialTemplateName = name; +} + +QXmlName XQTSTestCase::initialTemplateName() const +{ + return m_initialTemplateName; +} + +// vim: et:ts=4:sw=4:sts=4 + diff --git a/tests/auto/xmlpatternssdk/XQTSTestCase.h b/tests/auto/xmlpatternssdk/XQTSTestCase.h new file mode 100644 index 0000000..8872b32 --- /dev/null +++ b/tests/auto/xmlpatternssdk/XQTSTestCase.h @@ -0,0 +1,149 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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$ +** +****************************************************************************/ + +#ifndef PatternistSDK_XQTSTestCase_H +#define PatternistSDK_XQTSTestCase_H + +#include +#include +#include + +#include "qexternalvariableloader_p.h" + +#include "TestBaseLine.h" +#include "TestCase.h" + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +namespace QPatternistSDK +{ + /** + * @short Represents a test case in a test suite in the XML Query Test Suite. + * + * TestCase is a memory representation of a test case, and maps + * to the @c test-case element in the XQuery Test Suite test + * case catalog. + * + * @ingroup PatternistSDK + * @author Frans Englich + */ + class Q_PATTERNISTSDK_EXPORT XQTSTestCase : public TestCase + { + public: + XQTSTestCase(const Scenario scen, TreeItem *parent, + const QXmlQuery::QueryLanguage lang = QXmlQuery::XQuery10); + virtual ~XQTSTestCase(); + + /** + * The identifier, the name of the test. For example, "Literals034". + * The name of a test case must be unique. + */ + virtual QString name() const; + virtual QString creator() const; + virtual QString description() const; + /** + * @returns the query inside the file, specified by testCasePath(). Loading + * of the file is not cached in order to avoid complications. + * @param ok is set to @c false if loading the query file fails + */ + virtual QString sourceCode(bool &ok) const; + virtual QUrl testCasePath() const; + virtual QDate lastModified() const; + + bool isXPath() const; + + /** + * What kind of test case this is, what kind of scenario it takes part + * of. For example, whether the test case should evaluate normally or fail. + */ + Scenario scenario() const; + + void setCreator(const QString &creator); + void setLastModified(const QDate &date); + void setDescription(const QString &description); + void setIsXPath(const bool isXPath); + void setName(const QString &name); + void setQueryPath(const QUrl &uri); + void setContextItemSource(const QUrl &uri); + void addBaseLine(TestBaseLine *lines); + void setInitialTemplateName(const QXmlName &name); + + virtual TreeItem *parent() const; + + virtual QVariant data(const Qt::ItemDataRole role, int column) const; + + virtual QString title() const; + virtual TestBaseLine::List baseLines() const; + + virtual int columnCount() const; + + void setExternalVariableLoader(const QPatternist::ExternalVariableLoader::Ptr &loader); + virtual QPatternist::ExternalVariableLoader::Ptr externalVariableLoader() const; + virtual QUrl contextItemSource() const; + virtual QXmlQuery::QueryLanguage language() const; + void setParent(TreeItem *const parent); + virtual QXmlName initialTemplateName() const; + + private: + QString m_name; + QString m_creator; + QString m_description; + QUrl m_queryPath; + bool m_isXPath; + QDate m_lastModified; + const Scenario m_scenario; + TreeItem * m_parent; + TestBaseLine::List m_baseLines; + QPatternist::ExternalVariableLoader::Ptr m_externalVariableLoader; + QUrl m_contextItemSource; + QXmlQuery::QueryLanguage m_lang; + QXmlName m_initialTemplateName; + }; +} + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif +// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternssdk/XSDTSTestCase.cpp b/tests/auto/xmlpatternssdk/XSDTSTestCase.cpp new file mode 100644 index 0000000..3cbb681 --- /dev/null +++ b/tests/auto/xmlpatternssdk/XSDTSTestCase.cpp @@ -0,0 +1,375 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the autotests 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 +#include +#include + +#include "XSDTSTestCase.h" + +#include "qxmlschema.h" +#include "qxmlschemavalidator.h" + +using namespace QPatternistSDK; +using namespace QPatternist; + +XSDTSTestCase::XSDTSTestCase(const Scenario scen, TreeItem *p, TestType testType) + : m_scenario(scen) + , m_parent(p) + , m_testType(testType) +{ +} + +XSDTSTestCase::~XSDTSTestCase() +{ + qDeleteAll(m_baseLines); +} + +TestResult::List XSDTSTestCase::execute(const ExecutionStage, TestSuite*) +{ + ErrorHandler errHandler; + ErrorHandler::installQtMessageHandler(&errHandler); + + TestResult::List retval; + TestResult::Status resultStatus = TestResult::Unknown; + QString serialized; + + if (m_testType == SchemaTest) { + executeSchemaTest(resultStatus, serialized, &errHandler); + } else { + executeInstanceTest(resultStatus, serialized, &errHandler); + } + + resultStatus = TestBaseLine::scan(serialized, baseLines()); + Q_ASSERT(resultStatus != TestResult::Unknown); + + m_result = new TestResult(name(), resultStatus, 0, errHandler.messages(), + QPatternist::Item::List(), serialized); + retval.append(m_result); + ErrorHandler::installQtMessageHandler(0); + changed(this); + return retval; +} + +void XSDTSTestCase::executeSchemaTest(TestResult::Status &resultStatus, QString &serialized, QAbstractMessageHandler *handler) +{ + QFile file(m_schemaUri.path()); + if (!file.open(QIODevice::ReadOnly)) { + resultStatus = TestResult::Fail; + serialized = QString(); + return; + } + + QXmlSchema schema; + schema.setMessageHandler(handler); + schema.load(&file, m_schemaUri); + + if (schema.isValid()) { + resultStatus = TestResult::Pass; + serialized = QString::fromLatin1("true"); + } else { + resultStatus = TestResult::Pass; + serialized = QString::fromLatin1("false"); + } +} + +void XSDTSTestCase::executeInstanceTest(TestResult::Status &resultStatus, QString &serialized, QAbstractMessageHandler *handler) +{ + QFile instanceFile(m_instanceUri.path()); + if (!instanceFile.open(QIODevice::ReadOnly)) { + resultStatus = TestResult::Fail; + serialized = QString(); + return; + } + + QXmlSchema schema; + if (m_schemaUri.isValid()) { + QFile file(m_schemaUri.path()); + if (!file.open(QIODevice::ReadOnly)) { + resultStatus = TestResult::Fail; + serialized = QString(); + return; + } + + schema.setMessageHandler(handler); + schema.load(&file, m_schemaUri); + + if (!schema.isValid()) { + resultStatus = TestResult::Pass; + serialized = QString::fromLatin1("false"); + return; + } + } + + QXmlSchemaValidator validator(schema); + validator.setMessageHandler(handler); + + qDebug("check %s", qPrintable(m_instanceUri.path())); + if (validator.validate(&instanceFile, m_instanceUri)) { + resultStatus = TestResult::Pass; + serialized = QString::fromLatin1("true"); + } else { + resultStatus = TestResult::Pass; + serialized = QString::fromLatin1("false"); + } +} + +QVariant XSDTSTestCase::data(const Qt::ItemDataRole role, int column) const +{ + if(role == Qt::DisplayRole) + { + if(column == 0) + return title(); + + const TestResult *const tr = testResult(); + if(!tr) + { + if(column == 1) + return TestResult::displayName(TestResult::NotTested); + else + return QString(); + } + const TestResult::Status status = tr->status(); + + switch(column) + { + case 1: + return status == TestResult::Pass ? QString(QChar::fromLatin1('1')) + : QString(QChar::fromLatin1('0')); + case 2: + return status == TestResult::Fail ? QString(QChar::fromLatin1('1')) + : QString(QChar::fromLatin1('0')); + default: + return QString(); + } + } + + if(role != Qt::BackgroundRole) + return QVariant(); + + const TestResult *const tr = testResult(); + + if(!tr) + { + if(column == 0) + return Qt::yellow; + else + return QVariant(); + } + + const TestResult::Status status = tr->status(); + + if(status == TestResult::NotTested || status == TestResult::Unknown) + return Qt::yellow; + + switch(column) + { + case 1: + return status == TestResult::Pass ? Qt::green : QVariant(); + case 2: + return status == TestResult::Fail ? Qt::red : QVariant(); + default: + return QVariant(); + } +} + +QString XSDTSTestCase::sourceCode(bool &ok) const +{ + QFile file((m_testType == SchemaTest ? m_schemaUri : m_instanceUri).toLocalFile()); + + QString err; + + if(!file.exists()) + err = QString::fromLatin1("Error: %1 does not exist.").arg(file.fileName()); + else if(!QFileInfo(file.fileName()).isFile()) + err = QString::fromLatin1("Error: %1 is not a file, cannot display it.").arg(file.fileName()); + else if(!file.open(QIODevice::ReadOnly)) + err = QString::fromLatin1("Error: Could not open %1. Likely a permission error.") + .arg(file.fileName()); + + if(err.isNull()) /* No errors. */ + { + ok = true; + /* Scary, we assume the query is stored in UTF-8. */ + return QString::fromUtf8(file.readAll()); + } + else + { + ok = false; + return err; + } +} + +int XSDTSTestCase::columnCount() const +{ + return 2; +} + +void XSDTSTestCase::addBaseLine(TestBaseLine *line) +{ + m_baseLines.append(line); +} + +QString XSDTSTestCase::name() const +{ + return m_name; +} + +QString XSDTSTestCase::creator() const +{ + return m_creator; +} + +QString XSDTSTestCase::description() const +{ + return m_description; +} + +QDate XSDTSTestCase::lastModified() const +{ + return m_lastModified; +} + +bool XSDTSTestCase::isXPath() const +{ + return false; +} + +TestCase::Scenario XSDTSTestCase::scenario() const +{ + return m_scenario; +} + +void XSDTSTestCase::setName(const QString &n) +{ + m_name = n; +} + +void XSDTSTestCase::setCreator(const QString &ctor) +{ + m_creator = ctor; +} + +void XSDTSTestCase::setDescription(const QString &descriptionP) +{ + m_description = descriptionP; +} + +void XSDTSTestCase::setLastModified(const QDate &date) +{ + m_lastModified = date; +} + +void XSDTSTestCase::setSchemaUri(const QUrl &uri) +{ + m_schemaUri = uri; +} + +void XSDTSTestCase::setInstanceUri(const QUrl &uri) +{ + m_instanceUri = uri; +} + +TreeItem *XSDTSTestCase::parent() const +{ + return m_parent; +} + +QString XSDTSTestCase::title() const +{ + return m_name; +} + +TestBaseLine::List XSDTSTestCase::baseLines() const +{ + Q_ASSERT_X(!m_baseLines.isEmpty(), Q_FUNC_INFO, + qPrintable(QString::fromLatin1("The test %1 has no base lines, it should have at least one.").arg(name()))); + return m_baseLines; +} + +QUrl XSDTSTestCase::schemaUri() const +{ + return m_schemaUri; +} + +QUrl XSDTSTestCase::instanceUri() const +{ + return m_instanceUri; +} + +void XSDTSTestCase::setContextItemSource(const QUrl &uri) +{ + m_contextItemSource = uri; +} + +QUrl XSDTSTestCase::contextItemSource() const +{ + return m_contextItemSource; +} + +void XSDTSTestCase::setParent(TreeItem *const p) +{ + m_parent = p; +} + +QPatternist::ExternalVariableLoader::Ptr XSDTSTestCase::externalVariableLoader() const +{ + return QPatternist::ExternalVariableLoader::Ptr(); +} + +TestResult *XSDTSTestCase::testResult() const +{ + return m_result; +} + +TestItem::ResultSummary XSDTSTestCase::resultSummary() const +{ + if(m_result) + return ResultSummary(m_result->status() == TestResult::Pass ? 1 : 0, + 1); + + return ResultSummary(0, 1); +} + +// vim: et:ts=4:sw=4:sts=4 + diff --git a/tests/auto/xmlpatternssdk/XSDTSTestCase.h b/tests/auto/xmlpatternssdk/XSDTSTestCase.h new file mode 100644 index 0000000..947687a --- /dev/null +++ b/tests/auto/xmlpatternssdk/XSDTSTestCase.h @@ -0,0 +1,161 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the autotests 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$ +** +****************************************************************************/ + +#ifndef PatternistSDK_XSDTSTestCase_H +#define PatternistSDK_XSDTSTestCase_H + +#include +#include +#include + +#include "TestBaseLine.h" +#include "TestCase.h" + +QT_BEGIN_HEADER +QT_BEGIN_NAMESPACE + +namespace QPatternistSDK +{ + /** + * @short Represents a test case in a test suite in the XML Query Test Suite. + * + * TestCase is a memory representation of a test case, and maps + * to the @c test-case element in the XQuery Test Suite test + * case catalog. + * + * @ingroup PatternistSDK + * @author Frans Englich + */ + class Q_PATTERNISTSDK_EXPORT XSDTSTestCase : public TestCase + { + public: + enum TestType + { + SchemaTest, + InstanceTest + }; + + XSDTSTestCase(const Scenario scen, TreeItem *parent, TestType testType); + virtual ~XSDTSTestCase(); + + /** + * Executes the test, and returns the result. The returned list + * will always contain exactly one TestResult. + * + * @p stage is ignored when running out-of-process. + */ + virtual TestResult::List execute(const ExecutionStage stage, + TestSuite *ts); + /** + * The identifier, the name of the test. For example, "Literals034". + * The name of a test case must be unique. + */ + virtual QString name() const; + virtual QString creator() const; + virtual QString description() const; + /** + * @returns the query inside the file, specified by testCasePath(). Loading + * of the file is not cached in order to avoid complications. + * @param ok is set to @c false if loading the query file fails + */ + virtual QString sourceCode(bool &ok) const; + virtual QUrl schemaUri() const; + virtual QUrl instanceUri() const; + virtual QUrl testCasePath() const {return QUrl();} + virtual QDate lastModified() const; + + bool isXPath() const; + + /** + * What kind of test case this is, what kind of scenario it takes part + * of. For example, whether the test case should evaluate normally or fail. + */ + Scenario scenario() const; + + void setCreator(const QString &creator); + void setLastModified(const QDate &date); + void setDescription(const QString &description); + void setName(const QString &name); + void setSchemaUri(const QUrl &uri); + void setInstanceUri(const QUrl &uri); + void setTestCasePath(const QUrl & /* uri */) {} + void setContextItemSource(const QUrl &uri); + void addBaseLine(TestBaseLine *lines); + + virtual TreeItem *parent() const; + + virtual QVariant data(const Qt::ItemDataRole role, int column) const; + + virtual QString title() const; + virtual TestBaseLine::List baseLines() const; + + virtual int columnCount() const; + + virtual QUrl contextItemSource() const; + void setParent(TreeItem *const parent); + virtual QPatternist::ExternalVariableLoader::Ptr externalVariableLoader() const; + virtual TestResult *testResult() const; + virtual ResultSummary resultSummary() const; + + private: + void executeSchemaTest(TestResult::Status &resultStatus, QString &serialized, QAbstractMessageHandler *handler); + void executeInstanceTest(TestResult::Status &resultStatus, QString &serialized, QAbstractMessageHandler *handler); + + QString m_name; + QString m_creator; + QString m_description; + QUrl m_schemaUri; + QUrl m_instanceUri; + QDate m_lastModified; + const Scenario m_scenario; + TreeItem * m_parent; + TestBaseLine::List m_baseLines; + QUrl m_contextItemSource; + TestType m_testType; + QPointer m_result; + }; +} + +QT_END_NAMESPACE +QT_END_HEADER + +#endif +// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternssdk/XSDTestSuiteHandler.cpp b/tests/auto/xmlpatternssdk/XSDTestSuiteHandler.cpp new file mode 100644 index 0000000..a868d19 --- /dev/null +++ b/tests/auto/xmlpatternssdk/XSDTestSuiteHandler.cpp @@ -0,0 +1,910 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the autotests 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 "qacceltreeresourceloader_p.h" +#include "qnetworkaccessdelegator_p.h" + +#include "Global.h" +#include "TestBaseLine.h" +#include "TestGroup.h" + +#include "XSDTestSuiteHandler.h" +#include "XSDTSTestCase.h" + +using namespace QPatternistSDK; + +extern QNetworkAccessManager s_networkManager; + +XSDTestSuiteHandler::XSDTestSuiteHandler(const QUrl &catalogFile) : m_ts(0) + , m_catalogFile(catalogFile) + , m_inSchemaTest(false) + , m_inInstanceTest(false) + , m_inTestGroup(false) + , m_inDescription(false) + , m_schemaBlacklisted(false) + , m_counter(0) +{ + Q_ASSERT(!m_catalogFile.isRelative()); + m_ts = new TestSuite(); + m_topLevelGroup = new TestGroup(m_ts); + m_topLevelGroup->setTitle("XML Schema Test Suite"); + m_ts->appendChild(m_topLevelGroup); + + // exclude these test cases, as they break our current state machine + m_blackList << QLatin1String("addB099") + << QLatin1String("addB118") + << QLatin1String("elemJ003") + << QLatin1String("elemJ011") + << QLatin1String("elemZ004") + << QLatin1String("elemZ020") + << QLatin1String("groupH021v") + << QLatin1String("groupJ009v") + << QLatin1String("name00101m2") + << QLatin1String("schL5") + << QLatin1String("ste110") + << QLatin1String("stZ007") + << QLatin1String("stZ047") + << QLatin1String("stZ055") + << QLatin1String("addB049") + << QLatin1String("addB068") + << QLatin1String("addB078") + << QLatin1String("addB078A") + << QLatin1String("addB078B") + << QLatin1String("addB167") + << QLatin1String("addB191") + << QLatin1String("isDefault060_2") + << QLatin1String("isDefault069") + << QLatin1String("annotB025") + << QLatin1String("base64Binary_enumeration003_1321") + << QLatin1String("anyURI_a001_1336") + << QLatin1String("anyURI_a001_1336") + << QLatin1String("anyURI_a003_1338") + << QLatin1String("anyURI_a004_1339") + << QLatin1String("anyURI_b004_1354") + << QLatin1String("anyURI_b004_1354") + << QLatin1String("anyURI_b006_1356") + << QLatin1String("QName_length001_1357") + << QLatin1String("QName_length003_1359") + << QLatin1String("QName_minLength003_1362") + << QLatin1String("QName_maxLength001_1364") + << QLatin1String("NOTATION_length001_1372") + << QLatin1String("NOTATION_length003_1374") + << QLatin1String("NOTATION_minLength003_1377") + << QLatin1String("NOTATION_maxLength001_1379") + << QLatin1String("hexBinary003_2069") + << QLatin1String("QName009_2092") + << QLatin1String("dtZ107447_a_2245") + << QLatin1String("elemE001") + << QLatin1String("elemE002") + << QLatin1String("elemE003") + << QLatin1String("elemE004") + << QLatin1String("elemE005") + << QLatin1String("elemT026") + << QLatin1String("elemT027") + << QLatin1String("elemT028") + << QLatin1String("elemT029") + << QLatin1String("elemT054") + << QLatin1String("elemT055") + << QLatin1String("elemT056") + << QLatin1String("elemT057") + << QLatin1String("elemZ006") + << QLatin1String("elemZ007") + << QLatin1String("elemZ026") + << QLatin1String("elemZ027_c") + << QLatin1String("elemZ028c") + << QLatin1String("elemZ028d") + << QLatin1String("elemZ028f1") + << QLatin1String("elemZ028f1") + << QLatin1String("elemZ028f2") + << QLatin1String("elemZ028f2") + << QLatin1String("elemZ028f3") + << QLatin1String("elemZ028f3") + << QLatin1String("elemZ031") + << QLatin1String("errF001") + << QLatin1String("idC019") + << QLatin1String("idL100") + << QLatin1String("idZ011") + << QLatin1String("idZ015") + << QLatin1String("mgO013") + << QLatin1String("particlesA012") + << QLatin1String("particlesA013") + << QLatin1String("particlesA014") + << QLatin1String("particlesA015") + << QLatin1String("particlesHa161") + << QLatin1String("particlesHb008") + << QLatin1String("particlesHb011") + << QLatin1String("particlesIe003") + << QLatin1String("particlesIg003") + << QLatin1String("particlesIg004") + << QLatin1String("particlesJb003") + << QLatin1String("particlesJd003") + << QLatin1String("particlesJf003") + << QLatin1String("particlesJk003") + << QLatin1String("particlesOb001") + << QLatin1String("particlesOb002") + << QLatin1String("particlesOb004") + << QLatin1String("particlesOb008") + << QLatin1String("particlesOb009") + << QLatin1String("particlesOb013") + << QLatin1String("particlesOb018") + << QLatin1String("particlesQ005") + << QLatin1String("particlesS002") + << QLatin1String("particlesT002") + << QLatin1String("particlesT009") + << QLatin1String("particlesT014") + << QLatin1String("particlesV001") + << QLatin1String("particlesV002") + << QLatin1String("particlesV020") + << QLatin1String("particlesZ001") + << QLatin1String("particlesZ005") + << QLatin1String("particlesZ007") + << QLatin1String("particlesZ023") + << QLatin1String("particlesZ024") + << QLatin1String("particlesZ026") + << QLatin1String("particlesZ028") + << QLatin1String("particlesZ033_c") + << QLatin1String("particlesZ033_d") + << QLatin1String("particlesZ033_e") + << QLatin1String("particlesZ033_f") + << QLatin1String("particlesZ033_g") + << QLatin1String("particlesZ034_a1") + << QLatin1String("particlesZ034_a2") + << QLatin1String("particlesZ034_a3") + << QLatin1String("particlesZ034_b") + << QLatin1String("particlesZ035_a") + << QLatin1String("particlesZ035_b") + << QLatin1String("particlesZ036_a") + << QLatin1String("particlesZ036_b1") + << QLatin1String("particlesZ036_b2") + << QLatin1String("particlesZ036_c") +/* + << QLatin1String("reC65") + << QLatin1String("reC66") + << QLatin1String("reC67") + << QLatin1String("reC68") + << QLatin1String("reF58") + << QLatin1String("reG50") + << QLatin1String("reJ11") + << QLatin1String("reJ13") + << QLatin1String("reJ19") + << QLatin1String("reJ21") + << QLatin1String("reJ23") + << QLatin1String("reJ25") + << QLatin1String("reJ29") + << QLatin1String("reJ31") + << QLatin1String("reJ33") + << QLatin1String("reJ35") + << QLatin1String("reJ61") + << QLatin1String("reJ69") + << QLatin1String("reJ75") + << QLatin1String("reJ77") + << QLatin1String("reL98") + << QLatin1String("reL99") + << QLatin1String("reM98") + << QLatin1String("reN99") + << QLatin1String("reS21") + << QLatin1String("reS42") + << QLatin1String("reT63") + << QLatin1String("reT84") + << QLatin1String("reDG2") + << QLatin1String("RegexTest_9") + << QLatin1String("RegexTest_11") + << QLatin1String("RegexTest_14") + << QLatin1String("RegexTest_15") + << QLatin1String("RegexTest_16") + << QLatin1String("RegexTest_17") + << QLatin1String("RegexTest_23") + << QLatin1String("RegexTest_24") + << QLatin1String("RegexTest_25") + << QLatin1String("RegexTest_26") + << QLatin1String("RegexTest_27") + << QLatin1String("RegexTest_28") + << QLatin1String("RegexTest_30") + << QLatin1String("RegexTest_30") + << QLatin1String("RegexTest_33") + << QLatin1String("RegexTest_34") + << QLatin1String("RegexTest_34") + << QLatin1String("RegexTest_43") + << QLatin1String("RegexTest_44") + << QLatin1String("RegexTest_45") + << QLatin1String("RegexTest_46") + << QLatin1String("RegexTest_47") + << QLatin1String("RegexTest_48") + << QLatin1String("RegexTest_49") + << QLatin1String("RegexTest_50") + << QLatin1String("RegexTest_51") + << QLatin1String("RegexTest_52") + << QLatin1String("RegexTest_53") + << QLatin1String("RegexTest_54") + << QLatin1String("RegexTest_55") + << QLatin1String("RegexTest_56") + << QLatin1String("RegexTest_57") + << QLatin1String("RegexTest_57") + << QLatin1String("RegexTest_58") + << QLatin1String("RegexTest_58") + << QLatin1String("RegexTest_65") + << QLatin1String("RegexTest_113") + << QLatin1String("RegexTest_116") + << QLatin1String("RegexTest_119") + << QLatin1String("RegexTest_120") + << QLatin1String("RegexTest_121") + << QLatin1String("RegexTest_141") + << QLatin1String("RegexTest_142") + << QLatin1String("RegexTest_143") + << QLatin1String("RegexTest_145") + << QLatin1String("RegexTest_146") + << QLatin1String("RegexTest_147") + << QLatin1String("RegexTest_148") + << QLatin1String("RegexTest_149") + << QLatin1String("RegexTest_150") + << QLatin1String("RegexTest_151") + << QLatin1String("RegexTest_152") + << QLatin1String("RegexTest_154") + << QLatin1String("RegexTest_155") + << QLatin1String("RegexTest_156") + << QLatin1String("RegexTest_157") + << QLatin1String("RegexTest_158") + << QLatin1String("RegexTest_163") + << QLatin1String("RegexTest_164") + << QLatin1String("RegexTest_165") + << QLatin1String("RegexTest_166") + << QLatin1String("RegexTest_167") + << QLatin1String("RegexTest_168") + << QLatin1String("RegexTest_169") + << QLatin1String("RegexTest_170") + << QLatin1String("RegexTest_171") + << QLatin1String("RegexTest_172") + << QLatin1String("RegexTest_173") + << QLatin1String("RegexTest_174") + << QLatin1String("RegexTest_178") + << QLatin1String("RegexTest_194") + << QLatin1String("RegexTest_194") + << QLatin1String("RegexTest_195") + << QLatin1String("RegexTest_195") + << QLatin1String("RegexTest_196") + << QLatin1String("RegexTest_196") + << QLatin1String("RegexTest_197") + << QLatin1String("RegexTest_198") + << QLatin1String("RegexTest_199") + << QLatin1String("RegexTest_200") + << QLatin1String("RegexTest_200") + << QLatin1String("RegexTest_201") + << QLatin1String("RegexTest_201") + << QLatin1String("RegexTest_202") + << QLatin1String("RegexTest_202") + << QLatin1String("RegexTest_203") + << QLatin1String("RegexTest_204") + << QLatin1String("RegexTest_205") + << QLatin1String("RegexTest_206") + << QLatin1String("RegexTest_207") + << QLatin1String("RegexTest_208") + << QLatin1String("RegexTest_209") + << QLatin1String("RegexTest_209") + << QLatin1String("RegexTest_210") + << QLatin1String("RegexTest_210") + << QLatin1String("RegexTest_211") + << QLatin1String("RegexTest_211") + << QLatin1String("RegexTest_212") + << QLatin1String("RegexTest_213") + << QLatin1String("RegexTest_214") + << QLatin1String("RegexTest_215") + << QLatin1String("RegexTest_216") + << QLatin1String("RegexTest_217") + << QLatin1String("RegexTest_218") + << QLatin1String("RegexTest_220") + << QLatin1String("RegexTest_221") + << QLatin1String("RegexTest_222") + << QLatin1String("RegexTest_226") + << QLatin1String("RegexTest_230") + << QLatin1String("RegexTest_232") + << QLatin1String("RegexTest_233") + << QLatin1String("RegexTest_294") + << QLatin1String("RegexTest_294") + << QLatin1String("RegexTest_295") + << QLatin1String("RegexTest_295") + << QLatin1String("RegexTest_299") + << QLatin1String("RegexTest_300") + << QLatin1String("RegexTest_301") + << QLatin1String("RegexTest_302") + << QLatin1String("RegexTest_303") + << QLatin1String("RegexTest_304") + << QLatin1String("RegexTest_305") + << QLatin1String("RegexTest_306") + << QLatin1String("RegexTest_307") + << QLatin1String("RegexTest_308") + << QLatin1String("RegexTest_309") + << QLatin1String("RegexTest_310") + << QLatin1String("RegexTest_311") + << QLatin1String("RegexTest_312") + << QLatin1String("RegexTest_313") + << QLatin1String("RegexTest_314") + << QLatin1String("RegexTest_315") + << QLatin1String("RegexTest_315") + << QLatin1String("RegexTest_316") + << QLatin1String("RegexTest_316") + << QLatin1String("RegexTest_317") + << QLatin1String("RegexTest_317") + << QLatin1String("RegexTest_440") + << QLatin1String("RegexTest_441") + << QLatin1String("RegexTest_442") + << QLatin1String("RegexTest_443") + << QLatin1String("RegexTest_448") + << QLatin1String("RegexTest_449") + << QLatin1String("RegexTest_450") + << QLatin1String("RegexTest_451") + << QLatin1String("RegexTest_458") + << QLatin1String("RegexTest_464") + << QLatin1String("RegexTest_464") + << QLatin1String("RegexTest_465") + << QLatin1String("RegexTest_469") + << QLatin1String("RegexTest_470") + << QLatin1String("RegexTest_471") + << QLatin1String("RegexTest_472") + << QLatin1String("RegexTest_473") + << QLatin1String("RegexTest_477") + << QLatin1String("RegexTest_478") + << QLatin1String("RegexTest_478") + << QLatin1String("RegexTest_479") + << QLatin1String("RegexTest_480") + << QLatin1String("RegexTest_481") + << QLatin1String("RegexTest_482") + << QLatin1String("RegexTest_482") + << QLatin1String("RegexTest_483") + << QLatin1String("RegexTest_483") + << QLatin1String("RegexTest_484") + << QLatin1String("RegexTest_487") + << QLatin1String("RegexTest_516") + << QLatin1String("RegexTest_516") + << QLatin1String("RegexTest_517") + << QLatin1String("RegexTest_517") + << QLatin1String("RegexTest_518") + << QLatin1String("RegexTest_518") + << QLatin1String("RegexTest_519") + << QLatin1String("RegexTest_519") + << QLatin1String("RegexTest_521") + << QLatin1String("RegexTest_523") + << QLatin1String("RegexTest_524") + << QLatin1String("RegexTest_524") + << QLatin1String("RegexTest_586") + << QLatin1String("RegexTest_587") + << QLatin1String("RegexTest_592") + << QLatin1String("RegexTest_593") + << QLatin1String("RegexTest_594") + << QLatin1String("RegexTest_595") + << QLatin1String("RegexTest_596") + << QLatin1String("RegexTest_597") + << QLatin1String("RegexTest_598") + << QLatin1String("RegexTest_599") + << QLatin1String("RegexTest_600") + << QLatin1String("RegexTest_601") + << QLatin1String("RegexTest_602") + << QLatin1String("RegexTest_603") + << QLatin1String("RegexTest_604") + << QLatin1String("RegexTest_605") + << QLatin1String("RegexTest_648") + << QLatin1String("RegexTest_655") + << QLatin1String("RegexTest_688") + << QLatin1String("RegexTest_696") + << QLatin1String("RegexTest_697") + << QLatin1String("RegexTest_698") + << QLatin1String("RegexTest_700") + << QLatin1String("RegexTest_701") + << QLatin1String("RegexTest_702") + << QLatin1String("RegexTest_703") + << QLatin1String("RegexTest_704") + << QLatin1String("RegexTest_705") + << QLatin1String("RegexTest_706") + << QLatin1String("RegexTest_707") + << QLatin1String("RegexTest_717") + << QLatin1String("RegexTest_718") + << QLatin1String("RegexTest_719") + << QLatin1String("RegexTest_724") + << QLatin1String("RegexTest_725") + << QLatin1String("RegexTest_726") + << QLatin1String("RegexTest_727") + << QLatin1String("RegexTest_728") + << QLatin1String("RegexTest_729") + << QLatin1String("RegexTest_730") + << QLatin1String("RegexTest_731") + << QLatin1String("RegexTest_732") + << QLatin1String("RegexTest_733") + << QLatin1String("RegexTest_743") + << QLatin1String("RegexTest_755") + << QLatin1String("RegexTest_756") + << QLatin1String("RegexTest_761") + << QLatin1String("RegexTest_762") + << QLatin1String("RegexTest_781") + << QLatin1String("RegexTest_782") + << QLatin1String("RegexTest_783") + << QLatin1String("RegexTest_790") + << QLatin1String("RegexTest_791") + << QLatin1String("RegexTest_824") + << QLatin1String("RegexTest_826") + << QLatin1String("RegexTest_827") + << QLatin1String("RegexTest_836") + << QLatin1String("RegexTest_837") + << QLatin1String("RegexTest_841") + << QLatin1String("RegexTest_842") + << QLatin1String("RegexTest_843") + << QLatin1String("RegexTest_844") + << QLatin1String("RegexTest_845") + << QLatin1String("RegexTest_846") + << QLatin1String("RegexTest_847") + << QLatin1String("RegexTest_848") + << QLatin1String("RegexTest_851") + << QLatin1String("RegexTest_852") + << QLatin1String("RegexTest_853") + << QLatin1String("RegexTest_854") + << QLatin1String("RegexTest_855") + << QLatin1String("RegexTest_856") + << QLatin1String("RegexTest_857") + << QLatin1String("RegexTest_861") + << QLatin1String("RegexTest_862") + << QLatin1String("RegexTest_863") + << QLatin1String("RegexTest_864") + << QLatin1String("RegexTest_865") + << QLatin1String("RegexTest_866") + << QLatin1String("RegexTest_870") + << QLatin1String("RegexTest_879") + << QLatin1String("RegexTest_880") + << QLatin1String("RegexTest_888") + << QLatin1String("RegexTest_889") + << QLatin1String("RegexTest_890") + << QLatin1String("RegexTest_891") + << QLatin1String("RegexTest_892") + << QLatin1String("RegexTest_893") + << QLatin1String("RegexTest_894") + << QLatin1String("RegexTest_895") + << QLatin1String("RegexTest_896") + << QLatin1String("RegexTest_897") + << QLatin1String("RegexTest_898") + << QLatin1String("RegexTest_899") + << QLatin1String("RegexTest_900") + << QLatin1String("RegexTest_901") + << QLatin1String("RegexTest_902") + << QLatin1String("RegexTest_903") + << QLatin1String("RegexTest_904") + << QLatin1String("RegexTest_905") + << QLatin1String("RegexTest_906") + << QLatin1String("RegexTest_907") + << QLatin1String("RegexTest_908") + << QLatin1String("RegexTest_909") + << QLatin1String("RegexTest_910") + << QLatin1String("RegexTest_911") + << QLatin1String("RegexTest_912") + << QLatin1String("RegexTest_913") + << QLatin1String("RegexTest_914") + << QLatin1String("RegexTest_915") + << QLatin1String("RegexTest_916") + << QLatin1String("RegexTest_917") + << QLatin1String("RegexTest_918") + << QLatin1String("RegexTest_919") + << QLatin1String("RegexTest_920") + << QLatin1String("RegexTest_921") + << QLatin1String("RegexTest_922") + << QLatin1String("RegexTest_923") + << QLatin1String("RegexTest_924") + << QLatin1String("RegexTest_925") + << QLatin1String("RegexTest_926") + << QLatin1String("RegexTest_928") + << QLatin1String("RegexTest_929") + << QLatin1String("RegexTest_930") + << QLatin1String("RegexTest_936") + << QLatin1String("RegexTest_937") + << QLatin1String("RegexTest_938") + << QLatin1String("RegexTest_939") + << QLatin1String("RegexTest_940") + << QLatin1String("RegexTest_941") + << QLatin1String("RegexTest_942") + << QLatin1String("RegexTest_943") + << QLatin1String("RegexTest_944") + << QLatin1String("RegexTest_945") + << QLatin1String("RegexTest_946") + << QLatin1String("RegexTest_949") + << QLatin1String("RegexTest_950") + << QLatin1String("RegexTest_951") + << QLatin1String("RegexTest_952") + << QLatin1String("RegexTest_953") + << QLatin1String("RegexTest_954") + << QLatin1String("RegexTest_955") + << QLatin1String("RegexTest_956") + << QLatin1String("RegexTest_957") + << QLatin1String("RegexTest_958") + << QLatin1String("RegexTest_959") + << QLatin1String("RegexTest_960") + << QLatin1String("RegexTest_961") + << QLatin1String("RegexTest_962") + << QLatin1String("RegexTest_963") + << QLatin1String("RegexTest_964") + << QLatin1String("RegexTest_976") + << QLatin1String("RegexTest_977") + << QLatin1String("RegexTest_988") + << QLatin1String("RegexTest_989") + << QLatin1String("RegexTest_990") + << QLatin1String("RegexTest_991") + << QLatin1String("RegexTest_994") + << QLatin1String("RegexTest_995") + << QLatin1String("RegexTest_996") + << QLatin1String("RegexTest_997") + << QLatin1String("RegexTest_1000") + << QLatin1String("RegexTest_1001") + << QLatin1String("RegexTest_1002") + << QLatin1String("RegexTest_1003") + << QLatin1String("RegexTest_1004") + << QLatin1String("RegexTest_1007") + << QLatin1String("RegexTest_1008") + << QLatin1String("RegexTest_1009") + << QLatin1String("RegexTest_1010") + << QLatin1String("RegexTest_1011") + << QLatin1String("RegexTest_1012") + << QLatin1String("RegexTest_1013") + << QLatin1String("RegexTest_1014") + << QLatin1String("RegexTest_1015") + << QLatin1String("RegexTest_1016") + << QLatin1String("RegexTest_1017") + << QLatin1String("RegexTest_1018") + << QLatin1String("RegexTest_1019") + << QLatin1String("RegexTest_1070") + << QLatin1String("RegexTest_1071") + << QLatin1String("RegexTest_1076") + << QLatin1String("RegexTest_1077") + << QLatin1String("RegexTest_1078") + << QLatin1String("RegexTest_1079") + << QLatin1String("RegexTest_1080") + << QLatin1String("RegexTest_1081") + << QLatin1String("RegexTest_1082") + << QLatin1String("RegexTest_1083") + << QLatin1String("RegexTest_1084") + << QLatin1String("RegexTest_1085") + << QLatin1String("RegexTest_1086") + << QLatin1String("RegexTest_1087") + << QLatin1String("RegexTest_1088") + << QLatin1String("RegexTest_1089") + << QLatin1String("RegexTest_1132") + << QLatin1String("RegexTest_1139") + << QLatin1String("RegexTest_1172") + << QLatin1String("RegexTest_1180") + << QLatin1String("RegexTest_1181") + << QLatin1String("RegexTest_1182") + << QLatin1String("RegexTest_1184") + << QLatin1String("RegexTest_1185") + << QLatin1String("RegexTest_1186") + << QLatin1String("RegexTest_1187") + << QLatin1String("RegexTest_1188") + << QLatin1String("RegexTest_1189") + << QLatin1String("RegexTest_1190") + << QLatin1String("RegexTest_1191") + << QLatin1String("RegexTest_1201") + << QLatin1String("RegexTest_1202") + << QLatin1String("RegexTest_1203") + << QLatin1String("RegexTest_1208") + << QLatin1String("RegexTest_1209") + << QLatin1String("RegexTest_1210") + << QLatin1String("RegexTest_1211") + << QLatin1String("RegexTest_1212") + << QLatin1String("RegexTest_1213") + << QLatin1String("RegexTest_1214") + << QLatin1String("RegexTest_1215") + << QLatin1String("RegexTest_1216") + << QLatin1String("RegexTest_1217") + << QLatin1String("RegexTest_1227") + << QLatin1String("RegexTest_1239") + << QLatin1String("RegexTest_1240") + << QLatin1String("RegexTest_1245") + << QLatin1String("RegexTest_1246") + << QLatin1String("RegexTest_1265") + << QLatin1String("RegexTest_1266") + << QLatin1String("RegexTest_1267") + << QLatin1String("RegexTest_1274") + << QLatin1String("RegexTest_1275") + << QLatin1String("RegexTest_1308") + << QLatin1String("RegexTest_1310") + << QLatin1String("RegexTest_1311") + << QLatin1String("RegexTest_1320") + << QLatin1String("RegexTest_1321") + << QLatin1String("RegexTest_1322") + << QLatin1String("RegexTest_1323") + << QLatin1String("RegexTest_1324") + << QLatin1String("RegexTest_1325") + << QLatin1String("RegexTest_1326") + << QLatin1String("RegexTest_1327") + << QLatin1String("RegexTest_1328") + << QLatin1String("RegexTest_1329") + << QLatin1String("RegexTest_1330") + << QLatin1String("RegexTest_1331") + << QLatin1String("RegexTest_1332") + << QLatin1String("RegexTest_1335") + << QLatin1String("RegexTest_1336") + << QLatin1String("RegexTest_1337") + << QLatin1String("RegexTest_1338") + << QLatin1String("RegexTest_1339") + << QLatin1String("RegexTest_1340") + << QLatin1String("RegexTest_1341") + << QLatin1String("RegexTest_1345") + << QLatin1String("RegexTest_1346") + << QLatin1String("RegexTest_1347") + << QLatin1String("RegexTest_1348") + << QLatin1String("RegexTest_1349") + << QLatin1String("RegexTest_1350") + << QLatin1String("RegexTest_1354") + << QLatin1String("RegexTest_1363") + << QLatin1String("RegexTest_1364") + << QLatin1String("RegexTest_1365") + << QLatin1String("RegexTest_1372") + << QLatin1String("RegexTest_1373") + << QLatin1String("RegexTest_1374") + << QLatin1String("RegexTest_1375") + << QLatin1String("RegexTest_1376") + << QLatin1String("RegexTest_1377") + << QLatin1String("RegexTest_1378") + << QLatin1String("RegexTest_1379") + << QLatin1String("RegexTest_1380") + << QLatin1String("RegexTest_1381") + << QLatin1String("RegexTest_1382") + << QLatin1String("RegexTest_1383") + << QLatin1String("RegexTest_1384") + << QLatin1String("RegexTest_1385") + << QLatin1String("RegexTest_1386") + << QLatin1String("RegexTest_1387") + << QLatin1String("RegexTest_1388") + << QLatin1String("RegexTest_1389") + << QLatin1String("RegexTest_1390") + << QLatin1String("RegexTest_1391") + << QLatin1String("RegexTest_1392") + << QLatin1String("RegexTest_1393") + << QLatin1String("RegexTest_1394") + << QLatin1String("RegexTest_1395") + << QLatin1String("RegexTest_1396") + << QLatin1String("RegexTest_1397") + << QLatin1String("RegexTest_1398") + << QLatin1String("RegexTest_1399") + << QLatin1String("RegexTest_1400") + << QLatin1String("RegexTest_1401") + << QLatin1String("RegexTest_1402") + << QLatin1String("RegexTest_1403") + << QLatin1String("RegexTest_1404") + << QLatin1String("RegexTest_1405") + << QLatin1String("RegexTest_1406") + << QLatin1String("RegexTest_1407") + << QLatin1String("RegexTest_1408") + << QLatin1String("RegexTest_1409") + << QLatin1String("RegexTest_1410") + << QLatin1String("RegexTest_1412") + << QLatin1String("RegexTest_1413") + << QLatin1String("RegexTest_1414") + << QLatin1String("RegexTest_1420") + << QLatin1String("RegexTest_1421") + << QLatin1String("RegexTest_1422") + << QLatin1String("RegexTest_1423") + << QLatin1String("RegexTest_1424") + << QLatin1String("RegexTest_1425") + << QLatin1String("RegexTest_1426") + << QLatin1String("RegexTest_1427") + << QLatin1String("RegexTest_1428") + << QLatin1String("RegexTest_1429") + << QLatin1String("RegexTest_1430") + << QLatin1String("RegexTest_1433") + << QLatin1String("RegexTest_1434") + << QLatin1String("RegexTest_1435") + << QLatin1String("RegexTest_1436") + << QLatin1String("RegexTest_1437") + << QLatin1String("RegexTest_1438") + << QLatin1String("RegexTest_1439") + << QLatin1String("RegexTest_1440") + << QLatin1String("RegexTest_1441") + << QLatin1String("RegexTest_1442") + << QLatin1String("RegexTest_1443") + << QLatin1String("RegexTest_1444") + << QLatin1String("RegexTest_1445") + << QLatin1String("RegexTest_1446") + << QLatin1String("RegexTest_1447") + << QLatin1String("RegexTest_1448") + << QLatin1String("RegexTest_1451") + << QLatin1String("RegexTest_1452") + << QLatin1String("RegexTest_1453") + << QLatin1String("RegexTest_1454") + << QLatin1String("RegexTest_1455") + << QLatin1String("RegexTest_1456") + << QLatin1String("RegexTest_1472") + << QLatin1String("RegexTest_1473") + << QLatin1String("RegexTest_1474") + << QLatin1String("RegexTest_1475") + << QLatin1String("RegexTest_1478") + << QLatin1String("RegexTest_1479") + << QLatin1String("RegexTest_1480") + << QLatin1String("RegexTest_1481") + << QLatin1String("RegexTest_1484") + << QLatin1String("RegexTest_1485") + << QLatin1String("RegexTest_1486") + << QLatin1String("RegexTest_1487") + << QLatin1String("RegexTest_1488") + << QLatin1String("RegexTest_1491") + << QLatin1String("RegexTest_1492") + << QLatin1String("RegexTest_1493") + << QLatin1String("RegexTest_1494") + << QLatin1String("RegexTest_1495") + << QLatin1String("RegexTest_1496") + << QLatin1String("RegexTest_1497") + << QLatin1String("RegexTest_1498") + << QLatin1String("RegexTest_1499") + << QLatin1String("RegexTest_1500") + << QLatin1String("RegexTest_1501") + << QLatin1String("RegexTest_1502") + << QLatin1String("RegexTest_1503") + << QLatin1String("RegexTest_1543") + << QLatin1String("RegexTest_1544") + << QLatin1String("reZ001") +*/ + << QLatin1String("schA2") + << QLatin1String("schA5") + << QLatin1String("schA7") + << QLatin1String("schD8") + << QLatin1String("schG3") + << QLatin1String("schG6") + << QLatin1String("schG9") + << QLatin1String("schG11") + << QLatin1String("schG12") + << QLatin1String("schU1") + << QLatin1String("schU3") + << QLatin1String("schU4") + << QLatin1String("schU5") + << QLatin1String("schZ004") + << QLatin1String("schZ005") + << QLatin1String("schZ012_a") + << QLatin1String("stZ041") + << QLatin1String("wildZ010"); +} + +bool XSDTestSuiteHandler::startElement(const QString &namespaceURI, + const QString &localName, + const QString &/*qName*/, + const QXmlAttributes &atts) +{ + if(namespaceURI != QString::fromLatin1("http://www.w3.org/XML/2004/xml-schema-test-suite/")) + return true; + + if (localName == QLatin1String("testSet")) { + m_currentTestSet = new TestGroup(m_topLevelGroup); + Q_ASSERT(m_currentTestSet); + m_currentTestSet->setTitle(atts.value("name")); + m_topLevelGroup->appendChild(m_currentTestSet); + } else if (localName == QLatin1String("testGroup")) { + m_currentTestGroup = new TestGroup(m_currentTestSet); + Q_ASSERT(m_currentTestGroup); + m_currentTestGroup->setTitle(atts.value("name")); + m_currentTestSet->appendChild(m_currentTestGroup); + m_inTestGroup = true; + } else if (localName == QLatin1String("schemaTest")) { + if (m_blackList.contains(atts.value("name"))) { + m_currentTestCase = 0; + m_schemaBlacklisted = true; + return true; + } + m_schemaBlacklisted = false; + + m_currentTestCase = new XSDTSTestCase(TestCase::Standard, m_currentTestGroup, XSDTSTestCase::SchemaTest); + Q_ASSERT(m_currentTestCase); + m_counter++; + m_currentTestCase->setName(QString::number(m_counter) + atts.value("name")); + m_currentTestGroup->appendChild(m_currentTestCase); + m_currentTestCase->setParent(m_currentTestGroup); + + m_inSchemaTest = true; + } else if (localName == QLatin1String("instanceTest")) { + if (m_schemaBlacklisted) { + m_currentTestCase = 0; + return true; + } + + m_currentTestCase = new XSDTSTestCase(TestCase::Standard, m_currentTestGroup, XSDTSTestCase::InstanceTest); + Q_ASSERT(m_currentTestCase); + m_counter++; + m_currentTestCase->setName(QString::number(m_counter) + atts.value("name")); + m_currentTestGroup->appendChild(m_currentTestCase); + + m_inInstanceTest = true; + } else if (localName == QLatin1String("schemaDocument") || localName == QLatin1String("instanceDocument")) { + if (m_inSchemaTest) { + m_currentTestCase->setSchemaUri(QUrl(atts.value("xlink:href"))); + if (m_currentSchemaLink.isEmpty()) // we only use the first schema document for validation + m_currentSchemaLink = atts.value("xlink:href"); + } + if (m_inInstanceTest) { + m_currentTestCase->setInstanceUri(QUrl(atts.value("xlink:href"))); + m_currentTestCase->setSchemaUri(QUrl(m_currentSchemaLink)); + } + } else if (localName == QLatin1String("expected") && (m_inSchemaTest || m_inInstanceTest)) { + TestBaseLine *baseLine = new TestBaseLine(TestBaseLine::SchemaIsValid); + if (atts.value("validity") == QLatin1String("valid")) { + baseLine->setDetails(QLatin1String("true")); + m_currentTestCase->setName(m_currentTestCase->name() + QLatin1String(" tokoe:valid")); + } else { + baseLine->setDetails(QLatin1String("false")); + m_currentTestCase->setName(m_currentTestCase->name() + QLatin1String(" tokoe:invalid")); + } + + m_currentTestCase->addBaseLine(baseLine); + } else if (localName == QLatin1String("documentation") && m_inTestGroup) { + m_inDescription = true; + } + + return true; +} + +bool XSDTestSuiteHandler::endElement(const QString &/*namespaceURI*/, + const QString &localName, + const QString &/*qName*/) +{ + if (localName == QLatin1String("testGroup")) { + m_inTestGroup = false; + m_currentTestGroup->setDescription(m_documentation); + m_documentation.clear(); + m_currentSchemaLink.clear(); + + if (m_currentTestGroup->childCount() == 0) + m_currentTestSet->removeLast(); + } else if (localName == QLatin1String("schemaTest")) + m_inSchemaTest = false; + else if (localName == QLatin1String("instanceTest")) + m_inInstanceTest = false; + else if (localName == QLatin1String("documentation")) + m_inDescription = false; + + return true; +} + +bool XSDTestSuiteHandler::characters(const QString &ch) +{ + if (m_inDescription) + m_documentation += ch; + + return true; +} + +TestSuite *XSDTestSuiteHandler::testSuite() const +{ + return m_ts; +} + +// vim: et:ts=4:sw=4:sts=4 + diff --git a/tests/auto/xmlpatternssdk/XSDTestSuiteHandler.h b/tests/auto/xmlpatternssdk/XSDTestSuiteHandler.h new file mode 100644 index 0000000..5493c7d --- /dev/null +++ b/tests/auto/xmlpatternssdk/XSDTestSuiteHandler.h @@ -0,0 +1,121 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the autotests 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$ +** +****************************************************************************/ + +#ifndef PatternistSDK_XSDTestSuiteHandler_H +#define PatternistSDK_XSDTestSuiteHandler_H + +#include +#include + +#include "ExternalSourceLoader.h" +#include "TestSuite.h" +#include "XQTSTestCase.h" + +QT_BEGIN_HEADER +QT_BEGIN_NAMESPACE + +namespace QPatternistSDK +{ + class TestBaseLine; + class TestGroup; + class XSDTSTestCase; + + /** + * @short Creates a TestSuite from the XSD Test Suite. + * + * The created TestSuite can be retrieved via testSuite(). + * + * @note XSDTestSuiteHandler assumes the XML is valid by having been validated + * against the W3C XML Schema. It has no safety checks for that the XML format + * is correct but is hard coded for it. Thus, the behavior is undefined if + * the XML is invalid. + * + * @ingroup PatternistSDK + * @author Tobias Koenig + */ + class Q_PATTERNISTSDK_EXPORT XSDTestSuiteHandler : public QXmlDefaultHandler + { + public: + /** + * @param catalogFile the URI for the catalog file being parsed. This + * URI is used for creating absolute URIs for files mentioned in + * the catalog with relative URIs. + * @param useExclusionList whether excludeTestGroups.txt should be used to ignore + * test groups when loading + */ + XSDTestSuiteHandler(const QUrl &catalogFile); + virtual bool characters(const QString &ch); + + virtual bool endElement(const QString &namespaceURI, + const QString &localName, + const QString &qName); + virtual bool startElement(const QString &namespaceURI, + const QString &localName, + const QString &qName, + const QXmlAttributes &atts); + + virtual TestSuite *testSuite() const; + + private: + TestSuite* m_ts; + const QUrl m_catalogFile; + + TestGroup* m_topLevelGroup; + TestGroup* m_currentTestSet; + TestGroup* m_currentTestGroup; + XSDTSTestCase* m_currentTestCase; + bool m_inSchemaTest; + bool m_inInstanceTest; + bool m_inTestGroup; + bool m_inDescription; + bool m_schemaBlacklisted; + QString m_documentation; + QString m_currentSchemaLink; + int m_counter; + QSet m_blackList; + }; +} + +QT_END_NAMESPACE +QT_END_HEADER + +#endif +// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternssdk/XSLTTestSuiteHandler.cpp b/tests/auto/xmlpatternssdk/XSLTTestSuiteHandler.cpp new file mode 100644 index 0000000..cfc3b2b --- /dev/null +++ b/tests/auto/xmlpatternssdk/XSLTTestSuiteHandler.cpp @@ -0,0 +1,234 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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 "qacceltreeresourceloader_p.h" +#include "qnetworkaccessdelegator_p.h" + +#include "Global.h" +#include "TestBaseLine.h" +#include "TestGroup.h" + +#include "XSLTTestSuiteHandler.h" + +using namespace QPatternistSDK; + +extern QNetworkAccessManager s_networkManager; + +XSLTTestSuiteHandler::XSLTTestSuiteHandler(const QUrl &catalogFile) : m_ts(0) + , m_tc(0) + , m_baseLine(0) + , m_catalogFile(catalogFile) + , m_removeTestcase(false) +{ + const QPatternist::NetworkAccessDelegator::Ptr networkDelegator(new QPatternist::NetworkAccessDelegator(&s_networkManager, &s_networkManager)); + + m_resourceLoader = QPatternist::ResourceLoader::Ptr(new QPatternist::AccelTreeResourceLoader(Global::namePool(), + networkDelegator)); + Q_ASSERT(!m_catalogFile.isRelative()); +} + +bool XSLTTestSuiteHandler::startElement(const QString &namespaceURI, + const QString &localName, + const QString &/*qName*/, + const QXmlAttributes &atts) + { + if(namespaceURI != Global::xsltsCatalogNS) + return true; + + /* The elements are handled roughly in the order of highest occurrence in the catalog file. */ + if(localName == QLatin1String("testcase")) + { + /* We pass m_ts temporarily, and change it later. */ + m_tc = new XQTSTestCase(TestCase::Standard, 0, QXmlQuery::XSLT20); + + m_currentQueryPath = m_queryOffset.resolved(QUrl(atts.value(QLatin1String("FilePath")))); + m_currentBaselinePath = m_baselineOffset.resolved(QUrl(atts.value(QLatin1String("FilePath")))); + } + else if(localName == QLatin1String("stylesheet")) + m_tc->setQueryPath(m_currentQueryPath.resolved(atts.value(QLatin1String("file")))); + else if(localName == QLatin1String("error")) + { + m_baseLine = new TestBaseLine(TestBaseLine::ExpectedError); + m_baseLine->setDetails(atts.value(QLatin1String("error-id"))); + m_tc->addBaseLine(m_baseLine); + } + else if(localName == QLatin1String("testcases")) + { + m_ts = new TestSuite(); + m_ts->setVersion(atts.value(QLatin1String("testSuiteVersion"))); + + m_queryOffset = m_catalogFile.resolved(atts.value(QLatin1String("InputOffsetPath"))); + m_baselineOffset = m_catalogFile.resolved(atts.value(QLatin1String("ResultOffsetPath"))); + m_sourceOffset = m_catalogFile.resolved(atts.value(QLatin1String("InputOffsetPath"))); + } + else if(localName == QLatin1String("source-document")) + { + if(atts.value(QLatin1String("role")) == QLatin1String("principal")) + m_tc->setContextItemSource(m_sourceOffset.resolved(QUrl(atts.value(QLatin1String("file"))))); + } + else if(localName == QLatin1String("result-document")) + { + m_baseLine = new TestBaseLine(TestBaseLine::identifierFromString(atts.value(QLatin1String("type")))); + m_baseLine->setDetails(m_currentBaselinePath.resolved(atts.value(QLatin1String("file"))).toString()); + m_tc->addBaseLine(m_baseLine); + } + else if(localName == QLatin1String("discretionary-feature")) + { + const QString feature(atts.value(QLatin1String("name"))); + + m_removeTestcase = feature == QLatin1String("schema_aware") || + feature == QLatin1String("namespace_axis") || + feature == QLatin1String("disabling_output_escaping") || + feature == QLatin1String("XML_1.1"); + } + else if(localName == QLatin1String("discretionary-choice")) + { + m_baseLine = new TestBaseLine(TestBaseLine::ExpectedError); + m_baseLine->setDetails(atts.value(QLatin1String("name"))); + m_tc->addBaseLine(m_baseLine); + const QString feature(atts.value(QLatin1String("name"))); + + m_removeTestcase = feature == QLatin1String("schema_aware") || + feature == QLatin1String("namespace_axis") || + feature == QLatin1String("disabling_output_escaping") || + feature == QLatin1String("XML_1.1"); + } + else if(localName == QLatin1String("entry-named-template")) + { + const QString name(atts.value(QLatin1String("qname"))); + + if(!name.contains(QLatin1Char(':'))) + { + // TODO do namespace processing + const QXmlName complete(Global::namePool()->allocateQName(QString(), name)); + + m_tc->setInitialTemplateName(complete); + } + } + + return true; +} + +TestGroup *XSLTTestSuiteHandler::containerFor(const QString &name) +{ + TestGroup *& c = m_containers[name]; + + if(!c) + { + c = new TestGroup(m_ts); + c->setTitle(name); + Q_ASSERT(c); + m_ts->appendChild(c); + } + + return c; +} + +bool XSLTTestSuiteHandler::endElement(const QString &namespaceURI, + const QString &localName, + const QString &/*qName*/) +{ + if(namespaceURI != Global::xsltsCatalogNS) + return true; + + /* The elements are handled roughly in the order of highest occurrence in the catalog file. */ + if(localName == QLatin1String("description")) + { + if(m_tc) + { + /* We're inside a , so the belongs + * to the testcase. */ + m_tc->setDescription(m_ch.simplified()); + } + } + else if(localName == QLatin1String("testcase")) + { + Q_ASSERT(m_tc->baseLines().count() >= 1); + Q_ASSERT(m_resourceLoader); + // TODO can this be removed? + m_tc->setExternalVariableLoader(QPatternist::ExternalVariableLoader::Ptr + (new ExternalSourceLoader(m_tcSourceInputs, + m_resourceLoader))); + m_tcSourceInputs.clear(); + + if(!m_removeTestcase) + { + /* + TestContainer *const container = containerFor(m_currentCategory); + delete m_tc; + container->removeLast(); + */ + TestContainer *const container = containerFor(m_currentCategory); + m_tc->setParent(container); + Q_ASSERT(m_tc); + container->appendChild(m_tc); + } + + m_tc = 0; + m_removeTestcase = false; + } + else if(localName == QLatin1String("name")) + m_tc->setName(m_ch); + else if(localName == QLatin1String("creator")) + m_tc->setCreator(m_ch); + else if(localName == QLatin1String("contextItem")) + m_contextItemSource = m_ch; + else if(localName == QLatin1String("category")) + m_currentCategory = m_ch; + + return true; +} + +bool XSLTTestSuiteHandler::characters(const QString &ch) +{ + m_ch = ch; + return true; +} + +TestSuite *XSLTTestSuiteHandler::testSuite() const +{ + return m_ts; +} + +// vim: et:ts=4:sw=4:sts=4 + diff --git a/tests/auto/xmlpatternssdk/XSLTTestSuiteHandler.h b/tests/auto/xmlpatternssdk/XSLTTestSuiteHandler.h new file mode 100644 index 0000000..8614789 --- /dev/null +++ b/tests/auto/xmlpatternssdk/XSLTTestSuiteHandler.h @@ -0,0 +1,158 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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$ +** +****************************************************************************/ + +#ifndef PatternistSDK_XSLTTestSuiteHandler_H +#define PatternistSDK_XSLTTestSuiteHandler_H + +#include +#include +#include + +#include "ExternalSourceLoader.h" +#include "TestSuite.h" +#include "XQTSTestCase.h" + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +namespace QPatternistSDK +{ + class TestBaseLine; + class TestGroup; + + /** + * @short Creates a TestSuite from the XQuery Test Suite catalog. + * + * The created TestSuite can be retrieved via testSuite(). + * + * @note XSLTTestSuiteHandler assumes the XML is valid by having been validated + * against the W3C XML Schema. It has no safety checks for that the XML format + * is correct but is hard coded for it. Thus, the behavior is undefined if + * the XML is invalid. + * + * @see http://www.w3.org/XML/Group/xslt20-test/TestSuiteStagingArea/catalog.html + * @see http://www.w3.org/XML/Group/xslt20-test/Documentation/XSLT2Test.htm + * @ingroup PatternistSDK + * @author Frans Englich + */ + class Q_PATTERNISTSDK_EXPORT XSLTTestSuiteHandler : public QXmlDefaultHandler + { + public: + /** + * @param catalogFile the URI for the catalog file being parsed. This + * URI is used for creating absolute URIs for files mentioned in + * the catalog with relative URIs. + * @param useExclusionList whether excludeTestGroups.txt should be used to ignore + * test groups when loading + */ + XSLTTestSuiteHandler(const QUrl &catalogFile); + virtual bool characters(const QString &ch); + + virtual bool endElement(const QString &namespaceURI, + const QString &localName, + const QString &qName); + virtual bool startElement(const QString &namespaceURI, + const QString &localName, + const QString &qName, + const QXmlAttributes &atts); + + virtual TestSuite *testSuite() const; + + private: + TestGroup *containerFor(const QString &name); + + QHash m_containers; + + TestSuite * m_ts; + XQTSTestCase * m_tc; + TestBaseLine * m_baseLine; + QString m_ch; + const QUrl m_catalogFile; + + /** + * The base URI for where the XQuery query files are found. + * It is absolute, resolved against catalogFile. + */ + QUrl m_queryOffset; + + QUrl m_baselineOffset; + QUrl m_sourceOffset; + QUrl m_currentQueryPath; + QUrl m_currentBaselinePath; + + /** + * In the XQTSCatalog.xml, each source file in each test is referred to + * by a key, which can be fully looked up in the @c sources element. This QHash + * maps the keys to absolute URIs pointing to the source files. + */ + ExternalSourceLoader::SourceMap m_sourceMap; + + ExternalSourceLoader::VariableMap m_tcSourceInputs; + + QPatternist::ResourceLoader::Ptr m_resourceLoader; + + /** + * The current value of input-file/\@variable. + */ + QString m_currentInputVariable; + + /** + * The names of the test groups. + */ + QStack m_testGroupName; + + /** + * Holds the content of the current input-URI element. + */ + QString m_inputURI; + QString m_contextItemSource; + QString m_currentCategory; + bool m_removeTestcase; + }; +} + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif +// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternssdk/docs/XMLIndenterExample.cpp b/tests/auto/xmlpatternssdk/docs/XMLIndenterExample.cpp new file mode 100644 index 0000000..24ee158 --- /dev/null +++ b/tests/auto/xmlpatternssdk/docs/XMLIndenterExample.cpp @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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$ +** +****************************************************************************/ +QByteArray result; +QBuffer returnBuffer(&result); +XMLWriter writer(&returnBuffer); + +writer.startDocument(); + +writer.startDTD(QLatin1String("html"), QLatin1String("-//W3C//DTD XHTML 1.0 Strict//EN"), + QLatin1String("http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd")); +writer.endDTD(); + +writer.startPrefixMapping(QString(), QLatin1String("http://www.w3.org/1999/xhtml")); + +writer.startElement(QLatin1String("html"), QXmlAttributes()); +writer.startElement(QLatin1String("body"), QXmlAttributes()); +writer.startElement(QLatin1String("p"), QXmlAttributes()); + +writer.characters(QLatin1String("Hello World!")); + +writer.endElement(QLatin1String("p")); +writer.endElement(QLatin1String("body")); +writer.endElement(QLatin1String("html")); + +writer.endDocument(); diff --git a/tests/auto/xmlpatternssdk/docs/XMLIndenterExampleResult.xml b/tests/auto/xmlpatternssdk/docs/XMLIndenterExampleResult.xml new file mode 100644 index 0000000..c5e7312 --- /dev/null +++ b/tests/auto/xmlpatternssdk/docs/XMLIndenterExampleResult.xml @@ -0,0 +1,3 @@ + + +

Hello World!

diff --git a/tests/auto/xmlpatternssdk/docs/XMLWriterExample.cpp b/tests/auto/xmlpatternssdk/docs/XMLWriterExample.cpp new file mode 100644 index 0000000..24ee158 --- /dev/null +++ b/tests/auto/xmlpatternssdk/docs/XMLWriterExample.cpp @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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$ +** +****************************************************************************/ +QByteArray result; +QBuffer returnBuffer(&result); +XMLWriter writer(&returnBuffer); + +writer.startDocument(); + +writer.startDTD(QLatin1String("html"), QLatin1String("-//W3C//DTD XHTML 1.0 Strict//EN"), + QLatin1String("http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd")); +writer.endDTD(); + +writer.startPrefixMapping(QString(), QLatin1String("http://www.w3.org/1999/xhtml")); + +writer.startElement(QLatin1String("html"), QXmlAttributes()); +writer.startElement(QLatin1String("body"), QXmlAttributes()); +writer.startElement(QLatin1String("p"), QXmlAttributes()); + +writer.characters(QLatin1String("Hello World!")); + +writer.endElement(QLatin1String("p")); +writer.endElement(QLatin1String("body")); +writer.endElement(QLatin1String("html")); + +writer.endDocument(); diff --git a/tests/auto/xmlpatternssdk/docs/XMLWriterExampleResult.xml b/tests/auto/xmlpatternssdk/docs/XMLWriterExampleResult.xml new file mode 100644 index 0000000..c5e7312 --- /dev/null +++ b/tests/auto/xmlpatternssdk/docs/XMLWriterExampleResult.xml @@ -0,0 +1,3 @@ + + +

Hello World!

diff --git a/tests/auto/xmlpatternssdk/tests/XMLWriterTest.cpp b/tests/auto/xmlpatternssdk/tests/XMLWriterTest.cpp new file mode 100644 index 0000000..a10c01a --- /dev/null +++ b/tests/auto/xmlpatternssdk/tests/XMLWriterTest.cpp @@ -0,0 +1,186 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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 "XMLWriter.h" + +#include "XMLWriterTest.h" +#include "XMLWriterTest.moc" + +using namespace QPatternistSDK; + +QTEST_MAIN(XMLWriterTest) + +void XMLWriterTest::serialize() +{ + QFETCH(QString, input); + QFETCH(QString, expectedResult); + + QByteArray result; + QBuffer returnBuffer(&result); + + XMLWriter writer(&returnBuffer); + + QXmlInputSource inputSource; + inputSource.setData(input); + + QXmlSimpleReader reader; + reader.setContentHandler(&writer); + + const bool parseSuccess = reader.parse(inputSource); + Q_ASSERT_X(parseSuccess, Q_FUNC_INFO, + "XMLWriter reported an error while serializing the input."); + + QCOMPARE(QString::fromLatin1(result), expectedResult); +} + +void XMLWriterTest::serialize_data() +{ + QTest::addColumn("input"); + QTest::addColumn("expectedResult"); + + /* ------------------- Elements ------------------- */ + QTest::newRow("Only an document element") + << "" + << "\n"; + + QTest::newRow("Document element containing a short closed element") + << "" + << "\n"; + QTest::newRow("Complex nested elements") + << "" + << "\n"; + /* ------------------------------------------------- */ + + /* ---------------- Element Content ---------------- */ + QTest::newRow("Element content with simple content") + << "content" + << "\ncontent"; + + QTest::newRow("Element content with tricky to escape content") + << ">>&'\"''/>" + << "\n>>&'\"''/>"; + /* ------------------------------------------------- */ + + /* ----------- Processing Instructions ------------- */ + QTest::newRow("Simple processing instruction.") + << "" + << "\n"; + /* ------------------------------------------------- */ + + /* --------------- 'xml' attributes ---------------- */ + QTest::newRow("Simple xml:space attribute.") + << "content" + << "\ncontent"; + + QTest::newRow("Many 'xml' attributes.") + << "content" + << "\n" + "content"; + /* ------------------------------------------------- */ + + /* ------------ namespace declarations ------------- */ + QTest::newRow("One simple namespace declaration.") + << "" + << "\n" + ""; + + QTest::newRow("Two simple namespace declarations.") + << "" + << "\n" + ""; + + QTest::newRow("A simple default namespace.") + << "" + << "\n" + ""; + /* ------------------------------------------------- */ + + /* -------- namespace declarations in use ---------- */ + QTest::newRow("Simple use of a namespace declaration.") + << "" + << "\n" + ""; + /* ------------------------------------------------- */ +} + +void XMLWriterTest::cdata() +{ + /* + QTest::newRow("Simple CDATA") + << "" + << "\n"; + + QTest::newRow("Complex CDATA") + << ">&'\";&987;]]>" + << "\n>&'\";&123;]]>"; + */ +} + +void XMLWriterTest::comments() +{ + /* + QTest::newRow("Simple comment") + << "" + << "\n"; + QTest::newRow("Comment") + << "" + << "\n"; + */ +} + +void XMLWriterTest::doxygenExample() +{ +#include "../docs/XMLWriterExample.cpp" + + /* When changing, remember to update the Doxygen in XMLWriter.h */ + const QByteArray expectedResult( + "\n" + "\n" + "

Hello World!

" + ); + + QCOMPARE(QString::fromLatin1(result), QString::fromLatin1(expectedResult)); +} + +// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternssdk/tests/XMLWriterTest.h b/tests/auto/xmlpatternssdk/tests/XMLWriterTest.h new file mode 100644 index 0000000..f90aea2 --- /dev/null +++ b/tests/auto/xmlpatternssdk/tests/XMLWriterTest.h @@ -0,0 +1,77 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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$ +** +****************************************************************************/ + +#ifndef PatternistSDK_XMLWriterTest_H +#define PatternistSDK_XMLWriterTest_H + +#include + +QT_BEGIN_HEADER + +namespace QPatternistSDK +{ + /** + * @short QTestLib test for XMLWriter. + * + * @ingroup PatternistSDK + * @author Frans Englich + */ + class XMLWriterTest : public QObject + { + Q_OBJECT + private Q_SLOTS: + void serialize(); + void serialize_data(); + void comments(); + void cdata(); + + /** + * Ensure the example compiles, and that it does + * what it claims to. + */ + void doxygenExample(); + }; +} + +QT_END_HEADER + +#endif +// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternssdk/xmlpatternssdk.pro b/tests/auto/xmlpatternssdk/xmlpatternssdk.pro new file mode 100644 index 0000000..6204f01 --- /dev/null +++ b/tests/auto/xmlpatternssdk/xmlpatternssdk.pro @@ -0,0 +1,88 @@ +include (../xmlpatterns.pri) + +TARGET = $$XMLPATTERNS_SDK +TEMPLATE = lib +DEFINES += Q_PATTERNISTSDK_BUILDING + +# lib_bundle ensures we get a framework on OS X, a library bundle. +CONFIG += resources + +mac { + CONFIG += absolute_library_soname + target.path=$$[QT_INSTALL_LIBS] + INSTALLS += target +} + +symbian { + TARGET.EPOCALLOWDLLDATA=1 + TARGET.CAPABILITY = All -Tcb + MMP_RULES += EXPORTUNFROZEN +} + +# We add gui, because xmlpatterns.pri pull it out. +QT += xmlpatterns xml network testlib gui + +DESTDIR = $$QT_BUILD_TREE/lib +!wince*:DLLDESTDIR = $$QT_BUILD_TREE/bin + +# syncqt doesn't copy headers in tools/ so let's manually ensure +# it works with shadow builds and source builds. +INCLUDEPATH += $$QT_BUILD_TREE/include/QtXmlPatterns/private \ + $$QT_SOURCE_TREE/include/QtXmlPatterns/private \ + $$QT_SOURCE_TREE/tools/xmlpatterns + +HEADERS = ASTItem.h \ + DebugExpressionFactory.h \ + ErrorHandler.h \ + ErrorItem.h \ + ExitCode.h \ + ExpressionInfo.h \ + ExpressionNamer.h \ + ExternalSourceLoader.h \ + Global.h \ + ResultThreader.h \ + TestBaseLine.h \ + TestCase.h \ + TestContainer.h \ + TestGroup.h \ + TestItem.h \ + TestResult.h \ + TestResultHandler.h \ + TestSuite.h \ + TestSuiteHandler.h \ + TestSuiteResult.h \ + TreeItem.h \ + TreeModel.h \ + Worker.h \ + XMLWriter.h \ + XQTSTestCase.h \ + XSDTestSuiteHandler.h \ + XSDTSTestCase.h \ + XSLTTestSuiteHandler.h + +SOURCES = ASTItem.cpp \ + DebugExpressionFactory.cpp \ + ErrorHandler.cpp \ + ErrorItem.cpp \ + ExpressionInfo.cpp \ + ExpressionNamer.cpp \ + ExternalSourceLoader.cpp \ + Global.cpp \ + ResultThreader.cpp \ + TestBaseLine.cpp \ + TestCase.cpp \ + TestContainer.cpp \ + TestGroup.cpp \ + TestResult.cpp \ + TestResultHandler.cpp \ + TestSuite.cpp \ + TestSuiteHandler.cpp \ + TestSuiteResult.cpp \ + TreeItem.cpp \ + TreeModel.cpp \ + Worker.cpp \ + XMLWriter.cpp \ + XQTSTestCase.cpp \ + XSDTestSuiteHandler.cpp \ + XSDTSTestCase.cpp \ + XSLTTestSuiteHandler.cpp diff --git a/tests/auto/xmlpatternsview/test/test.pro b/tests/auto/xmlpatternsview/test/test.pro deleted file mode 100644 index 6adff4d..0000000 --- a/tests/auto/xmlpatternsview/test/test.pro +++ /dev/null @@ -1,17 +0,0 @@ -load(qttest_p4) -SOURCES += tst_xmlpatternsview.cpp - -include (../../xmlpatterns.pri) - -DESTDIR = .. -win32 { - CONFIG(debug, debug|release): DESTDIR = ../debug - else: DESTDIR = ../release -} -TARGET = tst_xmlpatternsview - -wince*: { - viewexe.sources = $$QT_BUILD_TREE/xmlpatternsview.exe - viewexe.path = . - DEPLOYMENT += viewexe -} diff --git a/tests/auto/xmlpatternsview/test/tst_xmlpatternsview.cpp b/tests/auto/xmlpatternsview/test/tst_xmlpatternsview.cpp deleted file mode 100644 index 91dee63..0000000 --- a/tests/auto/xmlpatternsview/test/tst_xmlpatternsview.cpp +++ /dev/null @@ -1,74 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 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 - -#ifdef QTEST_XMLPATTERNS - -/*! - \class tst_XmlPatternsView - \internal - \since 4.5 - \brief This test tests nothing, it only exists in order to have a place - for the xmlpatternsview utility. - - tests/auto/xmlpatternsview doesn't test anything, it only exists to house the - xmlpatternsview debugging utility inside the Qt directory. - */ -class tst_XmlPatternsView : public QObject -{ - Q_OBJECT - -private Q_SLOTS: - void run() const; -}; - -void tst_XmlPatternsView::run() const -{ -} - -QTEST_MAIN(tst_XmlPatternsView) - -#include "tst_xmlpatternsview.moc" -#else //QTEST_XMLPATTERNS -QTEST_NOOP_MAIN -#endif diff --git a/tests/auto/xmlpatternsview/tst_xmlpatternsview.cpp b/tests/auto/xmlpatternsview/tst_xmlpatternsview.cpp new file mode 100644 index 0000000..91dee63 --- /dev/null +++ b/tests/auto/xmlpatternsview/tst_xmlpatternsview.cpp @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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 + +#ifdef QTEST_XMLPATTERNS + +/*! + \class tst_XmlPatternsView + \internal + \since 4.5 + \brief This test tests nothing, it only exists in order to have a place + for the xmlpatternsview utility. + + tests/auto/xmlpatternsview doesn't test anything, it only exists to house the + xmlpatternsview debugging utility inside the Qt directory. + */ +class tst_XmlPatternsView : public QObject +{ + Q_OBJECT + +private Q_SLOTS: + void run() const; +}; + +void tst_XmlPatternsView::run() const +{ +} + +QTEST_MAIN(tst_XmlPatternsView) + +#include "tst_xmlpatternsview.moc" +#else //QTEST_XMLPATTERNS +QTEST_NOOP_MAIN +#endif diff --git a/tests/auto/xmlpatternsview/xmlpatternsview.pro b/tests/auto/xmlpatternsview/xmlpatternsview.pro index 04ee4d0..d93cba3 100644 --- a/tests/auto/xmlpatternsview/xmlpatternsview.pro +++ b/tests/auto/xmlpatternsview/xmlpatternsview.pro @@ -1,9 +1,12 @@ -TEMPLATE = subdirs -CONFIG += ordered +load(qttest_p4) +SOURCES += tst_xmlpatternsview.cpp -SUBDIRS = ../xmlpatternsxqts test +include (../xmlpatterns.pri) -contains(QT_CONFIG,xmlpatterns) { - SUBDIRS += view +TARGET = tst_xmlpatternsview + +wince*: { + viewexe.sources = $$QT_BUILD_TREE/xmlpatternsview.exe + viewexe.path = . + DEPLOYMENT += viewexe } -requires(contains(QT_CONFIG,private_tests)) diff --git a/tests/auto/xmlpatternsxqts/lib/ASTItem.cpp b/tests/auto/xmlpatternsxqts/lib/ASTItem.cpp deleted file mode 100644 index 3b4fbdc..0000000 --- a/tests/auto/xmlpatternsxqts/lib/ASTItem.cpp +++ /dev/null @@ -1,161 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 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 - -#include "ASTItem.h" - -using namespace QPatternistSDK; - -/** - * This is what the AST rendering is indented with. - */ -static const QLatin1String astIndent(" "); -// STATIC DATA - -ASTItem::ASTItem(ASTItem *p, - const QString &name, - const QString &details, - const QString &staticType, - const QString &reqType) : m_name(name), - m_details(details), - m_reqType(reqType), - m_staticType(staticType), - m_parent(p) -{ -} - -ASTItem::~ASTItem() -{ - qDeleteAll(m_children); -} - -QString ASTItem::toString() const -{ - /* The first ASTItem* is a virtual root node, so skip "this". */ - Q_ASSERT(m_children.count() == 1); - TreeItem *treeChild = m_children.first(); - Q_ASSERT(treeChild); - - ASTItem *astChild = static_cast(treeChild); - - return astChild->toString(QString()); -} - -QString ASTItem::toString(const QString &indent) const -{ - QString retval; - - retval += indent; - retval += m_name; - retval += QLatin1Char('('); - retval += m_details; - retval += QLatin1String(")\n"); - - const TreeItem::List::const_iterator end(m_children.constEnd()); - - for(TreeItem::List::const_iterator it(m_children.constBegin()); it != end; ++it) - { - TreeItem *treeChild = *it; /* Cast away the QPointer with its casting operator. */ - ASTItem *astChild = static_cast(treeChild); - - retval += astChild->toString(indent + astIndent); - } - - return retval; -} - -QVariant ASTItem::data(const Qt::ItemDataRole role, int column) const -{ - if(role != Qt::DisplayRole) - return QVariant(); - - switch(column) - { - case 0: - return m_name; - case 1: - return m_details; - case 2: - return m_staticType; - case 3: - return m_reqType; - default: - { - Q_ASSERT(false); - return QVariant(); - } - } -} - -int ASTItem::columnCount() const -{ - return 4; -} - -TreeItem::List ASTItem::children() const -{ - return m_children; -} - -void ASTItem::appendChild(TreeItem *item) -{ - m_children.append(item); -} - -TreeItem *ASTItem::child(const unsigned int rowP) const -{ - return m_children.value(rowP); -} - -unsigned int ASTItem::childCount() const -{ - return m_children.count(); -} - -TreeItem *ASTItem::parent() const -{ - return m_parent; -} - -// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternsxqts/lib/ASTItem.h b/tests/auto/xmlpatternsxqts/lib/ASTItem.h deleted file mode 100644 index ca3ac8f..0000000 --- a/tests/auto/xmlpatternsxqts/lib/ASTItem.h +++ /dev/null @@ -1,115 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 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$ -** -****************************************************************************/ - -#ifndef PatternistSDK_ASTItem_H -#define PatternistSDK_ASTItem_H - -#include -#include - -#include "TreeItem.h" -#include "Global.h" - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -namespace QPatternistSDK -{ - /** - * @short Is a node in a ASTItem tree; each ASTItem contains - * debug information about an QPatternist::Expression. - * - * ASTItem, by implementing TreeItem, leverages debug data about QPatternist::Expression - * instances into Qt's model/view framework. - * - * @ingroup PatternistSDK - * @author Frans Englich - */ - class Q_PATTERNISTSDK_EXPORT ASTItem : public TreeItem - { - public: - virtual ~ASTItem(); - ASTItem(ASTItem *parent, - const QString &name, - const QString &details = QString(), - const QString &staticType = QString(), - const QString &reqType = QString()); - - virtual void appendChild(TreeItem *item); - virtual TreeItem *child(const unsigned int row) const; - virtual unsigned int childCount() const; - virtual QVariant data(const Qt::ItemDataRole role, int column) const; - virtual TreeItem::List children() const; - virtual TreeItem *parent() const; - int columnCount() const; - - /** - * Returns a string representation of this AST node, recursively including - * children. For example, the query 1 eq number() would result in the string: - * -@verbatim -ValueComparison(eq) - xs:integer(0) - FunctionCall(fn:number) - ContextItem -@endverbatim - */ - QString toString() const; - - private: - QString toString(const QString &indent) const; - - const QString m_name; - const QString m_details; - const QString m_reqType; - const QString m_staticType; - TreeItem::List m_children; - TreeItem *m_parent; - }; -} - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif -// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternsxqts/lib/DebugExpressionFactory.cpp b/tests/auto/xmlpatternsxqts/lib/DebugExpressionFactory.cpp deleted file mode 100644 index 1b5121e..0000000 --- a/tests/auto/xmlpatternsxqts/lib/DebugExpressionFactory.cpp +++ /dev/null @@ -1,264 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 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 -#include - -#include "qfunctionfactorycollection_p.h" - -#include "ASTItem.h" -#include "ExpressionInfo.h" -#include "ExpressionNamer.h" -#include "Global.h" - -#include "DebugExpressionFactory.h" - -using namespace QPatternistSDK; -using namespace QPatternist; - -static const QPatternist::ExpressionVisitor::Ptr namer(new ExpressionNamer()); - -QStringList DebugExpressionFactory::availableFunctionSignatures() -{ - const QPatternist::FunctionFactory::Ptr factory(QPatternist::FunctionFactoryCollection::xpath20Factory(Global::namePool())); - const QPatternist::FunctionSignature::Hash signs(factory->functionSignatures()); - const QPatternist::FunctionSignature::Hash::const_iterator end(signs.constEnd()); - QPatternist::FunctionSignature::Hash::const_iterator it(signs.constBegin()); - QStringList retval; - - while(it != end) - { - retval << it.value()->displayName(Global::namePool()); - ++it; - } - - return retval; -} - -ASTItem *DebugExpressionFactory::buildASTTree(const QPatternist::Expression::Ptr &expr, - ASTItem *parent, - const QPatternist::SequenceType::Ptr &reqType) -{ - Q_ASSERT(expr); - const QPatternist::ExpressionVisitorResult::Ptr exprInfo(expr->accept(namer)); - Q_ASSERT(exprInfo); - const ExpressionInfo *const constExprInfo = static_cast(exprInfo.data()); - const QString name(constExprInfo->first); - const QString details(constExprInfo->second); - const QString rType(reqType ? reqType->displayName(Global::namePool()) : QLatin1String("Not specified")); - - /* ---------- Handle its staticType() -------- */ - const QPatternist::SequenceType::Ptr type(expr->staticType()); - QString seqType; - - if(type) - seqType = type->displayName(Global::namePool()); - else - seqType = QLatin1String("no type, null pointer returned"); - /* ------------------------------------------- */ - - ASTItem *const node = new ASTItem(parent, name, details, seqType, rType); - - /* ------------ Handle child nodes ----------- */ - const QPatternist::Expression::List children(expr->operands()); - QPatternist::Expression::List::const_iterator it(children.constBegin()); - const QPatternist::Expression::List::const_iterator end(children.constEnd()); - - const QPatternist::SequenceType::List reqTypes(expr->expectedOperandTypes()); - const QPatternist::SequenceType::List::const_iterator typeEnd(reqTypes.constEnd()); - QPatternist::SequenceType::List::const_iterator typeIt(reqTypes.constBegin()); - QPatternist::SequenceType::Ptr t; - - for(; it != end; ++it) - { - if(typeIt != typeEnd) - { - t = *typeIt; - ++typeIt; - } - - node->appendChild(buildASTTree(*it, node, t)); - } - /* ------------------------------------------- */ - - return node; -} - -QPatternist::Expression::Ptr -DebugExpressionFactory::createExpression(QIODevice *const expr, - const QPatternist::StaticContext::Ptr &context, - const QXmlQuery::QueryLanguage lang, - const QPatternist::SequenceType::Ptr &requiredType, - const QUrl &baseURI, - const QXmlName &initialTemplateName) -{ - /* Create the root node. */ - m_ast = new ASTItem(0, QString()); - - return ExpressionFactory::createExpression(expr, context, lang, requiredType, baseURI, initialTemplateName); -} - -void DebugExpressionFactory::processTreePass(const QPatternist::Expression::Ptr &expr, - const CompilationStage stage) -{ - ASTItem *newChild = 0; - - switch(stage) - { - case QueryBodyInitial: - { - newChild = new ASTItem(m_ast, QLatin1String("Initial Build")); - break; - } - case QueryBodyTypeCheck: - { - newChild = new ASTItem(m_ast, QLatin1String("Type Check")); - break; - } - case QueryBodyCompression: - { - newChild = new ASTItem(m_ast, QLatin1String("Compression")); - break; - } - case UserFunctionTypeCheck: - { - newChild = new ASTItem(m_ast, QLatin1String("User Function Type Check")); - break; - } - case UserFunctionCompression: - { - newChild = new ASTItem(m_ast, QLatin1String("User Function Compression")); - break; - } - case GlobalVariableTypeCheck: - { - newChild = new ASTItem(m_ast, QLatin1String("Global Variable Type Check")); - break; - } - } - - Q_ASSERT(newChild); - m_ast->appendChild(newChild); - newChild->appendChild(buildASTTree(expr, newChild, QPatternist::SequenceType::Ptr())); -} - -void DebugExpressionFactory::processTemplateRule(const Expression::Ptr &body, - const TemplatePattern::Ptr &pattern, - const QXmlName &mode, - const TemplateCompilationStage stage) -{ - const char * title; - - switch(stage) - { - case TemplateInitial: - { - title = "Initial Build"; - break; - } - case TemplateTypeCheck: - { - title = "Type Check"; - break; - } - case TemplateCompress: - { - title = "Compression"; - break; - } - } - - const QString modeName(Global::namePool()->displayName(mode)); - Q_ASSERT(title); - ASTItem *const newChild = new ASTItem(m_ast, QLatin1String("T-Rule ") - + QLatin1String(title) - + QLatin1String(" mode: ") - + modeName - + QLatin1String(" priority: ") - + QString::number(pattern->priority())); - m_ast->appendChild(newChild); - - newChild->appendChild(buildASTTree(pattern->matchPattern(), newChild, QPatternist::SequenceType::Ptr())); - newChild->appendChild(buildASTTree(body, newChild, QPatternist::SequenceType::Ptr())); -} - -void DebugExpressionFactory::processNamedTemplate(const QXmlName &name, - const Expression::Ptr &body, - const TemplateCompilationStage stage) -{ - const char * title; - - switch(stage) - { - case TemplateInitial: - { - title = "Named Template Initial Build"; - break; - } - case TemplateTypeCheck: - { - title = "Named Template Type Check"; - break; - } - case TemplateCompress: - { - title = "Named Template Compression"; - break; - } - } - - Q_ASSERT(title); - ASTItem *const newChild = new ASTItem(m_ast, QLatin1String(title) - + QLatin1String(": ") - + Global::namePool()->displayName(name)); - - m_ast->appendChild(newChild); - newChild->appendChild(buildASTTree(body, newChild, QPatternist::SequenceType::Ptr())); -} - -ASTItem *DebugExpressionFactory::astTree() const -{ - return m_ast; -} - -// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternsxqts/lib/DebugExpressionFactory.h b/tests/auto/xmlpatternsxqts/lib/DebugExpressionFactory.h deleted file mode 100644 index d5e676d..0000000 --- a/tests/auto/xmlpatternsxqts/lib/DebugExpressionFactory.h +++ /dev/null @@ -1,128 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 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$ -** -****************************************************************************/ - -#ifndef PatternistSDK_DebugExpressionFactory_H -#define PatternistSDK_DebugExpressionFactory_H - -#include "Global.h" -#include "qexpressionfactory_p.h" -#include "qfunctionfactory_p.h" - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -namespace QPatternistSDK -{ - class ASTItem; - - /** - * @short Is a QPatternist::ExpressionFactory, with the - * difference that it provides the hooks for building from a tree of - * debug data from the compiled expression. - * - * This tree can be retrieved via astTree(). The astTree() function - * returns the AST built the last time createExpression() was called. - * - * @ingroup PatternistSDK - * @author Frans Englich - */ - class Q_PATTERNISTSDK_EXPORT DebugExpressionFactory : public QPatternist::ExpressionFactory - { - public: - DebugExpressionFactory() : m_ast(0) - { - } - - typedef QExplicitlySharedDataPointer Ptr; - /** - * Identical to ExpressionFactory::createExpression() with the difference - * that it builds an ASTItem tree which can be accessed via astTree(). - */ - virtual QPatternist::Expression::Ptr createExpression(QIODevice *const expr, - const QPatternist::StaticContext::Ptr &context, - const QXmlQuery::QueryLanguage lang, - const QPatternist::SequenceType::Ptr &requiredType, - const QUrl &queryURI, - const QXmlName &initialTemplateName); - - /** - * @returns an ASTItem tree built for the last created expression, - * via createExpression(). - */ - virtual ASTItem *astTree() const; - - /** - * @returns a list containing string representations of all available - * functions in Patternist. Each QString in the returned QStringList - * is a function synopsis for human consumption. - */ - static QStringList availableFunctionSignatures(); - - protected: - /** - * Performs the ASTItem tree building. - */ - virtual void processTreePass(const QPatternist::Expression::Ptr &tree, - const CompilationStage stage); - - void processTemplateRule(const QPatternist::Expression::Ptr &body, - const QPatternist::TemplatePattern::Ptr &pattern, - const QXmlName &mode, - const TemplateCompilationStage stage); - - void processNamedTemplate(const QXmlName &name, - const QPatternist::Expression::Ptr &body, - const TemplateCompilationStage stage); - private: - static ASTItem *buildASTTree(const QPatternist::Expression::Ptr &expr, - ASTItem *const parent, - const QPatternist::SequenceType::Ptr &reqType); - ASTItem *m_ast; - }; -} - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif -// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternsxqts/lib/ErrorHandler.cpp b/tests/auto/xmlpatternsxqts/lib/ErrorHandler.cpp deleted file mode 100644 index 3f07737..0000000 --- a/tests/auto/xmlpatternsxqts/lib/ErrorHandler.cpp +++ /dev/null @@ -1,166 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 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 -#include -#include -#include -#include -#include - -#include "ErrorHandler.h" - -using namespace QPatternistSDK; - -ErrorHandler *ErrorHandler::handler = 0; - -void qMessageHandler(QtMsgType type, const char *description) -{ - if(type == QtDebugMsg) - { - std::fprintf(stderr, "%s\n", description); - return; - } - - QtMsgType t; - - switch(type) - { - case QtWarningMsg: - { - t = QtWarningMsg; - break; - } - case QtCriticalMsg: - { - t = QtFatalMsg; - break; - } - case QtFatalMsg: - { - /* We can't swallow Q_ASSERTs, we need to fail the hard way here. - * But maybe not: when run from "patternistrunsingle" it could be an idea - * to actually try to record it(but nevertheless fail somehow) such - * that it gets reported. */ - std::fprintf(stderr, "Fatal error: %s\n", description); - t = QtFatalMsg; /* Dummy, to silence a bogus compiler warning. */ - return; - } - case QtDebugMsg: /* This enum is handled above in the if-clause. */ - /* Fallthrough. */ - default: - { - Q_ASSERT(false); - return; - } - } - - Q_ASSERT(ErrorHandler::handler); - /* This message is hacky. Ideally, we should do it the same way - * ReportContext::error() constructs messages, but this is just testing - * code. */ - ErrorHandler::handler->message(t, QLatin1String("

") + QPatternist::escape(QLatin1String(description)) + QLatin1String("

")); -} - -void ErrorHandler::installQtMessageHandler(ErrorHandler *const h) -{ - handler = h; - - if(h) - qInstallMsgHandler(qMessageHandler); - else - qInstallMsgHandler(0); -} - -void ErrorHandler::handleMessage(QtMsgType type, - const QString &description, - const QUrl &identifier, - const QSourceLocation &) -{ - /* Don't use pDebug() in this function, it results in infinite - * recursion. Talking from experience.. */ - - Message msg; - msg.setType(type); - msg.setIdentifier(identifier); - - /* Let's remove all the XHTML markup. */ - QBuffer buffer; - buffer.setData(description.toLatin1()); - buffer.open(QIODevice::ReadOnly); - - QXmlQuery query; - query.bindVariable(QLatin1String("desc"), &buffer); - query.setQuery(QLatin1String("string(doc($desc))")); - - QStringList result; - const bool success = query.evaluateTo(&result); - - if(!description.startsWith(QLatin1String("\"Test-suite harness error:"))) - { - const QString msg(QString::fromLatin1("Invalid description: %1").arg(description)); - QVERIFY2(success, qPrintable(msg)); - - if(!success) - QTextStream(stderr) << msg; - } - - - if(!result.isEmpty()) - msg.setDescription(result.first()); - - m_messages.append(msg); -} - -ErrorHandler::Message::List ErrorHandler::messages() const -{ - return m_messages; -} - -void ErrorHandler::reset() -{ - m_messages.clear(); -} - -// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternsxqts/lib/ErrorHandler.h b/tests/auto/xmlpatternsxqts/lib/ErrorHandler.h deleted file mode 100644 index 25447a9..0000000 --- a/tests/auto/xmlpatternsxqts/lib/ErrorHandler.h +++ /dev/null @@ -1,149 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 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$ -** -****************************************************************************/ - -#ifndef PatternistSDK_ErrorHandler_H -#define PatternistSDK_ErrorHandler_H - -#include "Global.h" -#include "qabstractmessagehandler.h" - - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -template class QList; - -namespace QPatternistSDK -{ - /** - * @short A MessageHandler which - * accumulates all its received ErrorHandler::Message instances - * in a list, retrievable via messages(). - * - * Thus, ErrorHandler does not report errors, but collects them - * and allows easy access to them. - * - * @ingroup PatternistSDK - * @author Frans Englich - */ - class Q_PATTERNISTSDK_EXPORT ErrorHandler : public QAbstractMessageHandler - { - public: - class Message - { - public: - typedef QList List; - - QString description() const - { - return m_description; - } - - void setDescription(const QString &desc) - { - m_description = desc; - } - - void setIdentifier(const QUrl &newId) - { - m_identifier = newId; - } - - QUrl identifier() const - { - return m_identifier; - } - - QtMsgType type() const - { - return m_type; - } - - void setType(const QtMsgType t) - { - m_type = t; - } - - private: - QUrl m_identifier; - QtMsgType m_type; - QString m_description; - }; - - /** - * Clears all accumulated errors. - */ - void reset(); - - Message::List messages() const; - - /** - * Calling this function causes all Qt's internal debug messages to be - * sent to @p handler. If @p handler is @c null, Qt's default message - * handler is re-installed. In other words, via an internal proxy function, - * it installs @p handler as Qt's message handler. - * - * If @p handler is heap allocated, it will be leaked. - * - * @see qInstallMsgHandler() - */ - static void installQtMessageHandler(ErrorHandler *const handler); - - static ErrorHandler *handler; - - protected: - virtual void handleMessage(QtMsgType type, - const QString &description, - const QUrl &identifier = QUrl(), - const QSourceLocation &sourceLocation = QSourceLocation()); - - private: - ErrorHandler::Message::List m_messages; - }; -} - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif -// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternsxqts/lib/ErrorItem.cpp b/tests/auto/xmlpatternsxqts/lib/ErrorItem.cpp deleted file mode 100644 index 57edc1f..0000000 --- a/tests/auto/xmlpatternsxqts/lib/ErrorItem.cpp +++ /dev/null @@ -1,142 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 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 - -#include "qreportcontext_p.h" -#include "qcommonnamespaces_p.h" - -#include "ErrorItem.h" - -using namespace QPatternistSDK; - -QString ErrorItem::toString(const QtMsgType type) -{ - switch(type) - { - case QtWarningMsg: - return QLatin1String("Warning"); - case QtFatalMsg: - return QLatin1String("Error"); - default: - { - Q_ASSERT(false); - return QString(); - } - } -} - -ErrorItem::ErrorItem(const ErrorHandler::Message &error, - ErrorItem *p) : m_message(error), - m_parent(p) -{ -} - -ErrorItem::~ErrorItem() -{ - qDeleteAll(m_children); -} - -int ErrorItem::columnCount() const -{ - return 3; -} - -QVariant ErrorItem::data(const Qt::ItemDataRole role, int column) const -{ - if(role != Qt::DisplayRole) - return QVariant(); - - switch(column) - { - case 0: - return toString(m_message.type()); - case 1: - { - if(!m_message.type()) /* It's a warning, likely. */ - return QString(); - - QString ns; - const QString code(QPatternist::ReportContext::codeFromURI(m_message.identifier().toString(), ns)); - - if(ns == QPatternist::CommonNamespaces::XPERR) - return code; - else /* Do the full version. */ - return m_message.type(); - } - case 2: - return m_message.description(); - default: - { - Q_ASSERT(false); - return QVariant(); - } - } -} - -TreeItem::List ErrorItem::children() const -{ - return m_children; -} - -void ErrorItem::appendChild(TreeItem *item) -{ - m_children.append(item); -} - -TreeItem *ErrorItem::child(const unsigned int rowP) const -{ - return m_children.value(rowP); -} - -unsigned int ErrorItem::childCount() const -{ - return m_children.count(); -} - -TreeItem *ErrorItem::parent() const -{ - return m_parent; -} - -// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternsxqts/lib/ErrorItem.h b/tests/auto/xmlpatternsxqts/lib/ErrorItem.h deleted file mode 100644 index 1d05872..0000000 --- a/tests/auto/xmlpatternsxqts/lib/ErrorItem.h +++ /dev/null @@ -1,94 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 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$ -** -****************************************************************************/ - -#ifndef PatternistSDK_ErrorItem_H -#define PatternistSDK_ErrorItem_H - -#include - -#include "ErrorHandler.h" -#include "Global.h" -#include "TreeItem.h" - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -namespace QPatternistSDK -{ - /** - * @short Delegates a ErrorHandler::Message through the interface - * exposed by TreeItem, such that errors from DOM related code - * can be displayed/used in Qt's model/view framework. - * - * @ingroup PatternistSDK - * @author Frans Englich - */ - class Q_PATTERNISTSDK_EXPORT ErrorItem : public TreeItem - { - public: - ErrorItem(const ErrorHandler::Message &error, ErrorItem *parent); - virtual ~ErrorItem(); - - virtual QVariant data(const Qt::ItemDataRole role, int column) const; - - virtual void appendChild(TreeItem *item); - virtual TreeItem *child(const unsigned int row) const; - virtual unsigned int childCount() const; - virtual TreeItem::List children() const; - virtual TreeItem *parent() const; - int columnCount() const; - - private: - static QString toString(const QtMsgType sev); - - const ErrorHandler::Message m_message; - ErrorItem * m_parent; - TreeItem::List m_children; - }; -} - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif -// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternsxqts/lib/ExitCode.h b/tests/auto/xmlpatternsxqts/lib/ExitCode.h deleted file mode 100644 index e1810b1..0000000 --- a/tests/auto/xmlpatternsxqts/lib/ExitCode.h +++ /dev/null @@ -1,105 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 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$ -** -****************************************************************************/ - -#ifndef PatternistSDK_ExitCode_H -#define PatternistSDK_ExitCode_H - -#include "Global.h" - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -namespace QPatternistSDK -{ - /** - * @short Houses program exit codes for PatternistSDK utilities. - * - * @ingroup PatternistSDK - * @author Frans Englich - */ - class Q_PATTERNISTSDK_EXPORT ExitCode - { - public: - /** - * Exit codes for programs part of PatternistSDK. The values for the enums are specified - * to make it easily understandable what number a symbol corresponds to. - */ - enum Code - { - Success = 0, - InvalidArgCount = 1, - InvalidArgs = 2, - - /** - * Used in @c patternistrunsuite - */ - InvalidCatalogFile = 3, - FileNotExists = 4, - OpenError = 5, - WriteError = 6, - - /** - * Used in the test program used for comparing files on the byte level. - */ - NotEqual = 7, - UnevenTestCount = 8, - InternalError = 9, - Regression = 10 - }; - - private: - /** - * This constructor is private and has no implementation, because this - * class is not supposed to be instantiated. - */ - inline ExitCode(); - - Q_DISABLE_COPY(ExitCode) - }; -} - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif -// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternsxqts/lib/ExpressionInfo.cpp b/tests/auto/xmlpatternsxqts/lib/ExpressionInfo.cpp deleted file mode 100644 index abbc8b3..0000000 --- a/tests/auto/xmlpatternsxqts/lib/ExpressionInfo.cpp +++ /dev/null @@ -1,54 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 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 "ExpressionInfo.h" - -using namespace QPatternistSDK; - -ExpressionInfo::ExpressionInfo(const QString &name, - const QString &details) : QPair(name, details) -{ -} - -// vim: et:ts=4:sw=4:sts=4 - diff --git a/tests/auto/xmlpatternsxqts/lib/ExpressionInfo.h b/tests/auto/xmlpatternsxqts/lib/ExpressionInfo.h deleted file mode 100644 index 2d9d398..0000000 --- a/tests/auto/xmlpatternsxqts/lib/ExpressionInfo.h +++ /dev/null @@ -1,80 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 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$ -** -****************************************************************************/ - -#ifndef PatternistSDK_ExpressionInfo_H -#define PatternistSDK_ExpressionInfo_H - -#include "Global.h" -#include "qexpressiondispatch_p.h" - -#include -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -namespace QPatternistSDK -{ - /** - * @short Houses debug information about an QPatternist::Expression instance. - * - * An Expression's name, typically its class name, can be retrieved - * via the member variable first, and additional data, for example its string - * value or operator, can be retrieved via the member variable second. - * - * @ingroup PatternistSDK - * @author Frans Englich - */ - class Q_PATTERNISTSDK_EXPORT ExpressionInfo : public QPatternist::ExpressionVisitorResult - , public QPair - { - public: - ExpressionInfo(const QString &name, const QString &details); - }; -} - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif -// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternsxqts/lib/ExpressionNamer.cpp b/tests/auto/xmlpatternsxqts/lib/ExpressionNamer.cpp deleted file mode 100644 index 605c754..0000000 --- a/tests/auto/xmlpatternsxqts/lib/ExpressionNamer.cpp +++ /dev/null @@ -1,316 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 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 "qabstractfloat_p.h" -#include "qandexpression_p.h" -#include "qanyuri_p.h" -#include "qapplytemplate_p.h" -#include "qargumentreference_p.h" -#include "qarithmeticexpression_p.h" -#include "qatomicstring_p.h" -#include "qatomizer_p.h" -#include "qattributeconstructor_p.h" -#include "qattributenamevalidator_p.h" -#include "qaxisstep_p.h" -#include "qbase64binary_p.h" -#include "qboolean_p.h" -#include "qcardinalityverifier_p.h" -#include "qcastableas_p.h" -#include "qcastas_p.h" -#include "qcombinenodes_p.h" -#include "qcontextitem_p.h" -#include "qdate_p.h" -#include "qdecimal_p.h" -#include "qdynamiccontextstore_p.h" -#include "qelementconstructor_p.h" -#include "qemptysequence_p.h" -#include "qevaluationcache_p.h" -#include "qexpressionsequence_p.h" -#include "qexpressionvariablereference_p.h" -#include "qfirstitempredicate_p.h" -#include "qforclause_p.h" -#include "qfunctioncall_p.h" -#include "qgday_p.h" -#include "qgeneralcomparison_p.h" -#include "qgenericpredicate_p.h" -#include "qgmonthday_p.h" -#include "qgmonth_p.h" -#include "qgyearmonth_p.h" -#include "qgyear_p.h" -#include "qhexbinary_p.h" -#include "qifthenclause_p.h" -#include "qinstanceof_p.h" -#include "qinteger_p.h" -#include "qitem_p.h" -#include "qitemverifier_p.h" -#include "qliteral_p.h" -#include "qnamespaceconstructor_p.h" -#include "qncnameconstructor_p.h" -#include "qnodecomparison_p.h" -#include "qorexpression_p.h" -#include "qpath_p.h" -#include "qpositionalvariablereference_p.h" -#include "qqnameconstructor_p.h" -#include "qqnamevalue_p.h" -#include "qquantifiedexpression_p.h" -#include "qrangeexpression_p.h" -#include "qrangevariablereference_p.h" -#include "qschemadatetime_p.h" -#include "qschematime_p.h" -#include "qsimplecontentconstructor_p.h" -#include "qtreatas_p.h" -#include "qtruthpredicate_p.h" -#include "quntypedatomicconverter_p.h" -#include "quntypedatomic_p.h" -#include "quserfunctioncallsite_p.h" -#include "qvalidationerror_p.h" -#include "qvaluecomparison_p.h" - -#include "ExpressionInfo.h" -#include "Global.h" - -#include "ExpressionNamer.h" - -using namespace QPatternistSDK; - -/* Simple ones, they have no additional data. */ -#define implClass(cls) \ -QPatternist::ExpressionVisitorResult::Ptr ExpressionNamer::visit(const QPatternist::cls *) const \ -{ \ - return QPatternist::ExpressionVisitorResult::Ptr \ - (new ExpressionInfo(QLatin1String(#cls), QString())); \ -} - -implClass(AndExpression) -implClass(ArgumentConverter) -implClass(Atomizer) -implClass(AttributeConstructor) -implClass(AttributeNameValidator) -implClass(CallTemplate) -implClass(CardinalityVerifier) -implClass(CollationChecker) -implClass(CommentConstructor) -implClass(ComputedNamespaceConstructor) -implClass(ContextItem) -implClass(CopyOf) -implClass(CurrentItemStore) -implClass(DocumentConstructor) -implClass(DynamicContextStore) -implClass(EBVExtractor) -implClass(ElementConstructor) -implClass(EmptySequence) -implClass(ExpressionSequence) -implClass(ExternalVariableReference) -implClass(FirstItemPredicate) -implClass(ForClause) -implClass(GenericPredicate) -implClass(IfThenClause) -implClass(ItemVerifier) -implClass(LetClause) -implClass(LiteralSequence) -implClass(NCNameConstructor) -implClass(NodeSortExpression) -implClass(OrderBy) -implClass(OrExpression) -implClass(ParentNodeAxis) -implClass(ProcessingInstructionConstructor) -implClass(QNameConstructor) -implClass(RangeExpression) -implClass(ReturnOrderBy) -implClass(SimpleContentConstructor) -implClass(StaticBaseURIStore) -implClass(StaticCompatibilityStore) -implClass(TemplateParameterReference) -implClass(TextNodeConstructor) -implClass(TreatAs) -implClass(TruthPredicate) -implClass(UnresolvedVariableReference) -implClass(UntypedAtomicConverter) -implClass(UserFunctionCallsite) -implClass(ValidationError) -#undef implClass - -/** Variable references. */ -#define implVarRef(name) \ -QPatternist::ExpressionVisitorResult::Ptr ExpressionNamer::visit(const QPatternist::name *i) const \ -{ \ - return QPatternist::ExpressionVisitorResult::Ptr \ - (new ExpressionInfo(QLatin1String(#name), \ - QString(QLatin1String("Slot: %1")).arg(i->slot()))); \ -} -implVarRef(RangeVariableReference) -implVarRef(ArgumentReference) -implVarRef(ExpressionVariableReference) -implVarRef(PositionalVariableReference) -#undef implVarRef - -/* Type related classes which have a targetType() function. */ -#define implTypeClass(cls) \ -QPatternist::ExpressionVisitorResult::Ptr ExpressionNamer::visit(const QPatternist::cls *i) const \ -{ \ - return QPatternist::ExpressionVisitorResult::Ptr(new ExpressionInfo(QLatin1String(#cls), \ - i->targetType()->displayName(Global::namePool()))); \ -} - -implTypeClass(InstanceOf) -implTypeClass(CastableAs) -#undef implTypeClass - -/* Type related classes which have a targetType() function. */ -QPatternist::ExpressionVisitorResult::Ptr ExpressionNamer::visit(const QPatternist::CastAs *i) const -{ - return QPatternist::ExpressionVisitorResult::Ptr(new ExpressionInfo(QLatin1String("CastAs"), - i->targetSequenceType()->displayName(Global::namePool()))); -} - -/* Classes which represent operators. */ -#define implOPClass(cls, compClass) \ -QPatternist::ExpressionVisitorResult::Ptr ExpressionNamer::visit(const QPatternist::cls *i) const \ -{ \ - return QPatternist::ExpressionVisitorResult::Ptr(new ExpressionInfo(QLatin1String(#cls), \ - QPatternist::compClass::displayName(i->operatorID()))); \ -} - -implOPClass(ArithmeticExpression, AtomicMathematician) -implOPClass(NodeComparison, NodeComparison) -implOPClass(QuantifiedExpression, QuantifiedExpression) -implOPClass(CombineNodes, CombineNodes) -#undef implOPClass - -/* Classes which represent operators. */ -#define implCompClass(cls, type) \ -QPatternist::ExpressionVisitorResult::Ptr ExpressionNamer::visit(const QPatternist::cls *i) const \ -{ \ - return QPatternist::ExpressionVisitorResult::Ptr(new ExpressionInfo(QLatin1String(#cls), \ - QPatternist::AtomicComparator::displayName(i->operatorID(), \ - QPatternist::AtomicComparator::type))); \ -} - -implCompClass(GeneralComparison, AsGeneralComparison) -implCompClass(ValueComparison, AsValueComparison) -#undef implCompClass - -QPatternist::ExpressionVisitorResult::Ptr ExpressionNamer::visit(const QPatternist::FunctionCall *i) const -{ - return QPatternist::ExpressionVisitorResult::Ptr - (new ExpressionInfo(QLatin1String("FunctionCall"), - Global::namePool()->displayName(i->signature()->name()))); -} - -QPatternist::ExpressionVisitorResult::Ptr ExpressionNamer::visit(const QPatternist::Literal *i) const -{ - return QPatternist::ExpressionVisitorResult::Ptr(new ExpressionInfo( - i->item().type()->displayName(Global::namePool()), - i->item().stringValue())); -} - -QPatternist::ExpressionVisitorResult::Ptr ExpressionNamer::visit(const QPatternist::AxisStep *i) const -{ - return QPatternist::ExpressionVisitorResult::Ptr(new ExpressionInfo(QLatin1String("AxisStep"), - QPatternist::AxisStep::axisName(i->axis()) + - QLatin1String("::") + - i->nodeTest()->displayName(Global::namePool()))); - -} - - -QPatternist::ExpressionVisitorResult::Ptr ExpressionNamer::visit(const QPatternist::EvaluationCache *i) const -{ - return QPatternist::ExpressionVisitorResult::Ptr(new ExpressionInfo(QLatin1String("EvaluationCache"), - QLatin1String("Slot: ") + QString::number(i->slot()))); - -} - -QPatternist::ExpressionVisitorResult::Ptr ExpressionNamer::visit(const QPatternist::EvaluationCache *i) const -{ - return QPatternist::ExpressionVisitorResult::Ptr(new ExpressionInfo(QLatin1String("EvaluationCache"), - QLatin1String("Slot: ") + QString::number(i->slot()))); - -} - -QPatternist::ExpressionVisitorResult::Ptr ExpressionNamer::visit(const QPatternist::NamespaceConstructor *i) const -{ - return QPatternist::ExpressionVisitorResult::Ptr(new ExpressionInfo(QLatin1String("NamespaceConstructor"), - Global::namePool()->stringForPrefix(i->namespaceBinding().prefix()) + - QLatin1Char('=') + - Global::namePool()->stringForNamespace(i->namespaceBinding().namespaceURI()))); - -} - -QPatternist::ExpressionVisitorResult::Ptr ExpressionNamer::visit(const QPatternist::Path *path) const -{ - - QPatternist::Path::Kind k = path->kind(); - QString type; - - switch(k) - { - case QPatternist::Path::XSLTForEach: - { - type = QLatin1String("XSLTForEach"); - break; - } - case QPatternist::Path::RegularPath: - { - type = QLatin1String("RegularPath"); - break; - } - case QPatternist::Path::ForApplyTemplate: - { - type = QLatin1String("ForApplyTemplate"); - break; - } - } - - return QPatternist::ExpressionVisitorResult::Ptr(new ExpressionInfo(QLatin1String("Path"), type)); -} - -QPatternist::ExpressionVisitorResult::Ptr ExpressionNamer::visit(const QPatternist::ApplyTemplate *path) const -{ - const QPatternist::TemplateMode::Ptr mode(path->mode()); - return QPatternist::ExpressionVisitorResult::Ptr - (new ExpressionInfo(QLatin1String("ApplyTemplate"), mode ? Global::namePool()->displayName(mode->name()) : QString::fromLatin1("#current"))); -} - -// vim: et:ts=4:sw=4:sts=4 - diff --git a/tests/auto/xmlpatternsxqts/lib/ExpressionNamer.h b/tests/auto/xmlpatternsxqts/lib/ExpressionNamer.h deleted file mode 100644 index 129d8d7..0000000 --- a/tests/auto/xmlpatternsxqts/lib/ExpressionNamer.h +++ /dev/null @@ -1,281 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 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$ -** -****************************************************************************/ - -#ifndef PatternistSDK_ExpressionNamer_H -#define PatternistSDK_ExpressionNamer_H - -#include "Global.h" -#include "qexpressiondispatch_p.h" - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -namespace QPatternistSDK -{ - /** - * @short Extracts debug information from a QPatternist::Expression tree. - * - * This data is the name of the AST node(typically the class name), - * and additional data such as the value, type of operator, and so forth. The result - * is returned(from visit()), is an ExpressionInfo instance. - * - * @see ExpressionInfo - * @see ASTItem - * @ingroup PatternistSDK - * @author Frans Englich - */ - class Q_PATTERNISTSDK_EXPORT ExpressionNamer : public QPatternist::ExpressionVisitor - { - public: - - virtual QPatternist::ExpressionVisitorResult::Ptr - visit(const QPatternist::AndExpression *) const; - - virtual QPatternist::ExpressionVisitorResult::Ptr - visit(const QPatternist::ApplyTemplate *) const; - - virtual QPatternist::ExpressionVisitorResult::Ptr - visit(const QPatternist::ArgumentReference *) const; - - virtual QPatternist::ExpressionVisitorResult::Ptr - visit(const QPatternist::ArithmeticExpression *) const; - - virtual QPatternist::ExpressionVisitorResult::Ptr - visit(const QPatternist::Atomizer *) const; - - virtual QPatternist::ExpressionVisitorResult::Ptr - visit(const QPatternist::AttributeConstructor *) const; - - virtual QPatternist::ExpressionVisitorResult::Ptr - visit(const QPatternist::AttributeNameValidator *) const; - - virtual QPatternist::ExpressionVisitorResult::Ptr - visit(const QPatternist::CallTemplate *) const; - - virtual QPatternist::ExpressionVisitorResult::Ptr - visit(const QPatternist::CardinalityVerifier *) const; - - virtual QPatternist::ExpressionVisitorResult::Ptr - visit(const QPatternist::CastAs *) const; - - virtual QPatternist::ExpressionVisitorResult::Ptr - visit(const QPatternist::CastableAs *) const; - - virtual QPatternist::ExpressionVisitorResult::Ptr - visit(const QPatternist::CollationChecker *) const; - - virtual QPatternist::ExpressionVisitorResult::Ptr - visit(const QPatternist::CombineNodes *) const; - - virtual QPatternist::ExpressionVisitorResult::Ptr - visit(const QPatternist::ComputedNamespaceConstructor *) const; - - virtual QPatternist::ExpressionVisitorResult::Ptr - visit(const QPatternist::CommentConstructor *) const; - - virtual QPatternist::ExpressionVisitorResult::Ptr - visit(const QPatternist::ContextItem *) const; - - virtual QPatternist::ExpressionVisitorResult::Ptr - visit(const QPatternist::CopyOf *) const; - - virtual QPatternist::ExpressionVisitorResult::Ptr - visit(const QPatternist::CurrentItemStore *) const; - - virtual QPatternist::ExpressionVisitorResult::Ptr - visit(const QPatternist::DocumentConstructor *) const; - - virtual QPatternist::ExpressionVisitorResult::Ptr - visit(const QPatternist::DynamicContextStore *) const; - - virtual QPatternist::ExpressionVisitorResult::Ptr - visit(const QPatternist::EBVExtractor *) const; - - virtual QPatternist::ExpressionVisitorResult::Ptr - visit(const QPatternist::ElementConstructor *) const; - - virtual QPatternist::ExpressionVisitorResult::Ptr - visit(const QPatternist::EmptySequence *) const; - - virtual QPatternist::ExpressionVisitorResult::Ptr - visit(const QPatternist::ExpressionSequence *) const; - - virtual QPatternist::ExpressionVisitorResult::Ptr - visit(const QPatternist::ExpressionVariableReference *) const; - - virtual QPatternist::ExpressionVisitorResult::Ptr - visit(const QPatternist::ExternalVariableReference *) const; - - virtual QPatternist::ExpressionVisitorResult::Ptr - visit(const QPatternist::EvaluationCache *) const; - - virtual QPatternist::ExpressionVisitorResult::Ptr - visit(const QPatternist::EvaluationCache *) const; - - virtual QPatternist::ExpressionVisitorResult::Ptr - visit(const QPatternist::FirstItemPredicate *) const; - - virtual QPatternist::ExpressionVisitorResult::Ptr - visit(const QPatternist::ForClause *) const; - - virtual QPatternist::ExpressionVisitorResult::Ptr - visit(const QPatternist::FunctionCall *) const; - - virtual QPatternist::ExpressionVisitorResult::Ptr - visit(const QPatternist::GeneralComparison *) const; - - virtual QPatternist::ExpressionVisitorResult::Ptr - visit(const QPatternist::GenericPredicate *) const; - - virtual QPatternist::ExpressionVisitorResult::Ptr - visit(const QPatternist::IfThenClause *) const; - - virtual QPatternist::ExpressionVisitorResult::Ptr - visit(const QPatternist::InstanceOf *) const; - - virtual QPatternist::ExpressionVisitorResult::Ptr - visit(const QPatternist::ItemVerifier *) const; - - virtual QPatternist::ExpressionVisitorResult::Ptr - visit(const QPatternist::LetClause *) const; - - virtual QPatternist::ExpressionVisitorResult::Ptr - visit(const QPatternist::Literal *) const; - - virtual QPatternist::ExpressionVisitorResult::Ptr - visit(const QPatternist::LiteralSequence *) const; - - virtual QPatternist::ExpressionVisitorResult::Ptr - visit(const QPatternist::NCNameConstructor *) const; - - virtual QPatternist::ExpressionVisitorResult::Ptr - visit(const QPatternist::NodeComparison *) const; - - virtual QPatternist::ExpressionVisitorResult::Ptr - visit(const QPatternist::NodeSortExpression *) const; - - virtual QPatternist::ExpressionVisitorResult::Ptr - visit(const QPatternist::OrderBy *) const; - - virtual QPatternist::ExpressionVisitorResult::Ptr - visit(const QPatternist::OrExpression *) const; - - virtual QPatternist::ExpressionVisitorResult::Ptr - visit(const QPatternist::ParentNodeAxis *) const; - - virtual QPatternist::ExpressionVisitorResult::Ptr - visit(const QPatternist::Path *) const; - - virtual QPatternist::ExpressionVisitorResult::Ptr - visit(const QPatternist::PositionalVariableReference *) const; - - virtual QPatternist::ExpressionVisitorResult::Ptr - visit(const QPatternist::ProcessingInstructionConstructor *) const; - - virtual QPatternist::ExpressionVisitorResult::Ptr - visit(const QPatternist::QNameConstructor *) const; - - virtual QPatternist::ExpressionVisitorResult::Ptr - visit(const QPatternist::QuantifiedExpression *) const; - - virtual QPatternist::ExpressionVisitorResult::Ptr - visit(const QPatternist::RangeExpression *) const; - - virtual QPatternist::ExpressionVisitorResult::Ptr - visit(const QPatternist::RangeVariableReference *) const; - - virtual QPatternist::ExpressionVisitorResult::Ptr - visit(const QPatternist::ReturnOrderBy *) const; - - virtual QPatternist::ExpressionVisitorResult::Ptr - visit(const QPatternist::SimpleContentConstructor *) const; - - virtual QPatternist::ExpressionVisitorResult::Ptr - visit(const QPatternist::StaticBaseURIStore *) const; - - virtual QPatternist::ExpressionVisitorResult::Ptr - visit(const QPatternist::StaticCompatibilityStore *) const; - - virtual QPatternist::ExpressionVisitorResult::Ptr - visit(const QPatternist::AxisStep *) const; - - virtual QPatternist::ExpressionVisitorResult::Ptr - visit(const QPatternist::TemplateParameterReference *) const; - - virtual QPatternist::ExpressionVisitorResult::Ptr - visit(const QPatternist::TextNodeConstructor *) const; - - virtual QPatternist::ExpressionVisitorResult::Ptr - visit(const QPatternist::TreatAs *) const; - - virtual QPatternist::ExpressionVisitorResult::Ptr - visit(const QPatternist::TruthPredicate *) const; - - virtual QPatternist::ExpressionVisitorResult::Ptr - visit(const QPatternist::UntypedAtomicConverter *) const; - - virtual QPatternist::ExpressionVisitorResult::Ptr - visit(const QPatternist::UnresolvedVariableReference *) const; - - virtual QPatternist::ExpressionVisitorResult::Ptr - visit(const QPatternist::ArgumentConverter *) const; - - virtual QPatternist::ExpressionVisitorResult::Ptr - visit(const QPatternist::UserFunctionCallsite *) const; - - virtual QPatternist::ExpressionVisitorResult::Ptr - visit(const QPatternist::ValidationError *) const; - - virtual QPatternist::ExpressionVisitorResult::Ptr - visit(const QPatternist::ValueComparison *) const; - - virtual QPatternist::ExpressionVisitorResult::Ptr - visit(const QPatternist::NamespaceConstructor *) const; - }; -} - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif -// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternsxqts/lib/ExternalSourceLoader.cpp b/tests/auto/xmlpatternsxqts/lib/ExternalSourceLoader.cpp deleted file mode 100644 index a83a100..0000000 --- a/tests/auto/xmlpatternsxqts/lib/ExternalSourceLoader.cpp +++ /dev/null @@ -1,140 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 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 -#include -#include - -#include "Global.h" - -#include "qcommonsequencetypes_p.h" -#include "qdebug_p.h" -#include "qatomicstring_p.h" - -#include "ExternalSourceLoader.h" - -using namespace QPatternistSDK; -using namespace QPatternist; - -ExternalSourceLoader::ExternalSourceLoader(const VariableMap &varMap, - const QPatternist::ResourceLoader::Ptr &r) : m_variableMap(varMap) - , m_resourceLoader(r) - , m_query(Global::namePoolAsPublic()) -{ - Q_ASSERT(m_resourceLoader); -} - -QPatternist::SequenceType::Ptr -ExternalSourceLoader::announceExternalVariable(const QXmlName name, - const QPatternist::SequenceType::Ptr &declaredType) -{ - pDebug() << "ExternalSourceLoader::announceExternalVariable()"; - Q_ASSERT(!name.isNull()); - Q_ASSERT(declaredType); - Q_UNUSED(declaredType); /* Needed when bulding in release mode. */ - - if(name.namespaceURI() == QPatternist::StandardNamespaces::empty) - { - const VariableValue variable(m_variableMap.value(Global::namePool()->stringForLocalName(name.localName()))); - - if(variable.first.isEmpty()) - return QPatternist::SequenceType::Ptr(); - else - { - /* If announceDocument() can't load a document for uriForVar, it will return - * null, which we will too, which is fine, since we can't supply a value for - * this variable then. */ - if(variable.second == Document) - return m_resourceLoader->announceDocument(variable.first, QPatternist::ResourceLoader::WillUse); - else if(variable.second == URI) - { - return QPatternist::CommonSequenceTypes::ExactlyOneString; - } - else - { - /* The type is Query, and we don't pre-load - * them. No particular reason, just not worth it. */ - return QPatternist::CommonSequenceTypes::ZeroOrMoreItems; - } - } - } - else - return QPatternist::SequenceType::Ptr(); -} - -QPatternist::Item -ExternalSourceLoader::evaluateSingleton(const QXmlName name, - const QPatternist::DynamicContext::Ptr &context) -{ - Q_ASSERT(!name.isNull()); - const VariableValue variable(m_variableMap.value(Global::namePool()->stringForLocalName(name.localName()))); - - if(variable.second == Document) - { - Q_ASSERT_X(QFile::exists(variable.first.toLocalFile()), Q_FUNC_INFO, - qPrintable(QString::fromLatin1("The file %1 doesn't exist").arg(variable.first.toLocalFile()))); - Q_ASSERT_X(m_resourceLoader->openDocument(variable.first, context), Q_FUNC_INFO, - "We're supposed to have the value. If not, an error should have been issued at query compile time."); - - return m_resourceLoader->openDocument(variable.first, context); - } - else if(variable.second == Query) - { - /* Well, here we open the file and execute it. */ - m_query.setQuery(QUrl::fromLocalFile(variable.first.toLocalFile())); - Q_ASSERT(m_query.isValid()); - - QXmlResultItems result; - m_query.evaluateTo(&result); - - return QPatternist::Item::fromPublic(result.next()); - } - else - { - Q_ASSERT(variable.second == URI); - return QPatternist::AtomicString::fromValue(variable.first.toString()); - } -} - -// vim: et:ts=4:sw=4:sts=4 - diff --git a/tests/auto/xmlpatternsxqts/lib/ExternalSourceLoader.h b/tests/auto/xmlpatternsxqts/lib/ExternalSourceLoader.h deleted file mode 100644 index 2d88222..0000000 --- a/tests/auto/xmlpatternsxqts/lib/ExternalSourceLoader.h +++ /dev/null @@ -1,137 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 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$ -** -****************************************************************************/ - -#ifndef PatternistSDK_ExternalSourceLoader_H -#define PatternistSDK_ExternalSourceLoader_H - -#include -#include -#include - -#include "qdynamiccontext_p.h" -#include "qresourceloader_p.h" -#include "qexternalvariableloader_p.h" - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -namespace QPatternistSDK -{ - /** - * @short Handles external variables in XQTS queries, such as $input-context, - * by loading appropriate XML source files. - * - * @ingroup PatternistSDK - * @author Frans Englich - */ - class Q_PATTERNISTSDK_EXPORT ExternalSourceLoader : public QPatternist::ExternalVariableLoader - { - public: - enum TargetOfURI - { - /** - * Identifies @c input-file. - */ - Document, - - /** - * Identifies @c input-URI. - */ - URI, - - /** - * Identifies @c input-query. - */ - Query - }; - - /** - * The first is the complete, absolute, final URI to the file to be loaded, - * and the second is the type of source found at that URI. - */ - typedef QPair VariableValue; - - /** - * In the XQTSCatalog.xml each source file in each test is referred to - * by a key, which can be fully looked up in the @c sources element. This QHash - * maps the keys to absolute URIs pointing to the source file. - */ - typedef QHash SourceMap; - - /** - * The first value is the variable name, and the second is the URI identifying - * the XML source file that's supposed to be loaded as a document. - * - * This is one for every test case, except for @c rdb-queries-results-q5, - * @c rdb-queries-results-q17 and @c rdb-queries-results-q18(at least in XQTS 1.0). - */ - typedef QHash VariableMap; - - ExternalSourceLoader(const VariableMap &varMap, - const QPatternist::ResourceLoader::Ptr &resourceLoader); - - virtual QPatternist::SequenceType::Ptr - announceExternalVariable(const QXmlName name, - const QPatternist::SequenceType::Ptr &declaredType); - - virtual QPatternist::Item - evaluateSingleton(const QXmlName name, - const QPatternist::DynamicContext::Ptr &context); - - VariableMap variableMap() const - { - return m_variableMap; - } - - private: - const VariableMap m_variableMap; - const QPatternist::ResourceLoader::Ptr m_resourceLoader; - QXmlQuery m_query; - }; -} - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif -// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternsxqts/lib/Global.cpp b/tests/auto/xmlpatternsxqts/lib/Global.cpp deleted file mode 100644 index f78e421..0000000 --- a/tests/auto/xmlpatternsxqts/lib/Global.cpp +++ /dev/null @@ -1,83 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 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 "Global.h" - -using namespace QPatternistSDK; - -const QString Global::xqtsCatalogNS (QLatin1String("http://www.w3.org/2005/02/query-test-XQTSCatalog")); -const QString Global::xqtsResultNS (QLatin1String("http://www.w3.org/2005/02/query-test-XQTSResult")); -const QString Global::xsltsCatalogNS (QLatin1String("http://www.w3.org/2005/05/xslt20-test-catalog")); -const QString Global::organizationName (QLatin1String("Patternist Team")); -const qint16 Global::versionNumber (0x01); - -static QXmlNamePool s_namePool; - -QPatternist::NamePool::Ptr Global::namePool() -{ - return s_namePool.d; -} - -QXmlNamePool Global::namePoolAsPublic() -{ - return s_namePool; -} - -bool Global::readBoolean(const QString &value) -{ - const QString normd(value.simplified()); - - if(normd == QLatin1String("true") || - normd == QLatin1String("1")) - return true; - else if(normd.isEmpty() || - normd == QLatin1String("false") || - normd == QLatin1String("0")) - return false; - - Q_ASSERT_X(false, Q_FUNC_INFO, - "The lexical representation of xs:boolean was invalid"); - return false; -} - -// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternsxqts/lib/Global.h b/tests/auto/xmlpatternsxqts/lib/Global.h deleted file mode 100644 index 53c32cb..0000000 --- a/tests/auto/xmlpatternsxqts/lib/Global.h +++ /dev/null @@ -1,128 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 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$ -** -****************************************************************************/ - -#ifndef PatternistSDK_Global_H -#define PatternistSDK_Global_H - -#include - -#include "private/qitem_p.h" -#include "private/qnamepool_p.h" - -#if defined(Q_WS_WIN) || defined(Q_OS_SYMBIAN) -# ifdef Q_PATTERNISTSDK_BUILDING - #define Q_PATTERNISTSDK_EXPORT __declspec(dllexport) - #else - #define Q_PATTERNISTSDK_EXPORT __declspec(dllimport) - #endif -#else - #define Q_PATTERNISTSDK_EXPORT -#endif - -/** - * @short Contains testing utilities for Patternist, interfacing W3C's XQuery Test Suite. - * - * @see
XML Query Test Suite - * @author Frans Englich - */ -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -namespace QPatternistSDK -{ - /** - * @short Contains global constants. - * - * @ingroup PatternistSDK - * @author Frans Englich - */ - class Q_PATTERNISTSDK_EXPORT Global - { - public: - - /** - * The namespace which the XQTS test case catalog(specified by Catalog.xsd) - * is in. The namespace is: http://www.w3.org/2005/02/query-test-XQTSCatalog - */ - static const QString xqtsCatalogNS; - - /** - * The namespace which the XQTS test results collection(specified by XQTSResult.xsd) - * is in. The namespace is: http://www.w3.org/2005/02/query-test-XQTSResult - */ - static const QString xqtsResultNS; - - /** - * The organization which created PatternistSDK. It say something - * in the direction of "Patternist Team", and is used for QSettings and the like. - */ - static const QString organizationName; - - /** - * The namespace which W3C's XSL-T test suite resides in. - */ - static const QString xsltsCatalogNS; - - /** - * The version of PatternistSDK. The value has currently no other - * meaning than that larger means older. This version information is supplied to - * QMainWindow::restoreState() and QMainWindow::saveState(). - */ - static const qint16 versionNumber; - - /** - * Parses the lexical space of @c xs:boolean, - * with the exception that the empty string is considered @c false. - */ - static bool readBoolean(const QString &lexicalSpace); - - static QPatternist::NamePool::Ptr namePool(); - static QXmlNamePool namePoolAsPublic(); - }; -} - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif -// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternsxqts/lib/ResultThreader.cpp b/tests/auto/xmlpatternsxqts/lib/ResultThreader.cpp deleted file mode 100644 index 3296854..0000000 --- a/tests/auto/xmlpatternsxqts/lib/ResultThreader.cpp +++ /dev/null @@ -1,76 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 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 "ResultThreader.h" - -using namespace QPatternistSDK; - -ResultThreader::ResultThreader(QEventLoop &ev, - QFile *file, - const Type t, - QObject *p) : QThread(p) - , m_file(file) - , m_type(t) - , m_eventLoop(ev) -{ - Q_ASSERT_X(p, Q_FUNC_INFO, "Should have a parent"); - Q_ASSERT_X(file, Q_FUNC_INFO, "Should have a valid file"); - Q_ASSERT(m_type == Baseline || m_type == Result); -} - -void ResultThreader::run() -{ - QXmlSimpleReader reader; - reader.setContentHandler(this); - - QXmlInputSource source(m_file); - reader.parse(source); - m_file->close(); -} - -ResultThreader::Type ResultThreader::type() const -{ - return m_type; -} - -// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternsxqts/lib/ResultThreader.h b/tests/auto/xmlpatternsxqts/lib/ResultThreader.h deleted file mode 100644 index 19749f0..0000000 --- a/tests/auto/xmlpatternsxqts/lib/ResultThreader.h +++ /dev/null @@ -1,110 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 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$ -** -****************************************************************************/ - -#ifndef PatternistSDK_ResultThreader_H -#define PatternistSDK_ResultThreader_H - -#include -#include -#include - -#include "TestResultHandler.h" - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -class QEventLoop; - -namespace QPatternistSDK -{ - /** - * @short Reads XML in the @c XQTSResult.xsd format, as a thread, allowing - * multiple parses to be done simultaneously. - * - * @author Frans Englich - * @ingroup PatternistSDK - */ - class Q_PATTERNISTSDK_EXPORT ResultThreader : public QThread - , public TestResultHandler - { - public: - enum Type - { - Baseline = 1, - Result - }; - - /** - * Creates a ResultThreader that will read @p file when run() is called. - */ - ResultThreader(QEventLoop &ev, - QFile *file, - const Type type, - QObject *parent); - - /** - * Parses the file passed in this class's constructor with this ResultHandlerTH::Item::LisT - * as the QXmlContentHandler, and returns. - */ - virtual void run(); - - /** - * @note Do not reimplement this function. - * @returns whether this ResultThreader handles the baseline or the result. - */ - Type type() const; - - private: - Q_DISABLE_COPY(ResultThreader) - - QFile *const m_file; - const Type m_type; - QEventLoop & m_eventLoop; - }; -} - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif -// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternsxqts/lib/TestBaseLine.cpp b/tests/auto/xmlpatternsxqts/lib/TestBaseLine.cpp deleted file mode 100644 index 6a46bcc..0000000 --- a/tests/auto/xmlpatternsxqts/lib/TestBaseLine.cpp +++ /dev/null @@ -1,511 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 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 -#include -#include -#include -#include -#include - -#include "qdebug_p.h" -#include "XMLWriter.h" - -#include "TestBaseLine.h" - -using namespace QPatternistSDK; -using namespace QPatternist; - -Q_GLOBAL_STATIC_WITH_ARGS(QRegExp, errorRegExp, (QLatin1String("[A-Z]{4}[0-9]{4}"))) - -TestBaseLine::TestBaseLine(const Type t) : m_type(t) -{ - Q_ASSERT(errorRegExp()->isValid()); -} - -TestResult::Status TestBaseLine::scan(const QString &serialized, - const TestBaseLine::List &lines) -{ - Q_ASSERT_X(lines.count() >= 1, Q_FUNC_INFO, - "At least one base line must be passed, otherwise there's nothing " - "to compare to."); - - const TestBaseLine::List::const_iterator end(lines.constEnd()); - TestBaseLine::List::const_iterator it(lines.constBegin()); - for(; it != end; ++it) - { - const TestResult::Status retval((*it)->verify(serialized)); - - if(retval == TestResult::Pass || retval == TestResult::NotTested) - return retval; - } - - return TestResult::Fail; -} - -TestResult::Status TestBaseLine::scanErrors(const ErrorHandler::Message::List &errors, - const TestBaseLine::List &lines) -{ - pDebug() << "TestBaseLine::scanErrors()"; - - /* 1. Find the first error in @p errors that's a Patternist - * error(not warning and not from Qt) and extract the error code. */ - QString errorCode; - - const ErrorHandler::Message::List::const_iterator end(errors.constEnd()); - ErrorHandler::Message::List::const_iterator it(errors.constBegin()); - for(; it != end; ++it) - { - if((*it).type() != QtFatalMsg) - continue; - - errorCode = QUrl((*it).identifier()).fragment(); - - pDebug() << "ERR:" << (*it).description(); - /* This is hackish. We have no way of determining whether a Message - * is actually issued from Patternist, so we try to narrow it down like this. */ - if(errorRegExp()->exactMatch(errorCode)) - break; /* It's an error code. */ - else - errorCode.clear(); - } - - pDebug() << "Got error code: " << errorCode; - /* 2. Loop through @p lines, and for the first base line - * which is of type ExpectedError and which matches @p errorCode - * return Pass, otherwise Fail. */ - const TestBaseLine::List::const_iterator blend(lines.constEnd()); - TestBaseLine::List::const_iterator blit(lines.constBegin()); - for(; blit != blend; ++blit) - { - const Type t = (*blit)->type(); - - if(t == TestBaseLine::ExpectedError) - { - const QString d((*blit)->details()); - if(d == errorCode || d == QChar::fromLatin1('*')) - return TestResult::Pass; - } - } - - return TestResult::Fail; -} - -void TestBaseLine::toXML(XMLWriter &receiver) const -{ - switch(m_type) - { - case XML: /* Fallthrough. */ - case Fragment: /* Fallthrough. */ - case SchemaIsValid: /* Fallthrough. */ - case Text: - { - QXmlAttributes inspectAtts; - inspectAtts.append(QLatin1String("role"), QString(), - QLatin1String("role"), QLatin1String("principal")); - inspectAtts.append(QLatin1String("compare"), QString(), - QLatin1String("compare"), displayName(m_type)); - receiver.startElement(QLatin1String("output-file"), inspectAtts); - receiver.characters(m_details); - receiver.endElement(QLatin1String("output-file")); - return; - } - case Ignore: - { - Q_ASSERT_X(false, Q_FUNC_INFO, "Serializing 'Ignore' is not implemented."); - return; - } - case Inspect: - { - QXmlAttributes inspectAtts; - inspectAtts.append(QLatin1String("role"), QString(), - QLatin1String("role"), QLatin1String("principal")); - inspectAtts.append(QLatin1String("compare"), QString(), - QLatin1String("compare"), QLatin1String("Inspect")); - receiver.startElement(QLatin1String("output-file"), inspectAtts); - receiver.characters(m_details); - receiver.endElement(QLatin1String("output-file")); - return; - } - case ExpectedError: - { - receiver.startElement(QLatin1String("expected-error")); - receiver.characters(m_details); - receiver.endElement(QLatin1String("expected-error")); - return; - } - } -} - -bool TestBaseLine::isChildrenDeepEqual(const QDomNodeList &cl1, const QDomNodeList &cl2) -{ - const unsigned int len = cl1.length(); - - if(len == cl2.length()) - { - for(unsigned int i = 0; i < len; ++i) - { - if(!isDeepEqual(cl1.at(i), cl2.at(i))) - return false; - } - - return true; - } - else - return false; -} - -bool TestBaseLine::isAttributesEqual(const QDomNamedNodeMap &cl1, const QDomNamedNodeMap &cl2) -{ - const unsigned int len = cl1.length(); - pDebug() << "LEN:" << len; - - if(len == cl2.length()) - { - for(unsigned int i1 = 0; i1 < len; ++i1) - { - const QDomNode attr1(cl1.item(i1)); - Q_ASSERT(!attr1.isNull()); - - /* This is set if attr1 cannot be found at all in cl2. */ - bool earlyExit = false; - - for(unsigned int i2 = 0; i2 < len; ++i2) - { - const QDomNode attr2(cl2.item(i2)); - Q_ASSERT(!attr2.isNull()); - pDebug() << "ATTR1:" << attr1.localName() << attr1.namespaceURI() << attr1.prefix() << attr1.nodeName(); - pDebug() << "ATTR2:" << attr2.localName() << attr2.namespaceURI() << attr2.prefix() << attr2.nodeName(); - - if(attr1.localName() == attr2.localName() && - attr1.namespaceURI() == attr2.namespaceURI() && - attr1.prefix() == attr2.prefix() && - attr1.nodeName() == attr2.nodeName() && /* Yes, needed in addition to all the other. */ - attr1.nodeValue() == attr2.nodeValue()) - { - earlyExit = true; - break; - } - } - - if(!earlyExit) - { - /* An attribute was found that doesn't exist in the other list so exit. */ - return false; - } - } - - return true; - } - else - return false; -} - -bool TestBaseLine::isDeepEqual(const QDomNode &n1, const QDomNode &n2) -{ - if(n1.nodeType() != n2.nodeType()) - return false; - - switch(n1.nodeType()) - { - case QDomNode::CommentNode: - /* Fallthrough. */ - case QDomNode::TextNode: - { - return static_cast(n1).data() == - static_cast(n2).data(); - } - case QDomNode::ProcessingInstructionNode: - { - return n1.nodeName() == n2.nodeName() && - n1.nodeValue() == n2.nodeValue(); - } - case QDomNode::DocumentNode: - return isChildrenDeepEqual(n1.childNodes(), n2.childNodes()); - case QDomNode::ElementNode: - { - return n1.localName() == n2.localName() && - n1.namespaceURI() == n2.namespaceURI() && - n1.nodeName() == n2.nodeName() && /* Yes, this one is needed in addition to localName(). */ - isAttributesEqual(n1.attributes(), n2.attributes()) && - isChildrenDeepEqual(n1.childNodes(), n2.childNodes()); - } - /* Fallthrough all these. */ - case QDomNode::EntityReferenceNode: - case QDomNode::CDATASectionNode: - case QDomNode::EntityNode: - case QDomNode::DocumentTypeNode: - case QDomNode::DocumentFragmentNode: - case QDomNode::NotationNode: - case QDomNode::BaseNode: - case QDomNode::CharacterDataNode: - { - Q_ASSERT_X(false, Q_FUNC_INFO, - "An unsupported node type was encountered."); - return false; - } - case QDomNode::AttributeNode: - { - Q_ASSERT_X(false, Q_FUNC_INFO, - "This should never happen. QDom doesn't allow us to compare DOM attributes " - "properly."); - return false; - } - default: - { - Q_ASSERT_X(false, Q_FUNC_INFO, "Unhandled QDom::NodeType value."); - return false; - } - } -} - -TestResult::Status TestBaseLine::verify(const QString &serializedInput) const -{ - switch(m_type) - { - case SchemaIsValid: - /* Fall through. */ - case Text: - { - if(serializedInput == details()) - return TestResult::Pass; - else - return TestResult::Fail; - } - case Fragment: - /* Fall through. */ - case XML: - { - /* Read the baseline and the serialized input into two QDomDocuments, and compare - * them deeply. We wrap fragments in a root node such that it is well-formed XML. - */ - - QDomDocument output; - { - /* The reason we put things into a QByteArray and then parse it through QXmlSimpleReader, is that - * QDomDocument does whitespace stripping when calling setContent(QString). In other words, - * this workarounds a bug. */ - - QXmlInputSource source; - source.setData((m_type == XML ? serializedInput : QLatin1String("") + - serializedInput + - QLatin1String("")).toUtf8()); - - QString outputReadingError; - - QXmlSimpleReader reader; - reader.setFeature(QLatin1String("http://xml.org/sax/features/namespace-prefixes"), true); - - const bool success = output.setContent(&source, - &reader, - &outputReadingError); - - if(!success) - return TestResult::Fail; - - Q_ASSERT(success); - } - - QDomDocument baseline; - { - QXmlInputSource source; - source.setData((m_type == XML ? details() : QLatin1String("") + - details() + - QLatin1String("")).toUtf8()); - QString baselineReadingError; - - QXmlSimpleReader reader; - reader.setFeature(QLatin1String("http://xml.org/sax/features/namespace-prefixes"), true); - - const bool success = baseline.setContent(&source, - &reader, - &baselineReadingError); - - if(!success) - return TestResult::Fail; - - /* This piece of code workaround a bug in QDom, which treats XML prologs as processing - * instructions and make them available in the tree as so. */ - if(m_type == XML) - { - /* $doc/r/node() */ - const QDomNodeList children(baseline.childNodes()); - const int len = children.length(); - - for(int i = 0; i < len; ++i) - { - const QDomNode &child = children.at(i); - if(child.isProcessingInstruction() && child.nodeName() == QLatin1String("xml")) - { - baseline.removeChild(child); - break; - } - } - } - - Q_ASSERT_X(baselineReadingError.isNull(), Q_FUNC_INFO, - qPrintable((QLatin1String("Reading the baseline failed: ") + baselineReadingError))); - } - - if(isDeepEqual(output, baseline)) - return TestResult::Pass; - else - { - pDebug() << "FAILURE:" << output.toString() << "is NOT IDENTICAL to(baseline):" << baseline.toString(); - return TestResult::Fail; - } - } - case Ignore: - return TestResult::Pass; - case Inspect: - return TestResult::NotTested; - case ExpectedError: - { - /* This function is only called for Text/XML/Fragment tests. */ - return TestResult::Fail; - } - } - Q_ASSERT(false); - return TestResult::Fail; -} - -TestBaseLine::Type TestBaseLine::identifierFromString(const QString &string) -{ - /* "html-output: Using an ad hoc tool, it must assert that the document obeys the HTML - * Output Method as defined in the Serialization specification and section - * 20 of the XSLT 2.0 specification." We treat it as XML for now, same with - * xhtml-output. */ - if(string.compare(QLatin1String("XML"), Qt::CaseInsensitive) == 0 || - string == QLatin1String("html-output") || - string == QLatin1String("xml-output") || - string == QLatin1String("xhtml-output")) - return XML; - else if(string == QLatin1String("Fragment") || string == QLatin1String("xml-frag")) - return Fragment; - else if(string.compare(QLatin1String("Text"), Qt::CaseInsensitive) == 0) - return Text; - else if(string == QLatin1String("Ignore")) - return Ignore; - else if(string.compare(QLatin1String("Inspect"), Qt::CaseInsensitive) == 0) - return Inspect; - else - { - Q_ASSERT_X(false, Q_FUNC_INFO, - qPrintable(QString::fromLatin1("Invalid string representation for a comparation type: %1").arg(string))); - - return Ignore; /* Silence GCC. */ - } -} - -QString TestBaseLine::displayName(const Type id) -{ - switch(id) - { - case XML: - return QLatin1String("XML"); - case Fragment: - return QLatin1String("Fragment"); - case Text: - return QLatin1String("Text"); - case Ignore: - return QLatin1String("Ignore"); - case Inspect: - return QLatin1String("Inspect"); - case ExpectedError: - return QLatin1String("ExpectedError"); - case SchemaIsValid: - return QLatin1String("SchemaIsValid"); - } - - Q_ASSERT(false); - return QString(); -} - -QString TestBaseLine::details() const -{ - if(m_type == Ignore) /* We're an error code. */ - return QString(); - if(m_type == ExpectedError) /* We're an error code. */ - return m_details; - if(m_type == SchemaIsValid) /* We're a schema validation information . */ - return m_details; - - if(m_details.isEmpty()) - return m_details; - - /* m_details is a file name, we open it and return the result. */ - QFile file(QUrl(m_details).toLocalFile()); - - QString retval; - if(!file.exists()) - retval = QString::fromLatin1("%1 does not exist.").arg(file.fileName()); - else if(!QFileInfo(file.fileName()).isFile()) - retval = QString::fromLatin1("%1 is not a file, cannot display it.").arg(file.fileName()); - else if(!file.open(QIODevice::ReadOnly | QIODevice::Text)) - retval = QString::fromLatin1("Could not open %1. Likely a permission error.").arg(file.fileName()); - - if(retval.isNull()) - { - /* Scary, we assume the query/baseline is in UTF-8. */ - return QString::fromUtf8(file.readAll()); - } - else - { - /* We had a file error. */ - retval.prepend(QLatin1String("Test-suite harness error: ")); - qCritical() << retval; - return retval; - } -} - -TestBaseLine::Type TestBaseLine::type() const -{ - return m_type; -} - -void TestBaseLine::setDetails(const QString &detailsP) -{ - m_details = detailsP; -} - -// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternsxqts/lib/TestBaseLine.h b/tests/auto/xmlpatternsxqts/lib/TestBaseLine.h deleted file mode 100644 index e297128..0000000 --- a/tests/auto/xmlpatternsxqts/lib/TestBaseLine.h +++ /dev/null @@ -1,212 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 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$ -** -****************************************************************************/ - -#ifndef PatternistSDK_TestBaseLine_H -#define PatternistSDK_TestBaseLine_H - -#include - -#include "Global.h" -#include "TestResult.h" - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -class QDomNamedNodeMap; -class QDomNode; -class QDomNodeList; -template class QList; - -namespace QPatternistSDK -{ - /** - * @short Represents an expected test result for a test case. - * - * TestBaseLine represents a valid outcome for a test case, - * the "base line". A XQTS test case can have many different valid - * base lines, and one TestBaseLine instance represents on of them. - * - * Of highest interest, TestBaseLine have the function scan() and - * scanErrors(), which allows serialized output to be - * compared to the base line. - * - * @ingroup PatternistSDK - * @author Frans Englich - */ - class Q_PATTERNISTSDK_EXPORT TestBaseLine - { - public: - typedef QList List; - - /** - * Identifies what kind of comparator to use. The documentation - * for each enumerator is copied from - * Guidelines - * for Running the XML Query Test Suite - */ - enum Type - { - /** - * The test harness must canonicalize both, the actual result - * and the expected result according to the "Canonical XML" recommendation [2], - * which refers to a number of open-source implementations. Byte-comparison can - * then be applied to the resulting XML documents. If the test harness does - * this process in a different manner, it must be documented. - */ - XML, - - /** - * For XML fragments, the same root node must be created for both, - * implementation result and test suite result. The resulting XML - * can be compared using XML comparison. - */ - Fragment, - - /** - * Text (that has been produced by XML serialization) is compared - * using byte-comparison. - */ - Text, - - /** - * No comparison needs to be applied; the result is always @c true if - * the implementation successfully executes the test case. - */ - Ignore, - - /** - * A human is required to make the call about correctness of the result - * according to the description in the test case. - */ - Inspect, - - /** - * The expected result of the test case is an error, identified as an - * eight-character error code (e.g., XPST0003). The result of a test is - * @c true, if the implementation raises an error. However, raising an error - * because an implementation does not support the feature is not - * considered a correct result. - */ - ExpectedError, - - /** - * A special comparison for the schema validation tests. The details - * can only be 'true' or 'false' depending on whether it is a valid - * schema or not. - */ - SchemaIsValid - }; - - /** - * Takes a string identifying a comparator either in the XSL-T or the - * XQuery test suite, and returns an enum value for it. - * - * If the value is unknown, the code asserts. - */ - static Type identifierFromString(const QString &string); - - /** - * @returns a display name for @p id. For example, if Inspect was passed, "Inspect" - * would be returned. - */ - static QString displayName(const Type id); - - /** - * Compares @p items(typically the result of an evaluation) against - * the base lines @p lines. - * - * @returns the status of the first base line which passes, - * otherwise TestResult::Fail. - */ - static TestResult::Status scan(const QString &serialized, - const TestBaseLine::List &lines); - - static TestResult::Status scanErrors(const ErrorHandler::Message::List &errors, - const TestBaseLine::List &lines); - - /** - * Constructs a TestBaseLine of type @p type. - */ - TestBaseLine(const Type type); - - /** - * What @p details contains depends on the type(). If the type() is ExpectedError, - * @p details contains the relevant error code. If the type() is one which compares - * result against a base line, it is a filename locating the baseline. - */ - void setDetails(const QString &details); - - Type type() const; - - QString details() const; - - void toXML(XMLWriter &receiver) const; - - protected: - TestResult::Status verify(const QString &serializedInput) const; - - private: - static bool isDeepEqual(const QDomNode &n1, const QDomNode &n2); - - /** - * @returns @c true if the nodes in @p cl1 are equal to @p cl2, by calling isDeepEqual() - * for each pair. - */ - static bool isChildrenDeepEqual(const QDomNodeList &cl1, const QDomNodeList &cl2); - - /** - * Considers @p cl1 and @p cl2 to be lists containing attributes. The list are equal - * if they contain attributes by same value and name, but regardless of order. - */ - static bool isAttributesEqual(const QDomNamedNodeMap &cl1, const QDomNamedNodeMap &cl2); - const Type m_type; - QString m_details; - }; -} - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif -// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternsxqts/lib/TestCase.cpp b/tests/auto/xmlpatternsxqts/lib/TestCase.cpp deleted file mode 100644 index 7b424d2..0000000 --- a/tests/auto/xmlpatternsxqts/lib/TestCase.cpp +++ /dev/null @@ -1,439 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 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 -#include -#include -#include -#include - -#include "DebugExpressionFactory.h" -#include "ExternalSourceLoader.h" -#include "Global.h" -#include "TestSuite.h" -#include "XMLWriter.h" - -#include "TestCase.h" - -using namespace QPatternistSDK; -using namespace QPatternist; - -// STATIC DATA -static const DebugExpressionFactory::Ptr s_exprFact(new DebugExpressionFactory()); - -TestCase::TestCase() : m_result(0) -{ -} - -TestCase::~TestCase() -{ - delete m_result; -} - -TestResult::List TestCase::execute(const ExecutionStage stage, - TestSuite *) -{ - if(name() == QLatin1String("Constr-cont-document-3")) - { - TestResult::List result; - result.append(createTestResult(TestResult::Fail, QLatin1String("Skipped this test, because we loop infinitely on it."))); - return result; - } - else if(name() == QLatin1String("Axes089")) - { - TestResult::List result; - result.append(createTestResult(TestResult::Fail, QLatin1String("Skipped this test, we crash on it."))); - return result; - } - - qDebug() << "Running test case: " << name(); - - return execute(stage); - - Q_ASSERT(false); - return TestResult::List(); -} - -TestResult *TestCase::createTestResult(const TestResult::Status status, - const QString &comment) const -{ - TestResult *const result = new TestResult(name(), - status, - 0 /* We don't have an AST. */, - ErrorHandler::Message::List(), - QPatternist::Item::List(), - QString()); - result->setComment(comment); - return result; -} - -TestResult::List TestCase::execute(const ExecutionStage stage) -{ - ErrorHandler errHandler; - ErrorHandler::installQtMessageHandler(&errHandler); - - pDebug() << "TestCase::execute()"; - delete m_result; - - QXmlQuery query(language(), Global::namePoolAsPublic()); - - query.d->setExpressionFactory(s_exprFact); - query.setInitialTemplateName(initialTemplateName()); - - QXmlQuery openDoc(query.namePool()); - - if(contextItemSource().isValid()) - { - openDoc.setQuery(QString::fromLatin1("doc('") + contextItemSource().toString() + QLatin1String("')")); - Q_ASSERT(openDoc.isValid()); - QXmlResultItems result; - - openDoc.evaluateTo(&result); - const QXmlItem item(result.next()); - Q_ASSERT(!item.isNull()); - query.setFocus(item); - } - - TestResult::List retval; - - const Scenario scen(scenario()); - TestResult::Status resultStatus = TestResult::Unknown; - - bool ok = false; - const QString queryString(sourceCode(ok)); - - if(!ok) - { - /* Loading the query file failed, or similar. */ - resultStatus = TestResult::Fail; - - m_result = new TestResult(name(), resultStatus, s_exprFact->astTree(), - errHandler.messages(), QPatternist::Item::List(), QString()); - retval.append(m_result); - ErrorHandler::installQtMessageHandler(0); - changed(this); - return retval; - } - - query.setMessageHandler(&errHandler); - QXmlNamePool namePool(query.namePool()); - - /* Bind variables. */ - QPatternist::ExternalVariableLoader::Ptr loader(externalVariableLoader()); - if(loader) - { - Q_ASSERT(loader); - const ExternalSourceLoader::VariableMap vMap(static_cast(loader.data())->variableMap()); - const QStringList variables(vMap.keys()); - - for(int i = 0; i < variables.count(); ++i) - { - const QXmlName name(namePool, variables.at(i)); - const QXmlItem val(QPatternist::Item::toPublic(loader->evaluateSingleton(name, QPatternist::DynamicContext::Ptr()))); - query.bindVariable(name, val); - } - } - - /* We pass in the testCasePath(), such that the base URI is correct fort - * XSL-T stylesheets. */ - query.setQuery(queryString, testCasePath()); - - if(!query.isValid()) - { - pDebug() << "Got compilation exception."; - resultStatus = TestBaseLine::scanErrors(errHandler.messages(), baseLines()); - - Q_ASSERT(resultStatus != TestResult::Unknown); - m_result = new TestResult(name(), resultStatus, s_exprFact->astTree(), - errHandler.messages(), QPatternist::Item::List(), QString()); - retval.append(m_result); - ErrorHandler::installQtMessageHandler(0); - changed(this); - return retval; - } - - if(stage == CompileOnly) - { - m_result = new TestResult(name(), TestResult::Fail, s_exprFact->astTree(), - errHandler.messages(), QPatternist::Item::List(), QString()); - retval.append(m_result); - return retval; - } - - Q_ASSERT(stage == CompileAndRun); - - if(scen == ParseError) /* We're supposed to have received an error - at this point. */ - { - m_result = new TestResult(name(), TestResult::Fail, s_exprFact->astTree(), - errHandler.messages(), QPatternist::Item::List(), QString()); - ErrorHandler::installQtMessageHandler(0); - retval.append(m_result); - changed(this); - return retval; - } - - QPatternist::Item::List itemList; - - QByteArray output; - QBuffer buffer(&output); - buffer.open(QIODevice::WriteOnly); - - QXmlSerializer serializer(query, &buffer); - - pDebug() << "-------------------------- evaluateToPushCallback() ---------------------------- "; - const bool success = query.evaluateTo(&serializer); - pDebug() << "------------------------------------------------------------------------------------ "; - - buffer.close(); - - const QString serialized(QString::fromUtf8(output.constData(), output.size())); - - if(!success) - { - resultStatus = TestBaseLine::scanErrors(errHandler.messages(), baseLines()); - - Q_ASSERT(resultStatus != TestResult::Unknown); - m_result = new TestResult(name(), resultStatus, s_exprFact->astTree(), - errHandler.messages(), QPatternist::Item::List(), serialized); - retval.append(m_result); - ErrorHandler::installQtMessageHandler(0); - changed(this); - return retval; - } - - /* It's a regular test. */ - Q_ASSERT(scen == Standard || scen == RuntimeError); - - resultStatus = TestBaseLine::scan(serialized, baseLines()); - Q_ASSERT(resultStatus != TestResult::Unknown); - - /* Check that errHandler()->messages() at most only contains - * warnings, since it shouldn't have errors at this point. */ - const ErrorHandler::Message::List errors (errHandler.messages()); - const ErrorHandler::Message::List::const_iterator end(errors.constEnd()); - ErrorHandler::Message::List::const_iterator it(errors.constBegin()); - - for(; it != end; ++it) - { - const QtMsgType type = (*it).type(); - if(type == QtFatalMsg) - { - m_result = new TestResult(name(), TestResult::Fail, s_exprFact->astTree(), - errHandler.messages(), itemList, serialized); - retval.append(m_result); - ErrorHandler::installQtMessageHandler(0); - changed(this); - return retval; - } - } - - m_result = new TestResult(name(), resultStatus, s_exprFact->astTree(), - errHandler.messages(), itemList, serialized); - retval.append(m_result); - ErrorHandler::installQtMessageHandler(0); - changed(this); - return retval; -} - -TestCase::Scenario TestCase::scenarioFromString(const QString &string) -{ - if(string == QLatin1String("standard")) - return Standard; - else if(string == QLatin1String("parse-error")) - return ParseError; - else if(string == QLatin1String("runtime-error")) - return RuntimeError; - else if(string == QLatin1String("trivial")) - return Trivial; - else - { - Q_ASSERT_X(false, Q_FUNC_INFO, - qPrintable(QString::fromLatin1("Invalid string representation for the scenario-enum: %1").arg(string))); - return ParseError; /* Silence GCC. */ - } -} - -void TestCase::toXML(XMLWriter &receiver) const -{ - /* */ - QXmlAttributes test_caseAtts; - test_caseAtts.append(QLatin1String("is-XPath2"), QString(), - QLatin1String("is-XPath2"), isXPath() ? QLatin1String("true") - : QLatin1String("false")); - test_caseAtts.append(QLatin1String("name"), QString(), QLatin1String("name"), name()); - test_caseAtts.append(QLatin1String("creator"), QString(), QLatin1String("creator"), creator()); - QString scen; - switch(scenario()) - { - case Standard: - { - scen = QLatin1String("standard"); - break; - } - case ParseError: - { - scen = QLatin1String("parse-error"); - break; - } - case RuntimeError: - { - scen = QLatin1String("runtime-error"); - break; - } - case Trivial: - { - scen = QLatin1String("trivial"); - break; - } - default: /* includes 'AnyError' */ - Q_ASSERT(false); - } - test_caseAtts.append(QLatin1String("scenario"), QString(), QLatin1String("scenario"), scen); - test_caseAtts.append(QLatin1String(QLatin1String("FilePath")), QString(), - QLatin1String("FilePath"), QString()); - receiver.startElement(QLatin1String("test-case"), test_caseAtts); - - /* */ - receiver.startElement(QLatin1String("description"), test_caseAtts); - receiver.characters(description()); - - /* */ - receiver.endElement(QLatin1String("description")); - - /* */ - QXmlAttributes queryAtts; - queryAtts.append(QLatin1String("date"), QString(), QLatin1String("date"), /* This date is a dummy. */ - QDate::currentDate().toString(Qt::ISODate)); - queryAtts.append(QLatin1String("name"), QString(), QLatin1String("name"), testCasePath().toString()); - receiver.startElement(QLatin1String("query"), queryAtts); - - /* */ - receiver.endElement(QLatin1String("query")); - - /* Note: this is invalid, we don't add spec-citation. */ - TestBaseLine::List bls(baseLines()); - const TestBaseLine::List::const_iterator end(bls.constEnd()); - TestBaseLine::List::const_iterator it(bls.constBegin()); - - for(; it != end; ++it) - (*it)->toXML(receiver); - - /* */ - receiver.endElement(QLatin1String("test-case")); -} - -QString TestCase::displayName(const Scenario scen) -{ - switch(scen) - { - case Standard: - return QLatin1String("Standard"); - case ParseError: - return QLatin1String("Parse Error"); - case RuntimeError: - return QLatin1String("Runtime Error"); - case Trivial: - return QLatin1String("Trivial"); - case AnyError: - { - Q_ASSERT(false); - return QString(); - } - } - - Q_ASSERT(false); - return QString(); -} - -TestItem::ResultSummary TestCase::resultSummary() const -{ - if(m_result) - return ResultSummary(m_result->status() == TestResult::Pass ? 1 : 0, - 1); - - return ResultSummary(0, 1); -} - -void TestCase::appendChild(TreeItem *) -{ - Q_ASSERT_X(false, Q_FUNC_INFO, "Makes no sense to call appendChild() for TestCase."); -} - -TreeItem *TestCase::child(const unsigned int) const -{ - return 0; /* Silence GCC */ -} - -TreeItem::List TestCase::children() const -{ - return TreeItem::List(); -} - -unsigned int TestCase::childCount() const -{ - return 0; -} - -TestResult *TestCase::testResult() const -{ - return m_result; -} - -bool TestCase::isFinalNode() const -{ - return true; -} - -QXmlQuery::QueryLanguage TestCase::language() const -{ - return QXmlQuery::XQuery10; -} - -QXmlName TestCase::initialTemplateName() const -{ - return QXmlName(); -} - -// vim: et:ts=4:sw=4:sts=4 - diff --git a/tests/auto/xmlpatternsxqts/lib/TestCase.h b/tests/auto/xmlpatternsxqts/lib/TestCase.h deleted file mode 100644 index 28df5f1..0000000 --- a/tests/auto/xmlpatternsxqts/lib/TestCase.h +++ /dev/null @@ -1,256 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 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$ -** -****************************************************************************/ - -#ifndef PatternistSDK_TestCase_H -#define PatternistSDK_TestCase_H - -#include - -#include "qexternalvariableloader_p.h" - -#include "ErrorHandler.h" -#include "TestBaseLine.h" -#include "Global.h" - -#include "TestItem.h" - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -class QDate; -class QString; -class QUrl; - -namespace QPatternistSDK -{ - class XMLWriter; - - /** - * @short A generic abstract base class for test cases. - * - * @ingroup PatternistSDK - * @author Frans Englich - */ - class Q_PATTERNISTSDK_EXPORT TestCase : public TestItem - { - public: - /** - * Corresponds to the simpleType test:scenarios-enum - */ - enum Scenario - { - /** - * The test case should evaluate normally and that the output - * should match the supplied base line. - */ - Standard = 1, - - /** - * The test case should result in a static error, a parser error. - */ - ParseError = 2, - - /** - * The test case should result in a dynamic error, a runtime error. - */ - RuntimeError = 4, - - Trivial = 8, - - /** - * ParseError and RuntimeError OR'd. - */ - AnyError = RuntimeError | ParseError - - }; - - TestCase(); - virtual ~TestCase(); - - /** - * Executes the test, and returns the result. The returned list - * will always contain exactly one TestResult. - * - * @p stage is ignored when running out-of-process. - */ - virtual TestResult::List execute(const ExecutionStage stage, - TestSuite *ts); - - /** - * Determines the corresponding Scenario enumerator from the string - * representation @p string. - * - * The following mappings are in effect: - * @arg @c Standard "standard" - * @arg @c ParseError "parse-error" - * @arg @c RuntimeError "runtime-error" - */ - static Scenario scenarioFromString(const QString &string); - - /** - * @return always @c true - */ - virtual bool isFinalNode() const; - - /** - * Calling this function makes no sense, so it always - * performs an Q_ASSERT check. - */ - virtual void appendChild(TreeItem *); - - /** - * Calling this function makes no sense, so it always - * performs an Q_ASSERT check. - */ - virtual TreeItem *child(const unsigned int) const; - - /** - * @return always zero - */ - virtual unsigned int childCount() const; - - /** - * @return always an empty list. - */ - virtual TreeItem::List children() const; - - /** - * A description of the test case for human consumption. - */ - virtual QString description() const = 0; - - /** - * The title of the test. This can be the identifier of the test, for example. - */ - virtual QString title() const = 0; - - /** - * Whether this test case only make use of XPath features. - * - * @returns @c false if the test case exercises any XQuery feature - * which is not available in XPath 2.0. - */ - virtual bool isXPath() const = 0; - - /** - * The full name of the creator of the test case. For example, "Frans Englich". - */ - virtual QString creator() const = 0; - - /** - * The date of when the test case was created or last modified. - */ - virtual QDate lastModified() const = 0; - - /** - * The test's source code. That is, the XPath/XQuery code for the test. - * - * @param ok the function sets this value to @c false if loading the query - * failed, and returns a description of the error for human consumption. If - * everything went ok, @p ok is set to @c true, and the query is returned. - */ - virtual QString sourceCode(bool &ok) const = 0; - - /** - * The path to the file containing the code of the test case. - */ - virtual QUrl testCasePath() const = 0; - - /** - * The test case's identifier. For example, "Literals001". - */ - virtual QString name() const = 0; - - /** - * What kind of test this is. For example, whether the test case - * should result in a parser error or should evaluate without errors. - * - * The vast common case is that one Scenario is returned; the bit signifiance - * is for the TestCase sub-class UserTestCase. - */ - virtual Scenario scenario() const = 0; - - static QString displayName(const Scenario scen); - - /** - * @returns the valid test baselines for this test case. If only - * one outcome is valid, the returned list only contains - * that baseline. - */ - virtual TestBaseLine::List baseLines() const = 0; - - virtual TestResult *testResult() const; - - virtual ResultSummary resultSummary() const; - - void toXML(XMLWriter &receiver) const; - - virtual QPatternist::ExternalVariableLoader::Ptr externalVariableLoader() const = 0; - - /** - * @short The XML document that should be used as focus. If none should - * be used, and hence the focus be undefined, a default constructed - * QUrl is returned. - */ - virtual QUrl contextItemSource() const = 0; - - /** - * Returns by default QXmlQuery::XQuery10. - */ - virtual QXmlQuery::QueryLanguage language() const; - - virtual QXmlName initialTemplateName() const; - private: - TestResult::List execute(const ExecutionStage stage); - TestResult *createTestResult(const TestResult::Status status, - const QString &comment) const; - - QPointer m_result; - }; -} - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif -// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternsxqts/lib/TestContainer.cpp b/tests/auto/xmlpatternsxqts/lib/TestContainer.cpp deleted file mode 100644 index ec6196c..0000000 --- a/tests/auto/xmlpatternsxqts/lib/TestContainer.cpp +++ /dev/null @@ -1,151 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 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 "TestContainer.h" - -using namespace QPatternistSDK; - -TestContainer::TestContainer() : m_deleteChildren(true) -{ -} - -TestContainer::~TestContainer() -{ - if(m_deleteChildren) - qDeleteAll(m_children); -} - -TestResult::List TestContainer::execute(const ExecutionStage stage, - TestSuite *ts) -{ - Q_ASSERT(ts); - const unsigned int c = m_children.count(); - TestResult::List result; - - for(unsigned int i = 0; i != c; ++i) - result += static_cast(child(i))->execute(stage, ts); - - return result; -} - -TestItem::ResultSummary TestContainer::resultSummary() const -{ - const int c = childCount(); - int total = 0; - int pass = 0; - - for(int i = 0; i != c; ++i) - { - TestItem *t = static_cast(child(i)); - const ResultSummary sum(t->resultSummary()); - pass += sum.first; - total += sum.second; - } - - return ResultSummary(pass, total); -} - -TreeItem::List TestContainer::children() const -{ - return m_children; -} - -void TestContainer::appendChild(TreeItem *item) -{ - /* When one of our children changes, we changes. */ - connect(item, SIGNAL(changed(TreeItem *)), SIGNAL(changed(TreeItem *))); - m_children.append(item); -} - -TreeItem *TestContainer::child(const unsigned int rowP) const -{ - return m_children.value(rowP); -} - -unsigned int TestContainer::childCount() const -{ - return m_children.count(); -} - -void TestContainer::setTitle(const QString &titleP) -{ - m_title = titleP; -} - -QString TestContainer::title() const -{ - return m_title; -} - -bool TestContainer::isFinalNode() const -{ - return false; -} - -int TestContainer::columnCount() const -{ - return 4; -} - -QString TestContainer::description() const -{ - return m_description; -} - -void TestContainer::setDescription(const QString &desc) -{ - m_description = desc; -} - -void TestContainer::setDeleteChildren(const bool val) -{ - m_deleteChildren = val; -} - -void TestContainer::removeLast() -{ - m_children.removeLast(); -} - -// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternsxqts/lib/TestContainer.h b/tests/auto/xmlpatternsxqts/lib/TestContainer.h deleted file mode 100644 index 5b93491..0000000 --- a/tests/auto/xmlpatternsxqts/lib/TestContainer.h +++ /dev/null @@ -1,123 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 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$ -** -****************************************************************************/ - -#ifndef PatternistSDK_TestContainer_H -#define PatternistSDK_TestContainer_H - -#include "Global.h" -#include "TestItem.h" - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -namespace QPatternistSDK -{ - /** - * @short an abstract base class, containing - * an appropriate implementation of TestItem for sub-classes - * which can contain other TestItem instances. - * - * @ingroup PatternistSDK - * @author Frans Englich - */ - class Q_PATTERNISTSDK_EXPORT TestContainer : public TestItem - { - public: - virtual ~TestContainer(); - virtual void appendChild(TreeItem *item); - virtual TreeItem *child(const unsigned int row) const; - virtual unsigned int childCount() const; - - /** - * @returns the TestResults of this TestContainer's children. - */ - virtual TestResult::List execute(const ExecutionStage stage, - TestSuite *ts); - - QString title() const; - void setTitle(const QString &title); - - virtual TreeItem::List children() const; - - /** - * @return always 2 - */ - virtual int columnCount() const; - - virtual bool isFinalNode() const; - - virtual ResultSummary resultSummary() const; - virtual QString description() const; - virtual void setDescription(const QString &desc); - - /** - * Determines whether TestContainer will delete its children upon - * destruction. By default, it will. - */ - void setDeleteChildren(const bool val); - - /** - * Removes the last appended child. - */ - void removeLast(); - - protected: - /** - * Constructor, protected. TestContainer is an abstract class, - * and is not ment to be instantiated, but sub classed. - */ - TestContainer(); - - private: - TreeItem::List m_children; - QString m_title; - QString m_description; - bool m_deleteChildren; - }; -} - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif -// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternsxqts/lib/TestGroup.cpp b/tests/auto/xmlpatternsxqts/lib/TestGroup.cpp deleted file mode 100644 index f2cd2bd..0000000 --- a/tests/auto/xmlpatternsxqts/lib/TestGroup.cpp +++ /dev/null @@ -1,143 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 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 - -#include "TestGroup.h" - -using namespace QPatternistSDK; - -TestGroup::TestGroup(TreeItem *p) : m_parent(p) -{ -} - -QVariant TestGroup::data(const Qt::ItemDataRole role, int column) const -{ - if(role != Qt::DisplayRole && role != Qt::BackgroundRole && role != Qt::ToolTipRole) - return QVariant(); - - /* In ResultSummary, the first is the amount of passes and the second is the total. */ - const ResultSummary sum(resultSummary()); - const int failures = sum.second - sum.first; - - switch(role) - { - case Qt::DisplayRole: - { - - switch(column) - { - case 0: - return title(); - case 1: - /* Passes. */ - return QString::number(sum.first); - case 2: - /* Failures. */ - return QString::number(failures); - case 3: - /* Total. */ - return QString::number(sum.second); - default: - { - Q_ASSERT(false); - return QString(); - } - } - } - case Qt::BackgroundRole: - { - switch(column) - { - case 1: - { - if(sum.first) - { - /* Pass. */ - return Qt::green; - } - else - return QVariant(); - } - case 2: - { - if(failures) - { - /* Failure. */ - return Qt::red; - } - else - return QVariant(); - } - default: - return QVariant(); - } - } - case Qt::ToolTipRole: - { - return description(); - } - default: - { - Q_ASSERT_X(false, Q_FUNC_INFO, "This shouldn't be reached"); - return QVariant(); - } - } -} - -void TestGroup::setNote(const QString &n) -{ - m_note = n; -} - -QString TestGroup::note() const -{ - return m_note; -} - -TreeItem *TestGroup::parent() const -{ - return m_parent; -} - -// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternsxqts/lib/TestGroup.h b/tests/auto/xmlpatternsxqts/lib/TestGroup.h deleted file mode 100644 index 5f4798f..0000000 --- a/tests/auto/xmlpatternsxqts/lib/TestGroup.h +++ /dev/null @@ -1,93 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 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$ -** -****************************************************************************/ - -#ifndef PatternistSDK_TestGroup_H -#define PatternistSDK_TestGroup_H - -#include - -#include "TestContainer.h" - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -namespace QPatternistSDK -{ - /** - * @short Groups test groups and test cases into a group. - * - * TestGroup corresponds to the @c test-group element in XQTSCatalog.xsd. - * - * @ingroup PatternistSDK - * @author Frans Englich - */ - class Q_PATTERNISTSDK_EXPORT TestGroup : public TestContainer - { - public: - TestGroup(TreeItem *parent); - - /** - * @returns the parent of this group. Is either another group, or - * the TestSuite instance governing this tree. - */ - virtual TreeItem *parent() const; - - virtual QVariant data(const Qt::ItemDataRole role, int column) const; - - QString note() const; - - void setName(const QString &name); - void setNote(const QString ¬e); - - private: - QString m_name; - QString m_note; - TreeItem *m_parent; - }; -} - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif -// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternsxqts/lib/TestItem.h b/tests/auto/xmlpatternsxqts/lib/TestItem.h deleted file mode 100644 index 0b3c606..0000000 --- a/tests/auto/xmlpatternsxqts/lib/TestItem.h +++ /dev/null @@ -1,133 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 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$ -** -****************************************************************************/ - -#ifndef PatternistSDK_TestItem_H -#define PatternistSDK_TestItem_H - -#include "TestResult.h" -#include "TreeItem.h" - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -template struct QPair; - -namespace QPatternistSDK -{ - class XMLWriter; - class TestSuite; - - /** - * @short base class for all classes which - * represent an element in an XQuery Test Suite catalog. - * - * @ingroup PatternistSDK - * @author Frans Englich - */ - class Q_PATTERNISTSDK_EXPORT TestItem : public TreeItem - { - public: - - /** - * Determines how far an test case execution should go. - */ - enum ExecutionStage - { - /** - * The query will not be run. It will only go through the (whole) compilation stage. - */ - CompileOnly = 1, - - /** - * The query will be compiled and run, as ordinary. - */ - CompileAndRun - }; - - /** - * Represents a summary of test results for a collection - * of tests. QPair::first contains the amount of - * passed tests; QPair::second contains the count of - * all tests. For example TestCase::summary() returns - * ResultSummary(0, 1) or ResultSummary(1, 1) depending - * on whether the TestCase have succeeded or not. - */ - typedef QPair ResultSummary; - - /** - * Executes the test case(s) this TestItem represents, - * and return the TestResult. For example, the TestGroup - * returns the result of its children concatenated, while - * TestCase always returns a list containing one - * TestResult(what it evaluated to). - */ - virtual TestResult::List execute(const ExecutionStage stage, - TestSuite *ts) = 0; - - /** - * @todo Rename this function. Perhaps create a type() hierarchy - * instead. - */ - virtual bool isFinalNode() const = 0; - - /** - * @returns a ResultSummary for this TestItem. - */ - virtual ResultSummary resultSummary() const = 0; - - /** - * Serializes into the corresponding elements attributes - * specified in XQTSCatalog.xsd. - * - * @note Sub-classes must assume the XQTSCatalog namespace - * is the default namespace, and not add any namespace declarations. - */ - //virtual void toXML(XMLWriter &receiver) const = 0; - }; -} - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif -// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternsxqts/lib/TestResult.cpp b/tests/auto/xmlpatternsxqts/lib/TestResult.cpp deleted file mode 100644 index 2374bc0..0000000 --- a/tests/auto/xmlpatternsxqts/lib/TestResult.cpp +++ /dev/null @@ -1,158 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 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 "qdebug_p.h" -#include "Global.h" -#include "XMLWriter.h" - -#include "TestResult.h" - -using namespace QPatternistSDK; -using namespace QPatternist; - -QString TestResult::displayName(const TestResult::Status stat) -{ - switch(stat) - { - case Pass: - return QLatin1String("pass"); - case Fail: - return QLatin1String("fail"); - case NotTested: - return QLatin1String("not tested"); - case Unknown: - Q_ASSERT(false); - } - - Q_ASSERT(false); - return QString(); -} - -TestResult::Status TestResult::statusFromString(const QString &string) -{ - if(string == QLatin1String("pass")) - return Pass; - else if(string == QLatin1String("fail")) - return Fail; - else if(string == QLatin1String("not tested")) - return NotTested; - else - { - Q_ASSERT(false); - return Fail; - } -} - -TestResult::TestResult(const QString &n, - const Status s, - ASTItem *tree, - const ErrorHandler::Message::List &ers, - const QPatternist::Item::List &itemsP, - const QString &serialized) : m_status(s), - m_messages(ers), - m_astTree(tree), - m_testName(n), - m_items(itemsP), - m_asSerialized(serialized) -{ - Q_ASSERT(!n.isEmpty()); - Q_ASSERT(s != 0); -} - -TestResult::~TestResult() -{ - delete m_astTree; -} - -void TestResult::toXML(XMLWriter &receiver) const -{ - QXmlAttributes atts; - atts.append(QLatin1String("name"), QString(), QLatin1String("name"), m_testName); - atts.append(QLatin1String("result"), QString(), QLatin1String("result"), displayName(m_status)); - - if(!m_comment.isEmpty()) - atts.append(QLatin1String("comment"), QString(), QLatin1String("comment"), m_comment); - - receiver.startElement(QLatin1String("test-case"), atts); - receiver.endElement(QLatin1String("test-case")); -} - -void TestResult::setComment(const QString &comm) -{ - m_comment = comm; -} - -TestResult::Status TestResult::status() const -{ - return m_status; -} - -QString TestResult::comment() const -{ - return m_comment; -} - -ASTItem *TestResult::astTree() const -{ - return m_astTree; -} - -ErrorHandler::Message::List TestResult::messages() const -{ - return m_messages; -} - -QPatternist::Item::List TestResult::items() const -{ - return m_items; -} - -QString TestResult::asSerialized() const -{ - pDebug() << "asSerialized: " << m_asSerialized; - return m_asSerialized; -} - -// vim: et:ts=4:sw=4:sts=4 - diff --git a/tests/auto/xmlpatternsxqts/lib/TestResult.h b/tests/auto/xmlpatternsxqts/lib/TestResult.h deleted file mode 100644 index 6951f90..0000000 --- a/tests/auto/xmlpatternsxqts/lib/TestResult.h +++ /dev/null @@ -1,179 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 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$ -** -****************************************************************************/ - -#ifndef PatternistSDK_TestResult_H -#define PatternistSDK_TestResult_H - -#include -#include -#include -#include - -#include -#include "ErrorHandler.h" - -#include "ASTItem.h" - - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -namespace QPatternistSDK -{ - class ASTItem; - class XMLWriter; - - /** - * @short represents the result produced by running a test case. - * - * This information TestResult houses is: - * - * - The result status() of the run. Whether the test case succeeded or not, for example. - * - The astTree() which reflects the compiled test case - * - The messages issued when compiling and running the test case, retrievable via messages() - * - The data -- XPath Data Model items() -- the test case evaluated to, if any. - * - * @ingroup PatternistSDK - * @author Frans Englich - */ - class Q_PATTERNISTSDK_EXPORT TestResult : public QObject - { - Q_OBJECT - - public: - enum Status - { - /** - * Used when the status is unknown. - */ - Unknown = 0, - - /** - * The test case passed. - */ - Pass, - - /** - * The test case failed. - */ - Fail, - - /** - * The test was not run. Similar to "SKIP". - */ - NotTested - }; - - /** - * A list of TestResult instances. - */ - typedef QList > List; - - /** - * Constructs a TestResult. - * - * @param testName the name of the test. For example, @c Literal-001. - * @param astTree may be @c null, signalling no AST being available, or point to one. - * @param status the result status of running the test-case. Whether the test-case - * passed or failed, and so forth. - * @param errors the errors and warnings that were reported while running the test-case - * @param items the XDM items that were outputted, if any - * @param serialized the output when serialized - */ - TestResult(const QString &testName, - const Status status, - ASTItem *astTree, - const ErrorHandler::Message::List &errors, - const QPatternist::Item::List &items, - const QString &serialized); - - virtual ~TestResult(); - - Status status() const; - - QString comment() const; - void setComment(const QString &comment); - - QPatternist::Item::List items() const; - - ErrorHandler::Message::List messages() const; - - /** - * Serializes itself to @p receiver, into a test-case element, - * as per @c XQTSResult.xsd. - */ - void toXML(XMLWriter &receiver) const; - - ASTItem *astTree() const; - - /** - * @returns a string representation for @p status, as per the anonymous - * type inside the type test-case, in @c XQTSResult.xsd. For example, if @p status - * is NotTested, is "not tested" returned. - */ - static QString displayName(const TestResult::Status status); - - static Status statusFromString(const QString &string); - - /** - * @returns the output of this test result(if any) as when - * being serialized. - */ - QString asSerialized() const; - - private: - const Status m_status; - QString m_comment; - const ErrorHandler::Message::List m_messages; - QPointer m_astTree; - QString m_testName; - const QPatternist::Item::List m_items; - const QString m_asSerialized; - }; -} - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif -// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternsxqts/lib/TestResultHandler.cpp b/tests/auto/xmlpatternsxqts/lib/TestResultHandler.cpp deleted file mode 100644 index b87d481..0000000 --- a/tests/auto/xmlpatternsxqts/lib/TestResultHandler.cpp +++ /dev/null @@ -1,98 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 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 "Global.h" - -#include "TestResultHandler.h" - -using namespace QPatternistSDK; - -TestResultHandler::TestResultHandler() -{ - /* Fifteen thousand. When finished, we squeeze them. */ - m_result.reserve(15000); - m_comments.reserve(1000); /* Comments are only used for stuff that crash, more or less. */ -} - -bool TestResultHandler::startElement(const QString &namespaceURI, - const QString &localName, - const QString &, - const QXmlAttributes &atts) -{ - /* We only care about 'test-case', ignore everything else. */ - if(localName != QLatin1String("test-case") || - namespaceURI != Global::xqtsResultNS) - return true; - - /* The 'comments' attribute is optional. */ - Q_ASSERT_X(atts.count() == 2 || atts.count() == 3, Q_FUNC_INFO, - "The input appears to not conform to XQTSResult.xsd"); - - Q_ASSERT_X(!m_result.contains(atts.value(QLatin1String("name"))), - Q_FUNC_INFO, - qPrintable(QString::fromLatin1("A test result for test case %1 has " - "already been read(duplicate entry it seems).").arg(atts.value(QLatin1String("name"))))); - - m_result.insert(atts.value(0), TestResult::statusFromString(atts.value(QLatin1String("result")))); - - return true; -} - -bool TestResultHandler::endDocument() -{ - m_result.squeeze(); - m_comments.squeeze(); - return true; -} - -TestResultHandler::Hash TestResultHandler::result() const -{ - return m_result; -} - -TestResultHandler::CommentHash TestResultHandler::comments() const -{ - return m_comments; -} - -// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternsxqts/lib/TestResultHandler.h b/tests/auto/xmlpatternsxqts/lib/TestResultHandler.h deleted file mode 100644 index a786ac4..0000000 --- a/tests/auto/xmlpatternsxqts/lib/TestResultHandler.h +++ /dev/null @@ -1,115 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 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$ -** -****************************************************************************/ - -#ifndef PatternistSDK_TestResultHandler_H -#define PatternistSDK_TestResultHandler_H - -#include -#include -#include - -#include "TestResult.h" - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -namespace QPatternistSDK -{ - /** - * @short Reads XML in the @c XQTSResult.xsd format, and provides access to - * the reported results. - * - * @author Frans Englich - * @ingroup PatternistSDK - */ - class Q_PATTERNISTSDK_EXPORT TestResultHandler : public QXmlDefaultHandler - { - public: - /** - * A hash where the key is the class's name, that is test-case/@@name, - * and the value the test's result status. - */ - typedef QHash Hash; - - /** - * A hash mapping test-case names to their' comments. - */ - typedef QHash CommentHash; - - /** - * Creates a TestResultHandler that will read @p file when run() is called. - */ - TestResultHandler(); - - /** - * Performs finalization. - */ - virtual bool endDocument(); - - /** - * Reads the test-case element and its attributes, everything else is ignored. - */ - virtual bool startElement(const QString &namespaceURI, - const QString &localName, - const QString &qName, - const QXmlAttributes &atts); - /** - * @note Do not reimplement this function. - * @returns the result obtained from reading the XML file. - */ - Hash result() const; - - CommentHash comments() const; - - private: - Q_DISABLE_COPY(TestResultHandler) - Hash m_result; - CommentHash m_comments; - }; -} - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif -// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternsxqts/lib/TestSuite.cpp b/tests/auto/xmlpatternsxqts/lib/TestSuite.cpp deleted file mode 100644 index 2c3e49c..0000000 --- a/tests/auto/xmlpatternsxqts/lib/TestSuite.cpp +++ /dev/null @@ -1,269 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 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 -#include -#include - -#include "Global.h" -#include "TestSuiteHandler.h" -#include "TestSuiteResult.h" -#include "XMLWriter.h" -#include "XSLTTestSuiteHandler.h" -#include "XSDTestSuiteHandler.h" -#include "qdebug_p.h" - -#include "TestSuite.h" - -using namespace QPatternistSDK; -using namespace QPatternist; - -TestSuite::TestSuite() -{ -} - -QVariant TestSuite::data(const Qt::ItemDataRole role, int column) const -{ - if(role != Qt::DisplayRole) - return QVariant(); - - switch(column) - { - case 0: - return title(); - case 1: - return QString(); - default: - { - Q_ASSERT(false); - return QString(); - } - } -} - -TestSuiteResult *TestSuite::runSuite() -{ - const QDate date(QDate::currentDate()); - TestResult::List result(execute(CompileAndRun, this)); - - return new TestSuiteResult(version(), date, result); -} - -TestSuite *TestSuite::openCatalog(const QUrl &catalogURI, - QString &errorMsg, - const bool useExclusionList, - SuiteType suiteType) -{ - pDebug() << "Opening catalog:" << catalogURI.toString(); - QFile ts(catalogURI.toLocalFile()); - Q_ASSERT(catalogURI.isValid()); - - if(!ts.exists()) - { - errorMsg = QString::fromLatin1("The test suite catalog \"%1\" could not be found.\n") - .arg(ts.fileName()); - return 0; - } - - const QFileInfo info(ts); - - if(!info.isReadable()) - { - errorMsg = QString::fromLatin1("Cannot read the test suite catalog.\n"); - return 0; - } - else if(!info.isFile()) - { - errorMsg = QString::fromLatin1("The specified test suite catalog \"%1\" is not a file. " - "The test suite catalog must be a file, it cannot be " - "a directory, for example.\n") - .arg(ts.fileName()); - return 0; - } - else if(!ts.open(QIODevice::ReadOnly | QIODevice::Text)) - { - errorMsg = QString::fromLatin1("Failed to open the test suite catalog, \"%1\".\n") - .arg(ts.fileName()); - return 0; - } - - return openCatalog(&ts, errorMsg, catalogURI, useExclusionList, suiteType); -} - -TestSuite *TestSuite::openCatalog(QIODevice *input, - QString &errorMsg, - const QUrl &fileName, - const bool useExclusionList, - SuiteType suiteType) -{ - Q_ASSERT(input); - - QXmlSimpleReader reader; - typedef QPatternist::AutoPtr HandlerPtr; - - HandlerPtr loader; - - switch (suiteType) { - case XQuerySuite: loader = HandlerPtr(new TestSuiteHandler(fileName, useExclusionList)); break; - case XsltSuite: loader = HandlerPtr(new XSLTTestSuiteHandler(fileName)); break; - case XsdSuite: loader = HandlerPtr(new XSDTestSuiteHandler(fileName)); break; - default: Q_ASSERT(false); break; - } - - reader.setContentHandler(loader.data()); - - QXmlInputSource source(input); - - if(!reader.parse(source)) - { - errorMsg = QString::fromLatin1("Couldn't parse %1").arg(fileName.toString()); - return 0; - } - - TestSuite *suite = 0; - switch (suiteType) { - case XQuerySuite: suite = static_cast(loader.data())->testSuite(); break; - case XsltSuite: suite = static_cast(loader.data())->testSuite(); break; - case XsdSuite: suite = static_cast(loader.data())->testSuite(); break; - default: Q_ASSERT(false); break; - } - - if(suite) - return suite; - - errorMsg = QString::fromLatin1("Failed to load \"%1\". " - "It appears to have no test-suite element.\n").arg(fileName.toString()); - return 0; -} - -void TestSuite::toXML(XMLWriter &receiver, TestCase *const tc) const -{ - // TODO startElement() endElement() calls can be simplified. - - Q_ASSERT(tc); - - receiver.startDocument(); - /* */ - QXmlAttributes test_suiteAtts; - test_suiteAtts.append(QLatin1String("CatalogDesignDate"), QString(), - QLatin1String("CatalogDesignDate"), m_designDate.toString(Qt::ISODate)); - test_suiteAtts.append(QLatin1String("version"), QString(), - QLatin1String("version"), m_version); - test_suiteAtts.append(QLatin1String("SourceOffsetPath"), QString(), - QLatin1String("SourceOffsetPath"), QString()); - test_suiteAtts.append(QLatin1String("ResultOffsetPath"), QString(), - QLatin1String("ResultOffsetPath"), QString()); - test_suiteAtts.append(QLatin1String("XQueryQueryOffsetPath"), QString(), - QLatin1String("XQueryQueryOffsetPath"), QString()); - test_suiteAtts.append(QLatin1String("QueryXQueryOffsetPath"), QString(), - QLatin1String("QueryXQueryOffsetPath"), QString()); - test_suiteAtts.append(QLatin1String("XQueryFileExtension"), QString(), - QLatin1String("XQueryFileExtension"), QString()); - test_suiteAtts.append(QLatin1String("XQueryXFileExtension"), QString(), - QLatin1String("XQueryXFileExtension"), QString()); - - receiver.startPrefixMapping(QString(), Global::xqtsCatalogNS); - receiver.startElement(QLatin1String("test-suite"), test_suiteAtts); - receiver.endPrefixMapping(QString()); - - /* */ - QXmlAttributes test_groupAtts; - test_groupAtts.append(QLatin1String("GeneratedGroupByPatternistSDKRunSuite"), QString(), - QLatin1String("GeneratedGroupByPatternistSDKRunSuite"), QString()); - receiver.startElement(QLatin1String("test-group"), test_groupAtts); - - /* */ - receiver.startElement(QLatin1String("GroupInfo"), test_groupAtts); - - /* */ - receiver.startElement(QLatin1String("title"), test_groupAtts); - receiver.characters(QLatin1String("Contains the test case generated by PatternistSDKRunSuite.")); - - /* */ - receiver.endElement(QLatin1String("title")); - - /* */ - receiver.startElement(QLatin1String("description"), test_groupAtts); - /* */ - receiver.endElement(QLatin1String("description")); - - /* */ - receiver.endElement(QLatin1String("GroupInfo")); - - /* */ - tc->toXML(receiver); - /* */ - - /* */ - receiver.endElement(QLatin1String("test-group")); - - /* */ - receiver.endElement(QLatin1String("test-suite")); -} - -QString TestSuite::version() const -{ - return m_version; -} - -QDate TestSuite::designDate() const -{ - return m_designDate; -} - -void TestSuite::setVersion(const QString &ver) -{ - m_version = ver; -} - -void TestSuite::setDesignDate(const QDate &date) -{ - m_designDate = date; -} - -TestContainer *TestSuite::parent() const -{ - return 0; -} - -// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternsxqts/lib/TestSuite.h b/tests/auto/xmlpatternsxqts/lib/TestSuite.h deleted file mode 100644 index d14dc62..0000000 --- a/tests/auto/xmlpatternsxqts/lib/TestSuite.h +++ /dev/null @@ -1,160 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 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$ -** -****************************************************************************/ - -#ifndef PatternistSDK_TestSuite_H -#define PatternistSDK_TestSuite_H - -#include -#include - -#include "TestContainer.h" - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -class QIODevice; -class QUrl; -class QVariant; - -namespace QPatternistSDK -{ - class TestCase; - class TestSuiteResult; - - /** - * @short Represents a test suite in the W3C XML Query Test Suite format. - * - * TestSuite contains the test suite's test cases and meta data. - * - * @ingroup PatternistSDK - * @author Frans Englich - */ - class Q_PATTERNISTSDK_EXPORT TestSuite : public TestContainer - { - public: - /** - * Describes the type of test suite. - */ - enum SuiteType - { - XQuerySuite, ///< The test suite for XQuery - XsltSuite, ///< The test suite for XSLT - XsdSuite ///< The test suite for XML Schema - }; - - TestSuite(); - - virtual QVariant data(const Qt::ItemDataRole role, int column) const; - - /** - * The version of the catalog test suite. For example, "0.8.0". - */ - QString version() const; - - /** - * When the catalog was designed, last modified. - */ - QDate designDate() const; - - void setVersion(const QString &version); - void setDesignDate(const QDate &version); - - /** - * @return always @c null - */ - virtual TestContainer *parent() const; - - /** - * Creates and returns a pointer to a TestSuite instance, which - * was instantiated from the XQuery Test Suite catalog file @p catalogFile. - * - * If loading went wrong, @c null is returned and @p errorMsg is set with a - * human readable message string. However, @p catalogFile is not validated; - * if the XML file is not valid against the XQTS task force's W3C XML Schema, the - * behavior and result for this function is undefined. - * - * This function blocks. Currently is only local files supported. - */ - static TestSuite *openCatalog(const QUrl &catalogFile, - QString &errorMsg, - const bool useExclusionList, - SuiteType type); - - void toXML(XMLWriter &receiver, TestCase *const tc) const; - - /** - * Evaluates all the test cases in this TestSuite, and returns - * it all in a TestSuiteResult. - */ - TestSuiteResult *runSuite(); - - private: - /** - * Essentially similar to open(const QUrl &, QString &errorMsg), - * with the difference that it takes directly a QIODevice as input, - * as opposed to a file name locating the catalog file to read. - * - * @param input the test suite catalog - * @param fileName this URI is used for resolving relative paths inside - * the catalog file into absolute. - * @param errorMsg if an error occurs, this QString is set to contain the message. - * Whether an error occurred can therefore be determined by checking if this variable - * still is @c null after the call - * @param useExclusionList whether the excludeTestGroups.txt file should be used - * to exclude test groups for this catalog - */ - static TestSuite *openCatalog(QIODevice *input, - QString &errorMsg, - const QUrl &fileName, - const bool useExclusionList, - SuiteType type); - QString m_version; - QDate m_designDate; - }; -} - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif -// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternsxqts/lib/TestSuiteHandler.cpp b/tests/auto/xmlpatternsxqts/lib/TestSuiteHandler.cpp deleted file mode 100644 index 7c687f3..0000000 --- a/tests/auto/xmlpatternsxqts/lib/TestSuiteHandler.cpp +++ /dev/null @@ -1,312 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 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 "qacceltreeresourceloader_p.h" -#include "qnetworkaccessdelegator_p.h" - -#include "Global.h" -#include "TestBaseLine.h" -#include "TestGroup.h" - -#include "TestSuiteHandler.h" - -using namespace QPatternistSDK; - -QNetworkAccessManager s_networkManager; - -TestSuiteHandler::TestSuiteHandler(const QUrl &catalogFile, - const bool useEList) : m_ts(0) - , m_container(0) - , m_tc(0) - , m_baseLine(0) - , m_catalogFile(catalogFile) - , m_exclusionList(readExclusionList(useEList)) - , m_isExcluding(false) -{ - Q_ASSERT(!m_catalogFile.isRelative()); -} - -QStringList TestSuiteHandler::readExclusionList(const bool useExclusionList) const -{ - if(!useExclusionList) - return QStringList(); - - QStringList avoid; - - /* These test groups are for features we don't support. - * - * Originally these were stored in a text file pulled in with Qt resources, but - * it was not possible to get it to link on some HP-UX and Intel-icc platforms. */ - - avoid << "SchemaImport"; // The schema import feature - avoid << "SchemaValidation"; // The validate expression(requires schema import) - avoid << "StaticTyping"; // Pessimistic static typing checking - avoid << "TrivialEmbedding"; // XQueryX inside XQuery - avoid << "XMark"; // We're currently too buggy for running these tests. - - return avoid; -} - -bool TestSuiteHandler::startElement(const QString &namespaceURI, - const QString &localName, - const QString &/*qName*/, - const QXmlAttributes &atts) -{ - if(namespaceURI != Global::xqtsCatalogNS) - return true; - else if(m_isExcluding) - { - if(localName == QLatin1String("test-group")) - { - m_testGroupName.push(atts.value(QLatin1String("name"))); - return true; - } - else - return true; - } - - /* The elements are handled roughly in the order of highest occurrence in the catalog file. */ - if(localName == QLatin1String("test-case")) - { - XQTSTestCase *const c = new XQTSTestCase( - TestCase::scenarioFromString(atts.value(QLatin1String("scenario"))), m_container); - - c->setName(atts.value(QLatin1String("name"))); - c->setCreator(atts.value(QLatin1String("Creator"))); - c->setIsXPath(Global::readBoolean(atts.value(QLatin1String("is-XPath2")))); - c->setLastModified(QDate::fromString(atts.value(QLatin1String("version-drop")), Qt::ISODate)); - Q_ASSERT(c->lastModified().isNull() || c->lastModified().isValid()); - - m_currentQueryPath = m_queryOffset.resolved(QUrl(atts.value(QLatin1String("FilePath")))); - m_currentBaselinePath = m_baselineOffset.resolved(QUrl(atts.value(QLatin1String("FilePath")))); - - m_container->appendChild(c); - m_tc = c; - } - else if(localName == QLatin1String("query")) - { - m_tc->setQueryPath(m_currentQueryPath.resolved(atts.value(QLatin1String("name")) + - m_xqueryFileExtension)); - } - else if(localName == QLatin1String("input-file") || - localName == QLatin1String("input-URI")) - { - m_currentInputVariable = atts.value(QLatin1String("variable")); - } - else if(localName == QLatin1String("output-file")) - { - m_baseLine = new TestBaseLine(TestBaseLine::identifierFromString(atts.value(QLatin1String("compare")))); - } - else if(localName == QLatin1String("expected-error")) - { - m_baseLine = new TestBaseLine(TestBaseLine::ExpectedError); - } - else if(localName == QLatin1String("test-group")) - { - m_testGroupName.push(atts.value(QLatin1String("name"))); - - if(m_exclusionList.contains(m_testGroupName.top())) - { - /* Ok, this group is supposed to be excluded, we don't - * insert it into the tree. */ - m_isExcluding = true; - return true; - } - else - { - Q_ASSERT(m_container); - TestGroup *const newGroup = new TestGroup(m_container); - m_container->appendChild(newGroup); - m_container = newGroup; - } - } - else if(localName == QLatin1String("source")) - { - m_sourceMap.insert(atts.value(QLatin1String("ID")), - m_sourceOffset.resolved(QUrl(atts.value(QLatin1String("FileName"))))); - } - else if(localName == QLatin1String("test-suite")) - { - m_ts = new TestSuite(); - m_ts->setVersion(atts.value(QLatin1String("version"))); - m_ts->setDesignDate(QDate::fromString(atts.value(QLatin1String("CatalogDesignDate")), Qt::ISODate)); - Q_ASSERT(m_ts->designDate().isValid()); - m_container = m_ts; - - m_xqueryFileExtension = atts.value(QLatin1String("XQueryFileExtension")); - m_queryOffset = m_catalogFile.resolved(atts.value(QLatin1String("XQueryQueryOffsetPath"))); - m_baselineOffset = m_catalogFile.resolved(atts.value(QLatin1String("ResultOffsetPath"))); - m_sourceOffset = m_catalogFile.resolved(atts.value(QLatin1String("SourceOffsetPath"))); - } - else if(localName == QLatin1String("input-query")) - { - m_tcSourceInputs.insert(atts.value(QLatin1String("variable")), - ExternalSourceLoader::VariableValue(m_currentQueryPath.resolved(atts.value(QLatin1String("name")) + m_xqueryFileExtension), - ExternalSourceLoader::Query)); - } - - return true; -} - -bool TestSuiteHandler::endElement(const QString &namespaceURI, - const QString &localName, - const QString &/*qName*/) -{ - if(namespaceURI != Global::xqtsCatalogNS) - return true; - - if(m_isExcluding) - { - if(localName == QLatin1String("test-group")) - { - const QString myName(m_testGroupName.pop()); - - if(m_exclusionList.contains(myName)) - { - /* This test-group is being excluded and now we're exiting from it. */ - m_isExcluding = false; - } - } - - return true; - } - - /* The elements are handled roughly in the order of highest occurrence in the catalog file. */ - if(localName == QLatin1String("description")) - { - if(m_tc) - { - /* We're inside a , so the belongs - * to the test-case. */ - m_tc->setDescription(m_ch.simplified()); - } - else - m_container->setDescription(m_ch.simplified()); - } - else if(localName == QLatin1String("test-case")) - { - Q_ASSERT(m_tc->baseLines().count() >= 1); - Q_ASSERT(m_resourceLoader); - m_tc->setExternalVariableLoader(QPatternist::ExternalVariableLoader::Ptr - (new ExternalSourceLoader(m_tcSourceInputs, - m_resourceLoader))); - m_tcSourceInputs.clear(); - - if(!m_contextItemSource.isEmpty()) - { - m_tc->setContextItemSource(QUrl(m_sourceMap.value(m_contextItemSource))); - m_contextItemSource.clear(); - } - - m_tc = 0; - } - else if(localName == QLatin1String("output-file")) - { - m_baseLine->setDetails(m_currentBaselinePath.resolved(m_ch).toString()); - m_tc->addBaseLine(m_baseLine); - } - else if(localName == QLatin1String("input-file")) - { - m_tcSourceInputs.insert(m_currentInputVariable, ExternalSourceLoader::VariableValue(m_sourceMap.value(m_ch), - ExternalSourceLoader::Document)); - } - else if(localName == QLatin1String("expected-error")) - { - m_baseLine->setDetails(m_ch); - m_tc->addBaseLine(m_baseLine); - } - else if(localName == QLatin1String("title")) - { - /* A bit dangerous, the only element with name title in the vocabulary - * is the the child of GroupInfo */ - m_container->setTitle(m_ch.simplified()); - } - else if(localName == QLatin1String("test-group")) - { - m_testGroupName.pop(); - Q_ASSERT(m_container); - m_container = static_cast(m_container->parent()); - Q_ASSERT(m_container); - } - else if(localName == QLatin1String("test-suite")) - { - Q_ASSERT(m_container); - m_container = static_cast(m_container->parent()); - } - else if(localName == QLatin1String("sources")) - { - const QPatternist::NetworkAccessDelegator::Ptr networkDelegator(new QPatternist::NetworkAccessDelegator(&s_networkManager, &s_networkManager)); - - m_resourceLoader = QPatternist::ResourceLoader::Ptr(new QPatternist::AccelTreeResourceLoader(Global::namePool(), - networkDelegator)); - - const ExternalSourceLoader::SourceMap::const_iterator end(m_sourceMap.constEnd()); - ExternalSourceLoader::SourceMap::const_iterator it(m_sourceMap.constBegin()); - - for(; it != end; ++it) - m_resourceLoader->announceDocument(it.value(), QPatternist::ResourceLoader::WillUse); - } - else if(localName == QLatin1String("input-URI")) - { - m_tcSourceInputs.insert(m_currentInputVariable, ExternalSourceLoader::VariableValue(m_sourceMap.value(m_ch), - ExternalSourceLoader::URI)); - } - else if(localName == QLatin1String("contextItem")) - m_contextItemSource = m_ch; - - return true; -} - -bool TestSuiteHandler::characters(const QString &ch) -{ - m_ch = ch; - return true; -} - -TestSuite *TestSuiteHandler::testSuite() const -{ - return m_ts; -} - -// vim: et:ts=4:sw=4:sts=4 - diff --git a/tests/auto/xmlpatternsxqts/lib/TestSuiteHandler.h b/tests/auto/xmlpatternsxqts/lib/TestSuiteHandler.h deleted file mode 100644 index 76156c0..0000000 --- a/tests/auto/xmlpatternsxqts/lib/TestSuiteHandler.h +++ /dev/null @@ -1,169 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 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$ -** -****************************************************************************/ - -#ifndef PatternistSDK_TestSuiteHandler_H -#define PatternistSDK_TestSuiteHandler_H - -#include -#include -#include - -#include "ExternalSourceLoader.h" -#include "TestSuite.h" -#include "XQTSTestCase.h" - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -namespace QPatternistSDK -{ - class TestBaseLine; - - /** - * @short Creates a TestSuite from the XQuery Test Suite catalog, - * represented as a SAX stream. - * - * The created TestSuite can be retrieved via testSuite(). - * - * @note TestSuiteHandler assumes the XML is valid by having been validated - * against the W3C XML Schema. It have no safety checks for that the XML format - * is correct but is hard coded for it. Thus, the behavior is undefined if - * the XML is invalid. - * - * @ingroup PatternistSDK - * @author Frans Englich - */ - class Q_PATTERNISTSDK_EXPORT TestSuiteHandler : public QXmlDefaultHandler - { - public: - /** - * @param catalogFile the URI for the catalog file being parsed. This - * URI is used for creating absolute URIs for files mentioned in - * the catalog with relative URIs. - * @param useExclusionList whether excludeTestGroups.txt should be used to ignore - * test groups when loading - */ - TestSuiteHandler(const QUrl &catalogFile, - const bool useExclusionList); - virtual bool characters(const QString &ch); - - virtual bool endElement(const QString &namespaceURI, - const QString &localName, - const QString &qName); - virtual bool startElement(const QString &namespaceURI, - const QString &localName, - const QString &qName, - const QXmlAttributes &atts); - - virtual TestSuite *testSuite() const; - - private: - QStringList readExclusionList(const bool useExclusionList) const; - - TestSuite * m_ts; - TestContainer * m_container; - XQTSTestCase * m_tc; - TestBaseLine * m_baseLine; - QString m_ch; - const QUrl m_catalogFile; - - /** - * The extension of XQuery files. For example, ".xq" - */ - QString m_xqueryFileExtension; - - /** - * The base URI for where the XQuery query files are found. - * It is absolute, resolved against catalogFile. - */ - QUrl m_queryOffset; - - QUrl m_baselineOffset; - QUrl m_sourceOffset; - QUrl m_currentQueryPath; - QUrl m_currentBaselinePath; - - /** - * In the XQTSCatalog.xml, each source file in each test is referred to - * by a key, which can be fully looked up in the @c sources element. This QHash - * maps the keys to absolute URIs pointing to the source files. - */ - ExternalSourceLoader::SourceMap m_sourceMap; - - ExternalSourceLoader::VariableMap m_tcSourceInputs; - - QPatternist::ResourceLoader::Ptr m_resourceLoader; - - /** - * The current value of input-file/\@variable/. - */ - QString m_currentInputVariable; - - /** - * The names of the test groups we're excluding. - */ - const QStringList m_exclusionList; - - /** - * This is set when we're inside a test-group that we're excluding. - */ - bool m_isExcluding; - - /** - * The names of the test groups. - */ - QStack m_testGroupName; - - /** - * Holds the content of the current input-URI element. - */ - QString m_inputURI; - QString m_contextItemSource; - }; -} - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif -// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternsxqts/lib/TestSuiteResult.cpp b/tests/auto/xmlpatternsxqts/lib/TestSuiteResult.cpp deleted file mode 100644 index 4e81859..0000000 --- a/tests/auto/xmlpatternsxqts/lib/TestSuiteResult.cpp +++ /dev/null @@ -1,173 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 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 "Global.h" -#include "XMLWriter.h" - -#include "TestSuiteResult.h" - -using namespace QPatternistSDK; - -TestSuiteResult::TestSuiteResult(const QString &testSuiteVersion, - const QDate &runDate, - const TestResult::List &results) : m_testSuiteVersion(testSuiteVersion), - m_runDate(runDate), - m_results(results) -{ -} - -TestSuiteResult::~TestSuiteResult() -{ - qDeleteAll(m_results); -} - -void TestSuiteResult::toXML(XMLWriter &receiver) const -{ - /* If this data needs to be configurable in someway(say, another - * XML format is supported), then break out the info into getters(alternatively, combined - * with setters, or that the class is subclassed), and access the getters instead. - */ - const QString organizationName (QLatin1String("K Desktop Environment(KDE)")); - const QString organizationWebsite (QLatin1String("http://www.kde.org/")); - const QString submittorName (QLatin1String("Frans Englich")); - const QString submittorEmail (QLatin1String("frans.englich@nokia.com")); - const QString implementationVersion (QLatin1String("0.1")); - const QString implementationName (QLatin1String("Patternist")); - const QString implementationDescription (QLatin1String( - "Patternist is an implementation written in C++ " - "and with the Qt/KDE libraries. " - "It is licensed under GNU LGPL and part of KDE, " - "the K Desktop Environment.")); - - /* Not currently serialized: - * - - * - - * - - */ - - receiver.startDocument(); - /* */ - receiver.startPrefixMapping(QString(), Global::xqtsResultNS); - receiver.startElement(QLatin1String("test-suite-result")); - receiver.endPrefixMapping(QString()); - - /* */ - QXmlAttributes implementationAtts; - implementationAtts.append(QLatin1String("name"), QString(), - QLatin1String("name"), implementationName); - implementationAtts.append(QLatin1String("version"), QString(), - QLatin1String("version"), implementationVersion); - receiver.startElement(QLatin1String("implementation"), implementationAtts); - - /* */ - QXmlAttributes organizationAtts; - organizationAtts.append(QLatin1String("name"), QString(), - QLatin1String("name"), organizationName); - organizationAtts.append(QLatin1String("website"), QString(), - QLatin1String("website"), organizationWebsite); - receiver.startElement(QLatin1String("organization"), organizationAtts); - - /* */ - receiver.endElement(QLatin1String("organization")); - - /* */ - QXmlAttributes submittorAtts; - submittorAtts.append(QLatin1String("name"), QString(), QLatin1String("name"), submittorName); - submittorAtts.append(QLatin1String("email"), QString(), QLatin1String("email"), submittorEmail); - receiver.startElement(QLatin1String("submittor"), submittorAtts); - - /* */ - receiver.endElement(QLatin1String("submittor")); - - /* */ - receiver.startElement(QLatin1String("description")); - - /*

*/ - receiver.startElement(QLatin1String("p")); - receiver.characters(implementationDescription); - - /*

*/ - receiver.endElement(QLatin1String("p")); - /*
*/ - receiver.endElement(QLatin1String("description")); - - /*
*/ - receiver.endElement(QLatin1String("implementation")); - - /* */ - receiver.startElement(QLatin1String("syntax")); - receiver.characters(QLatin1String(QLatin1String("XQuery"))); - - /* */ - receiver.endElement(QLatin1String("syntax")); - - /* */ - QXmlAttributes test_runAtts; - test_runAtts.append(QLatin1String("dateRun"), QString(), QLatin1String("dateRun"), m_runDate.toString(QLatin1String("yyyy-MM-dd"))); - receiver.startElement(QLatin1String("test-run"), test_runAtts); - - /* */ - QXmlAttributes test_suiteAtts; - test_suiteAtts.append(QLatin1String("version"), QString(), QLatin1String("version"), m_testSuiteVersion); - receiver.startElement(QLatin1String("test-suite"), test_suiteAtts); - - /* */ - receiver.endElement(QLatin1String("test-suite")); - - /* */ - receiver.endElement(QLatin1String("test-run")); - - /* Serialize the TestResults: tons of test-case elements. */ - const TestResult::List::const_iterator end(m_results.constEnd()); - TestResult::List::const_iterator it(m_results.constBegin()); - - for(; it != end; ++it) - (*it)->toXML(receiver); - - /*
*/ - receiver.endElement(QLatin1String("test-suite-result")); - receiver.endDocument(); -} - -// vim: et:ts=4:sw=4:sts=4 - diff --git a/tests/auto/xmlpatternsxqts/lib/TestSuiteResult.h b/tests/auto/xmlpatternsxqts/lib/TestSuiteResult.h deleted file mode 100644 index 491c2b2..0000000 --- a/tests/auto/xmlpatternsxqts/lib/TestSuiteResult.h +++ /dev/null @@ -1,93 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 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$ -** -****************************************************************************/ - -#ifndef PatternistSDK_TestSuiteResult_H -#define PatternistSDK_TestSuiteResult_H - -#include -#include - -#include "TestResult.h" - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -namespace QPatternistSDK -{ - /** - * @short A collection of TestResult instances. - * - * A TestSuiteResult gathers all TestResult instances, and provides - * the toXML() function which serializes it all into a XQuery Test Suite - * result file, conforming to XQTSResult.xsd. - * - * @ingroup PatternistSDK - * @author Frans Englich - */ - class Q_PATTERNISTSDK_EXPORT TestSuiteResult - { - public: - ~TestSuiteResult(); - - TestSuiteResult(const QString &testSuiteVersion, - const QDate &runDate, - const TestResult::List &results); - - /** - * Serializes the test results this TestSuiteResult represents, - * into XQTS test-suite-result document, conformant to XQTSCatalog.xsd. - */ - void toXML(XMLWriter &receiver) const; - - private: - const QString m_testSuiteVersion; - const QDate m_runDate; - const TestResult::List m_results; - }; -} - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif -// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternsxqts/lib/TreeItem.cpp b/tests/auto/xmlpatternsxqts/lib/TreeItem.cpp deleted file mode 100644 index b34262d..0000000 --- a/tests/auto/xmlpatternsxqts/lib/TreeItem.cpp +++ /dev/null @@ -1,62 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 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 "TestContainer.h" - -#include "TreeItem.h" - -using namespace QPatternistSDK; - -int TreeItem::row() const -{ - const TreeItem *const p = parent(); - - if(p) - { - /* The const_cast makes it possible for QPointer's constructor - * to implicitly kick in. */ - return p->children().indexOf(const_cast(this)); - } - else - return -1; -} - -// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternsxqts/lib/TreeItem.h b/tests/auto/xmlpatternsxqts/lib/TreeItem.h deleted file mode 100644 index f5e051f..0000000 --- a/tests/auto/xmlpatternsxqts/lib/TreeItem.h +++ /dev/null @@ -1,114 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 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$ -** -****************************************************************************/ - -#ifndef PatternistSDK_TreeItem_H -#define PatternistSDK_TreeItem_H - -#include - -#include "Global.h" - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -class QVariant; -template class QList; -template class QPointer; - -namespace QPatternistSDK -{ - /** - * @short TreeItem is a node in a hierachial structure and is used together - * with TreeModel. - * - * TreeItem is abstract base class. Instances of sub-classes of TreeItem - * can be used with TreeModel in order to use hierarchial data in Qt's - * model/view framework. - * - * TreeItem is a QObject in order to be able to be used with QPointer. - * - * @author Frans Englich - * @see TreeModel - * @ingroup PatternistSDK - */ - class Q_PATTERNISTSDK_EXPORT TreeItem : public QObject - { - Q_OBJECT - public: - typedef QList > List; - - virtual ~TreeItem() {} - virtual void appendChild(TreeItem *item) = 0; - virtual TreeItem *child(const unsigned int row) const = 0; - virtual unsigned int childCount() const = 0; - virtual TreeItem *parent() const = 0; - - virtual TreeItem::List children() const = 0; - virtual int columnCount() const = 0; - - /** - * Determines the position among the children of - * this TreeItem's parent. This is done by introspecting the result - * of children(). - */ - int row() const; - - virtual QVariant data(const Qt::ItemDataRole role, int column) const = 0; - - Q_SIGNALS: - /** - * Emitted whenever this item changed. This is used for keeping - * views in synchronization with the item model which houses - * this item. - * - * @param item the item which changed. That is, this TreeItem. - */ - void changed(TreeItem *item); - }; -} - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif -// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternsxqts/lib/TreeModel.cpp b/tests/auto/xmlpatternsxqts/lib/TreeModel.cpp deleted file mode 100644 index e27f8e0..0000000 --- a/tests/auto/xmlpatternsxqts/lib/TreeModel.cpp +++ /dev/null @@ -1,184 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 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 "TestContainer.h" - -#include "TreeModel.h" - -using namespace QPatternistSDK; - -TreeModel::TreeModel(const QStringList columnData, - QObject *p) : QAbstractItemModel(p), - m_root(0), - m_columnData(columnData) -{ -} - -TreeModel::~TreeModel() -{ -} - -QVariant TreeModel::data(const QModelIndex &idx, int role) const -{ - if(!idx.isValid()) - return QVariant(); - - TreeItem *item = static_cast(idx.internalPointer()); - Q_ASSERT(item); - - return item->data(static_cast(role), idx.column()); -} - -QVariant TreeModel::headerData(int section, Qt::Orientation orientation, int role) const -{ - if(orientation == Qt::Horizontal && role == Qt::DisplayRole) - return m_columnData.value(section); - - return QVariant(); -} - -void TreeModel::childChanged(TreeItem *item) -{ - if (item) { - const QModelIndex index = createIndex(item->row(), 0, item); - dataChanged(index, index); - } else { - layoutChanged(); - } -} - -QModelIndex TreeModel::index(int row, int column, const QModelIndex &p) const -{ - const int c = columnCount(p); - - if(row < 0 || column < 0 || column >= c) - return QModelIndex(); - - TreeItem *parentItem; - - if(p.isValid()) - parentItem = static_cast(p.internalPointer()); - else - parentItem = m_root; - - if(!parentItem) - return QModelIndex(); - - TreeItem *childItem = parentItem->child(row); - - if(childItem) - return createIndex(row, column, childItem); - else - return QModelIndex(); -} - -QModelIndex TreeModel::parent(const QModelIndex &idx) const -{ - if(!idx.isValid()) - return QModelIndex(); - - TreeItem *childItem = static_cast(idx.internalPointer()); - Q_ASSERT(childItem); - TreeItem *parentItem = childItem->parent(); - - if(!parentItem || parentItem == m_root) - return QModelIndex(); - - Q_ASSERT(parentItem); - return createIndex(parentItem->row(), 0, parentItem); -} - -Qt::ItemFlags TreeModel::flags(const QModelIndex &idx) const -{ - /* Not sure about this code. */ - if(!idx.isValid()) - return Qt::ItemFlags(); - - return Qt::ItemIsEnabled | Qt::ItemIsSelectable; -} - -int TreeModel::rowCount(const QModelIndex &p) const -{ - if(p.column() > 0) - return 0; - - const TreeItem *parentItem; - - if(p.isValid()) - parentItem = static_cast(p.internalPointer()); - else - { - if(m_root) - parentItem = m_root; - else - return 0; - } - - return parentItem->childCount(); -} - -int TreeModel::columnCount(const QModelIndex &p) const -{ - if(p.isValid()) - return static_cast(p.internalPointer())->columnCount(); - else - return m_columnData.count(); -} - -TreeItem *TreeModel::root() const -{ - return m_root; -} - -void TreeModel::setRoot(TreeItem *r) -{ - TreeItem *const oldRoot = m_root; - m_root = r; - - if(m_root) - connect(r, SIGNAL(changed(TreeItem *)), SLOT(childChanged(TreeItem *))); - reset(); /* Notify views that we have radically changed. */ - delete oldRoot; -} - -// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternsxqts/lib/TreeModel.h b/tests/auto/xmlpatternsxqts/lib/TreeModel.h deleted file mode 100644 index 1d8ea72..0000000 --- a/tests/auto/xmlpatternsxqts/lib/TreeModel.h +++ /dev/null @@ -1,110 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 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$ -** -****************************************************************************/ - -#ifndef PatternistSDK_TreeModel_H -#define PatternistSDK_TreeModel_H - -#include -#include -#include -#include - -#include "Global.h" - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -namespace QPatternistSDK -{ - class TreeItem; - - /** - * @short TreeItem is a generic QAbstractItemModel tailored for - * representing hierarchial data. - * - * TreeModel is an item model in Qt's model/view framework. Its - * data consists of TreeItem instances. - * - * @see TreeItem - * @ingroup PatternistSDK - * @author Frans Englich - */ - class Q_PATTERNISTSDK_EXPORT TreeModel : public QAbstractItemModel - { - Q_OBJECT - public: - TreeModel(const QStringList columnData, QObject *parent); - virtual ~TreeModel(); - - virtual QVariant data(const QModelIndex &index, int role) const; - virtual Qt::ItemFlags flags(const QModelIndex &index) const; - virtual QVariant headerData(int section, - Qt::Orientation orientation, - int role = Qt::DisplayRole) const; - virtual QModelIndex index(int row, - int column, - const QModelIndex &parent = QModelIndex()) const; - virtual QModelIndex parent(const QModelIndex &index) const; - virtual int rowCount(const QModelIndex &parent = QModelIndex()) const; - virtual int columnCount(const QModelIndex &parent = QModelIndex()) const; - - TreeItem *root() const; - /** - * Sets @p root to the new root, and deletes the old. - */ - void setRoot(TreeItem *root); - - protected Q_SLOTS: - void childChanged(TreeItem *child); - - private: - QPointer m_root; - const QStringList m_columnData; - }; -} - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif -// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternsxqts/lib/Worker.cpp b/tests/auto/xmlpatternsxqts/lib/Worker.cpp deleted file mode 100644 index 0121099..0000000 --- a/tests/auto/xmlpatternsxqts/lib/Worker.cpp +++ /dev/null @@ -1,258 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 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 -#include - -#include "ExitCode.h" - -#include "Worker.h" - -using namespace QPatternistSDK; - -const char *const Worker::m_indent = " "; - -Worker::Worker(QEventLoop &ev, - const QFileInfo &baseline, - const QFileInfo &result) : m_finishedCount(0) - , m_baselineFile(baseline) - , m_resultFile(result) - , m_eventLoop(ev) -{ -} - -void Worker::list(QTextStream &out, const QString &msg, QStringList &list) -{ - Q_ASSERT(!msg.isEmpty()); - - if(list.isEmpty()) - return; - - list.sort(); /* Make it pretty, and easy to read. */ - - out << msg << ":\n"; - - const QStringList::const_iterator end(list.constEnd()); - QStringList::const_iterator it(list.constBegin()); - - for(; it != end; ++it) - out << m_indent << qPrintable(*it) << '\n'; -} - -static inline int count(const ResultThreader::Hash &list, const TestResult::Status stat) -{ - const ResultThreader::Hash::const_iterator end(list.constEnd()); - ResultThreader::Hash::const_iterator it(list.constBegin()); - int result = 0; - - for(; it != end; ++it) - { - if(it.value() == stat) - ++result; - } - - return result; -} - -void Worker::threadFinished() -{ - ++m_finishedCount; - Q_ASSERT(m_finishedCount == 1 || m_finishedCount == 2); - - const ResultThreader *const handler = static_cast(sender()); - Q_ASSERT(handler); - - switch(handler->type()) - { - case ResultThreader::Baseline: - { - m_baseline = handler->result(); - break; - } - case ResultThreader::Result: - m_result = handler->result(); - } - - if(m_finishedCount == 1) /* One thread's missing. */ - return; - - /* Ok, both threads have now finished, and we got their results in m_result and m_baseline. */ - - /* No matter how this function exits, we want to delete this Worker. */ - deleteLater(); - - ResultThreader::Hash::const_iterator itA(m_result.constBegin()); - ResultThreader::Hash::const_iterator itB(m_baseline.constBegin()); - const ResultThreader::Hash::const_iterator endA(m_result.constEnd()); - const ResultThreader::Hash::const_iterator endB(m_baseline.constEnd()); - const int baselineCount = m_baseline.count(); - const int resultCount = m_result.count(); - - /* If you want useful output, change the QTextStream to use stderr. */ - //QTextStream err(stderr); - QByteArray out; - QTextStream err(&out); - - if(resultCount < baselineCount) - { - err << qPrintable(QString(QLatin1String("WARNING: Test result contains %1 reports, " - "but the baseline contains %2, a DECREASE " - "of %3 tests.\n")) - .arg(resultCount) - .arg(baselineCount) - .arg(resultCount - baselineCount)); - } - else if(resultCount > baselineCount) - { - err << qPrintable(QString(QLatin1String("NOTE: The number of tests run is more than what " - "the baseline specifies. Run was %1 test cases, the " - "baseline specifies %2; an increase of %3 tests.\n")) - .arg(resultCount) - .arg(baselineCount) - .arg(resultCount - baselineCount)); - } - - for(; itA != endA; ++itA) - { - const TestResult::Status result = itA.value(); - const TestResult::Status baseline = m_baseline.value(itA.key()); - - if(result == baseline) /* We have no change. */ - { - if(result == TestResult::NotTested) - m_notTested.append(itA.key()); - else - continue; - } - else if(baseline == TestResult::Pass && result == TestResult::Fail) - m_unexpectedFailures.append(itA.key()); - else if(baseline == TestResult::Fail && result == TestResult::Pass) - m_unexpectedPasses.append(itA.key()); - } - - list(err, QLatin1String("Not tested"), m_notTested); - list(err, QLatin1String("Unexpected failures"), m_unexpectedFailures); - list(err, QLatin1String("Unexpected passes"), m_unexpectedPasses); - - err << "SUMMARY:\n"; - typedef QPair Info; - typedef QList InfoList; - InfoList info; - - const int totFail = count(m_result, TestResult::Fail); - const int totPass = count(m_result, TestResult::Pass); - const int total = resultCount; - const int notTested = m_notTested.count(); - const int percentage = int((static_cast(totPass) / total) * 100); - - Q_ASSERT_X(percentage >= 0 && percentage <= 100, Q_FUNC_INFO, - qPrintable(QString(QLatin1String("Percentage was: %1")).arg(percentage))); - - info.append(Info(QLatin1String("Total"), total)); - info.append(Info(QLatin1String("Failures"), totFail)); - info.append(Info(QLatin1String("Passes"), totPass)); - info.append(Info(QLatin1String("Not tested"), notTested)); - info.append(Info(QLatin1String("Pass percentage(%)"), percentage)); - info.append(Info(QLatin1String("Unexpected failures"), m_unexpectedFailures.count())); - info.append(Info(QLatin1String("Unexpected passes"), m_unexpectedPasses.count())); - - const InfoList::const_iterator end(info.constEnd()); - InfoList::const_iterator it(info.constBegin()); - - /* List the statistics nicely in a row with padded columns. */ - for(; it != end; ++it) - { - const QString result((((*it).first) + QLatin1Char(':')).leftJustified(22, QLatin1Char(' '))); - err << m_indent << qPrintable(result) << (*it).second << '\n'; - } - - if(!m_unexpectedFailures.isEmpty()) - { - err << "FAILURE: Regressions discovered, baseline was not updated.\n"; - err.flush(); - QTextStream(stderr) << out; - m_eventLoop.exit(ExitCode::Regression); - return; - } - else if(m_unexpectedPasses.isEmpty() && baselineCount == resultCount) - { - err << "Result was identical to the baseline, baseline was not updated.\n"; - m_eventLoop.exit(ExitCode::Success); - return; - } - - /* Ok, we got unexpected successes and no regressions: let's update the baseline. */ - - QFile resultFile(m_resultFile.absoluteFilePath()); - - /* Remove the old file, otherwise QFile::copy() will fail. */ - QDir baselineDir(m_baselineFile.absolutePath()); - baselineDir.remove(m_baselineFile.fileName()); - - if(resultFile.copy(m_baselineFile.absoluteFilePath())) - { - /* Give a detailed message of what's going on. */ - if(resultCount > baselineCount) - err << "More tests was run than specified in the baseline, updating the baseline.\n"; - else - err << "Improvement, the baseline was updated.\n"; - - /* We actually flag this as an error, because the new baseline must be submitted. */ - err.flush(); - QTextStream(stderr) << out; - m_eventLoop.exit(ExitCode::Regression); - return; - } - else - { - err << qPrintable(QString(QLatin1String("Encountered error when updating " - "the baseline: %1\n")) - .arg(resultFile.errorString())); - err.flush(); - QTextStream(stderr) << out; - m_eventLoop.exit(ExitCode::WriteError); - return; - } -} - -// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternsxqts/lib/Worker.h b/tests/auto/xmlpatternsxqts/lib/Worker.h deleted file mode 100644 index b3d7ae2..0000000 --- a/tests/auto/xmlpatternsxqts/lib/Worker.h +++ /dev/null @@ -1,100 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 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$ -** -****************************************************************************/ - -#ifndef PatternistSDK_Worker_H -#define PatternistSDK_Worker_H - -#include -#include -#include -#include - -#include "ResultThreader.h" - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -class QEventLoop; - -namespace QPatternistSDK -{ - /** - * @short Gets notified when the ResultThreader threads are - * finished, and output summaries and adjusts a baseline. - * - * @author Frans Englich - * @ingroup PatternistSDK - */ - class Q_PATTERNISTSDK_EXPORT Worker : public QObject - { - Q_OBJECT - public: - Worker(QEventLoop &e, - const QFileInfo &baseline, - const QFileInfo &result); - - public Q_SLOTS: - void threadFinished(); - - private: - static inline void list(QTextStream &out, const QString &msg, QStringList &list); - - qint8 m_finishedCount; - const QFileInfo m_baselineFile; - const QFileInfo m_resultFile; - ResultThreader::Hash m_result; - ResultThreader::Hash m_baseline; - ResultThreader::Hash m_summary; - QStringList m_unexpectedPasses; - QStringList m_unexpectedFailures; - QStringList m_notTested; - QEventLoop & m_eventLoop; - static const char *const m_indent; - }; -} - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif -// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternsxqts/lib/XMLWriter.cpp b/tests/auto/xmlpatternsxqts/lib/XMLWriter.cpp deleted file mode 100644 index 60a5344..0000000 --- a/tests/auto/xmlpatternsxqts/lib/XMLWriter.cpp +++ /dev/null @@ -1,669 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 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 -#include -#include -#include -#include - -#include "XMLWriter.h" - -/* Issues: - * - Switch to Qt's d-pointer semantics, if in Qt. - * - Remove namespace(PatternistSDK), and change name, if in Qt. - * - Is it really necessary to pass the tag name to endElement()? - * - Could it be of interest to let the user control the encoding? Are those cases common - * enough to justify support in Qt? Using anything but UTF-8 or UTF-16 - * means asking for trouble, from an interoperability perspective. - */ - -/* Design rationalis, comments: - * - * - The class is called XMLWriter to harvest familarity by being consistent with - * Java's XMLWriter class. If XMLWriter is moved to Qt, the name QXmlWriter is perhaps suitable. - * - The class does not handle indentation because the "do one thing well"-principle is - * in use. XMLWriter should be fast and not assume a certain idea of indentation. Indentation - * should be implemented in a standalone QXmlContentHandler that performs the indentation and - * "has a" QXmlContentHandler which it in addition calls, and by that proxying/piping another - * QXmlContentHandler(which most likely is an XMLWriter). Thus, achieving a modularized, - * flexibly approach to indentation. A reason is also that indentation is very subjective. - * The indenter class should probably be called XMLIndenter/QXmlIndenter. - * - It could be of interest to implement QXmlDTDHandler such that it would be possible to serialize - * DTDs. Must be done before BC becomes significant. - * - I think the most valuable of this class is its Q_ASSERT tests. Many programmers have severe problems - * producing XML, and the tests helps them catching their mistakes. They therefore promote - * interoperability. Do not remove them. If any are wrong, fix them instead. - */ - -using namespace QPatternistSDK; - -/** - * A namespace binding, prefix/namespace URI. - */ -typedef QPair NSBinding; -typedef QList NSBindingList; - -#ifdef QT_NO_DEBUG -# define DEBUG_CODE(code) -#else -# define DEBUG_CODE(code) code -#endif - -class XMLWriter::Private -{ -public: - inline Private(QIODevice *devP) : insideCDATA(false), - addModificationNote(false), - dev(devP) - { - hasContentStack.push(true); - } - -#ifdef QT_NO_DEBUG - inline void validateQName(const QString &) const - { - } - - inline void verifyNS(const QString &) const - { - } -#else - /** - * Simple test of that @p name is an acceptable QName. - */ - inline void validateQName(const QString &name) - { - Q_ASSERT_X(!name.isEmpty(), Q_FUNC_INFO, - "An XML name cannot be empty."); - Q_ASSERT_X(!name.endsWith(QLatin1Char(':')), Q_FUNC_INFO, - "An XML name cannot end with a colon(QLatin1Char(':'))."); - Q_ASSERT_X(!name.contains(QRegExp(QLatin1String("[ \t\n]"))), Q_FUNC_INFO, - "An XML name cannot contain whitespace."); - } - - /** - * Ensures that the prefix of @p qName is declared. - */ - inline void verifyNS(const QString &qName) const - { - const QString prefix(qName.left(qName.indexOf(QLatin1Char(':')))); - - if(qName.contains(QLatin1Char(':')) && prefix != QLatin1String("xml")) - { - bool foundPrefix = false; - const QStack::const_iterator end(namespaceTracker.constEnd()); - QStack::const_iterator it(namespaceTracker.constBegin()); - - for(; it != end; ++it) - { - const NSBindingList::const_iterator lend((*it).constEnd()); - NSBindingList::const_iterator lit((*it).constBegin()); - - for(; lit != lend; ++it) - { - if((*lit).first == prefix) - { - foundPrefix = true; - break; - } - } - if(foundPrefix) - break; - } - - Q_ASSERT_X(foundPrefix, "XMLWriter::startElement()", - qPrintable(QString::fromLatin1("The prefix %1 is not declared. All prefixes " - "except 'xml' must be declared.").arg(prefix))); - } - } -#endif - - inline QString escapeElementContent(const QString &ch) - { - const int l = ch.length(); - QString retval; - - for(int i = 0; i != l; ++i) - { - const QChar c(ch.at(i)); - - if(c == QLatin1Char(QLatin1Char('&'))) - retval += QLatin1String("&"); - else if(c == QLatin1Char(QLatin1Char('<'))) - retval += QLatin1String("<"); - else - retval += c; - } - - return retval; - } - - inline QString escapeAttributeContent(const QString &ch) - { - const int l = ch.length(); - QString retval; - - for(int i = 0; i != l; ++i) - { - const QChar c(ch.at(i)); - - /* We don't have to escape '\'' because we use '\"' as attribute delimiter. */ - if(c == QLatin1Char('&')) - retval += QLatin1String("&"); - else if(c == QLatin1Char('<')) - retval += QLatin1String("<"); - else if(c == QLatin1Char('"')) - retval += QLatin1String("""); - else - retval += c; - } - - return retval; - } - - inline QString escapeCDATAContent(const QString &ch) - { - const int l = ch.length(); - QString retval; - qint8 atEnd = 0; - - for(int i = 0; i != l; ++i) - { - const QChar c(ch.at(i)); - - /* Escape '>' if in "]]>" */ - if(c == QLatin1Char(']')) - { - if(atEnd == 0 || atEnd == 1) - ++atEnd; - else - atEnd = 0; - - retval += QLatin1Char(']'); - } - else if(c == QLatin1Char('>')) - { - if(atEnd == 2) - retval += QLatin1String(">"); - else - { - atEnd = 0; - retval += QLatin1Char('>'); - } - } - else - retval += c; - } - - return retval; - } - - /** - * We wrap dev in this function such that we can deploy the Q_ASSERT_X - * macro in each place it's used. - */ - inline QIODevice *device() const - { - Q_ASSERT_X(dev, Q_FUNC_INFO, - "No device specified for XMLWriter; one must be specified with " - "setDevice() or via the constructor before XMLWriter can be used."); - return dev; - } - - /** - * @returns true on success, otherwise false - */ - inline bool serialize(const QString &data) - { - const QByteArray utf8(data.toUtf8()); - - return device()->write(utf8) == utf8.size(); - } - - /** - * @returns true on success, otherwise false - */ - inline bool serialize(const char data) - { - return device()->putChar(data); - } - - /** - * @returns true on success, otherwise false - */ - inline bool serialize(const char *data) - { - return device()->write(data) == qstrlen(data); - } - - inline bool hasElementContent() const - { - return hasContentStack.top(); - } - - inline void handleElement() - { - if(!hasElementContent()) - serialize('>'); - - /* This element is content for the parent. */ - hasContentStack.top() = true; - } - - NSBindingList namespaces; - bool insideCDATA; - bool addModificationNote; - QString msg; - QIODevice *dev; - QStack hasContentStack; - QString errorString; - DEBUG_CODE(QStack tags;) - DEBUG_CODE(QStack namespaceTracker;) -}; - -/** - * Reduces complexity. The empty else clause is for avoiding mess when macro - * is used in the 'then' branch of an if clause, which is followed by an else clause. - */ -#define serialize(string) if(!d->serialize(string)) \ - { \ - d->errorString = d->device()->errorString(); \ - return false; \ - } \ - else do {} while (false) - -XMLWriter::XMLWriter(QIODevice *outStream) : d(new Private(outStream)) -{ -} - -XMLWriter::~XMLWriter() -{ - delete d; -} - -bool XMLWriter::startDocument() -{ - if(!device()->isOpen() && !device()->open(QIODevice::WriteOnly)) - return false; - - if(d->addModificationNote) - { - if(d->msg.isNull()) - { - d->msg = QString::fromLatin1("NOTE: This file was automatically generated " - "by %1 at %2. All changes to this file will be lost.") - .arg(QCoreApplication::instance()->applicationName(), - QDateTime::currentDateTime().toString()); - } - if(!comment(d->msg)) - return false; - - serialize('\n'); - } - - serialize(QLatin1String("\n")); - - return true; -} - -bool XMLWriter::startElement(const QString &/*namespaceURI*/, - const QString &/*localName*/, - const QString &qName, - const QXmlAttributes &atts) -{ - return startElement(qName, atts); -} - -bool XMLWriter::startElement(const QString &qName, - const QXmlAttributes &atts) -{ - Q_ASSERT_X(!d->insideCDATA, Q_FUNC_INFO, - "Only characters() can be received when inside CDATA."); - Q_ASSERT_X(!qName.startsWith(QLatin1String("xmlns")), Q_FUNC_INFO, - "startElement should not be used for declaring prefixes, " - "use startPrefixMapping() for that."); - - d->validateQName(qName); - d->verifyNS(qName); - - d->handleElement(); - - serialize('<'); - serialize(qName); - - DEBUG_CODE(d->tags.push(qName)); - DEBUG_CODE(d->namespaceTracker.push(d->namespaces)); - - /* Add namespace declarations. */ - const NSBindingList::const_iterator end(d->namespaces.constEnd()); - NSBindingList::const_iterator it(d->namespaces.constBegin()); - - for(; it != end; ++it) - { - if((*it).first.isEmpty()) - serialize(" xmlns="); - else - { - serialize(" xmlns:"); - serialize((*it).first); - serialize('='); - } - - serialize('"'); - serialize(d->escapeElementContent((*it).second)); - serialize('"'); - } - d->namespaces.clear(); - - const int c = atts.count(); - - /* Serialize attributes. */ - for(int i = 0; i != c; ++i) - { - d->validateQName(atts.qName(i)); - d->verifyNS(atts.qName(i)); - - serialize(' '); - serialize(atts.qName(i)); - serialize("=\""); - serialize(d->escapeAttributeContent(atts.value(i))); - serialize('"'); - } - - d->hasContentStack.push(false); - return true; -} - -bool XMLWriter::endElement(const QString &/*namespaceURI*/, - const QString &/*localName*/, - const QString &qName) -{ - return endElement(qName); -} - -bool XMLWriter::endElement(const QString &qName) -{ - Q_ASSERT_X(!d->insideCDATA, Q_FUNC_INFO, - "Only characters() can be received when inside CDATA."); - Q_ASSERT_X(d->tags.pop() == qName, Q_FUNC_INFO, - "The element tags are not balanced, the produced XML is invalid."); - - DEBUG_CODE(d->namespaceTracker.pop()); - - /* "this" element is content for our parent, so ensure hasElementContent is true. */ - - if(d->hasElementContent()) - { - serialize(QLatin1String("'); - } - else - serialize(QLatin1String("/>")); - - d->hasContentStack.pop(); - - return true; -} - -bool XMLWriter::startPrefixMapping(const QString &prefix, const QString &uri) -{ - Q_ASSERT_X(!d->insideCDATA, Q_FUNC_INFO, - "Only characters() can be received when inside CDATA."); - Q_ASSERT_X(prefix.toLower() != QLatin1String("xml") || - (prefix.toLower() == QLatin1String("xml") && - (uri == QLatin1String("http://www.w3.org/TR/REC-xml-names/") || - uri.isEmpty())), - Q_FUNC_INFO, - "The prefix 'xml' can only be bound to the namespace " - "\"http://www.w3.org/TR/REC-xml-names/\"."); - Q_ASSERT_X(prefix.toLower() != QLatin1String("xml") && - uri != QLatin1String("http://www.w3.org/TR/REC-xml-names/"), - Q_FUNC_INFO, - "The namespace \"http://www.w3.org/TR/REC-xml-names/\" can only be bound to the " - "\"xml\" prefix."); - - d->namespaces.append(qMakePair(prefix, uri)); - return true; -} - -bool XMLWriter::processingInstruction(const QString &target, - const QString &data) -{ - Q_ASSERT_X(target.toLower() != QLatin1String("xml"), Q_FUNC_INFO, - "A processing instruction cannot have the name xml in any " - "capitalization, because it is reserved."); - Q_ASSERT_X(!data.contains(QLatin1String("?>")), Q_FUNC_INFO, - "The content of a processing instruction cannot contain the string \"?>\"."); - Q_ASSERT_X(!d->insideCDATA, "XMLWriter::processingInstruction()", - "Only characters() can be received when inside CDATA."); - - d->handleElement(); - - serialize(QLatin1String("")); - return true; -} - -bool XMLWriter::characters(const QString &ch) -{ - Q_ASSERT_X(d->tags.count() >= 1, Q_FUNC_INFO, - "Text nodes can only appear inside elements(no elements sent)."); - d->handleElement(); - - if(d->insideCDATA) - serialize(d->escapeCDATAContent(ch)); - else - serialize(d->escapeElementContent(ch)); - - return true; -} - -bool XMLWriter::comment(const QString &ch) -{ - Q_ASSERT_X(!d->insideCDATA, Q_FUNC_INFO, - "Only characters() can be received when inside CDATA."); - Q_ASSERT_X(!ch.contains(QLatin1String("--")), Q_FUNC_INFO, - "XML comments may not contain double-hyphens(\"--\")."); - Q_ASSERT_X(!ch.endsWith(QLatin1Char('-')), Q_FUNC_INFO, - "XML comments cannot end with a hyphen, \"-\"(add a space, for example)."); - /* A comment starting with "")); - - return true; -} - -bool XMLWriter::startCDATA() -{ - Q_ASSERT_X(d->insideCDATA, Q_FUNC_INFO, - "startCDATA() has already been called."); - Q_ASSERT_X(d->tags.count() >= 1, Q_FUNC_INFO, - "CDATA sections can only appear inside elements(no elements sent)."); - d->insideCDATA = true; - serialize(QLatin1String("insideCDATA = false; - serialize("]]>"); - return true; -} - -bool XMLWriter::startDTD(const QString &name, - const QString &publicId, - const QString &systemId) -{ - Q_ASSERT_X(!d->insideCDATA, Q_FUNC_INFO, - "Only characters() can be received when inside CDATA."); - Q_ASSERT_X(!name.isEmpty(), Q_FUNC_INFO, - "The DOCTYPE name cannot be empty."); - Q_ASSERT_X(d->tags.isEmpty() && d->namespaces.isEmpty(), Q_FUNC_INFO, - "No content such as namespace declarations or elements can be serialized " - "before the DOCTYPE declaration, the XML is invalid."); - Q_ASSERT_X(!publicId.contains(QLatin1Char('"')), Q_FUNC_INFO, - "The PUBLIC ID cannot contain quotes('\"')."); - Q_ASSERT_X(!systemId.contains(QLatin1Char('"')), Q_FUNC_INFO, - "The SYSTEM ID cannot contain quotes('\"')."); - - serialize(QLatin1String("tags.isEmpty() && d->namespaces.isEmpty(), Q_FUNC_INFO, - "Content such as namespace declarations or elements cannot occur inside " - "the DOCTYPE declaration, the XML is invalid."); - serialize(QLatin1String(">\n")); - return true; -} - -bool XMLWriter::startEntity(const QString &) -{ - return true; -} - -bool XMLWriter::endEntity(const QString &) -{ - return true; -} - -void XMLWriter::setMessage(const QString &msg) -{ - d->msg = msg; -} - -QString XMLWriter::modificationMessage() const -{ - return d->msg; -} - -bool XMLWriter::endDocument() -{ - Q_ASSERT_X(d->tags.isEmpty(), Q_FUNC_INFO, - "endDocument() called before all elements were closed with endElement()."); - d->device()->close(); - return true; -} - -QString XMLWriter::errorString() const -{ - return d->errorString; -} - -bool XMLWriter::ignorableWhitespace(const QString &ch) -{ - return characters(ch); -} - -bool XMLWriter::endPrefixMapping(const QString &) -{ - /* Again, should we do something with this? */ - return true; -} - -bool XMLWriter::skippedEntity(const QString &) -{ - return true; -} - -void XMLWriter::setDocumentLocator(QXmlLocator *) -{ -} - -QIODevice *XMLWriter::device() const -{ - return d->dev; -} - -void XMLWriter::setDevice(QIODevice *dev) -{ - d->dev = dev; -} - -void XMLWriter::setAddMessage(const bool toggle) -{ - d->addModificationNote = toggle; -} - -bool XMLWriter::addModificationMessage() const -{ - return d->addModificationNote; -} - -#undef serialize -// vim: et:ts=4:sw=4:sts=4 - diff --git a/tests/auto/xmlpatternsxqts/lib/XMLWriter.h b/tests/auto/xmlpatternsxqts/lib/XMLWriter.h deleted file mode 100644 index 2b629bb..0000000 --- a/tests/auto/xmlpatternsxqts/lib/XMLWriter.h +++ /dev/null @@ -1,403 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 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$ -** -****************************************************************************/ - -#ifndef PatternistSDK_XMLWriter_H -#define PatternistSDK_XMLWriter_H - -#include "Global.h" - -#include -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -class QIODevice; - -namespace QPatternistSDK -{ - /** - * @short Serializes a stream of SAX events into XML, sent to a QIODevice. - * - * XMLWriter is a fast and simple XML serializer which takes care of - * all the low level details of well-formedness and character escaping, allowing - * the user to focus on higher level issues and increasing the chances of producing - * valid, interoperable XML. - * - * The content XMLWriter produces is sent to a QIODevice, which is either - * specified in XMLWriter's constructor or via setDevice(). If writing to - * the device fails, the content functions such as startElement() returns @c false. - * - * XMLWriter sub-classes QXmlContentHandler meaning it can serialize content - * from any code that produces SAX events. The class can also be used manually, - * by calling startElement(), endCDATA(), and so forth. - * - * XMLWriter cannot be used to serialize multiple documents. One instance per - * document must be used. - * - * XMLWriter takes care of escaping content into character references as necessary. Thus, - * it should not be done manually. In fact, it would most likely - * result in invalid XML or an unintended result. XMLWriter always serializes into UTF-8. - * - * When compiled in debug mode, XMLWriter contains several tests that helps - * ensuring that XMLWriter produces valid XML. Some of these tests ensures that: - * - * - The @c xmlns and @c xml prefixes are used properly - * - Content of comments and processing instructions is valid - * - Element, attribute and DOCTYPE names are sensible - * - Elements are properly nested and balanced - * - To some extent that things occur in the proper order. For example, that - * the document type definition isn't added inside an element - * - That namespaces prefixes are declared - * - * Not triggering XMLWriter's tests does not guarantee valid XML is produced, - * but they do help catching common mistakes and some of the corner cases in the - * specifications. When XMLWriter is compiled in release mode, these tests are not enabled - * and the error handling in effect is concerning writing to the QIODevice. - * - * Often it is of interest to add a note at the beginning of the file communicating - * it is auto-generated. setMessage() and setAddMessage() provides - * a convenient way of doing that. - * - * Namespace declarations are added with startPrefixMapping(), not by sending attributes - * with name xmlns:* to startElement(). - * - * @see HOWTO Avoid Being - * Called a Bozo When Producing XML - * @see Extensible Markup - * Language (XML) 1.0 (Third Edition) - * @see Namespaces in XML - * @todo Replace this class with QXmlStreamWriter - * @author Frans Englich - * @ingroup PatternistSDK - */ - class Q_PATTERNISTSDK_EXPORT XMLWriter : public QXmlContentHandler - , public QXmlLexicalHandler - { - public: - /** - * Creates a XMLWriter which serializes its received events - * to @p outStream. - * - * @note XMLWriter does not claim ownership of @p outStream. Thus, - * @p outStream may not be destroyed as long as - * this XMLWriter instance uses it. - */ - XMLWriter(QIODevice *outStream = 0); - - virtual ~XMLWriter(); - - /** - * @returns @c true if opening the output device succeeds, otherwise @c false - */ - virtual bool startDocument(); - - /** - * @returns @c false if failure occurs in writing to the QIODevice, otherwise - * @c true - */ - virtual bool characters(const QString &ch); - - /** - * Starts an element with name @p qName and attributes @p atts. The prefix - * in @p qName must first be declared with startPrefixMapping(), if it has one. - * - * A call to startElement() must always at some point be balanced with a call - * to endElement(). - * - * To declare namespaces, don't put attributes with name xmlns:* in @p atts, - * but use startPrefixMapping(). - */ - virtual bool startElement(const QString &qName, const QXmlAttributes &atts = QXmlAttributes()); - - /** - * - * Behaves essentially as startElement(const QString &qName, const QXmlAttributes &atts). This - * function is used in conjunction with other SAX classes. - * - * The call: - * - * @code - * startElement(QString(), QString(), qName, atts); - * @endcode - * - * is equivalent to: - * - * @code - * startElement(qName, atts); - * @endcode - * - * @p namespaceURI and @p localName are not used. This function is - * used in conjunction with other SAX classes. - * - * @returns @c false if failure occurs in writing to the QIODevice, otherwise - * @c true - */ - virtual bool startElement(const QString &namespaceURI, - const QString &localName, - const QString &qName, - const QXmlAttributes &atts); - - /** - * Signals the end of an element with name @p qName. @p qName must - * be supplied. - * - * Calls to startElement() and endElement() must always be balanced. - * - * @returns @c false if failure occurs in writing to the QIODevice, otherwise - * @c true - */ - virtual bool endElement(const QString &qName); - - /** - * Behaves essentially as endElement(const QString &qName). This function - * is used when XMLWriter is used in SAX code. - * - * @p namespaceURI and @p localName are not used. - * - * The call: - * - * @code - * endElement(QString(), QString(), qName); - * @endcode - * - * is equivalent to: - * - * @code - * endElement(qName); - * @endcode - * - * @returns @c false if failure occurs in writing to the QIODevice, otherwise - * @c true - */ - virtual bool endElement(const QString &namespaceURI, - const QString &localName, - const QString &qName); - - /** - * A description of an error if it occurred. This is typically - * QIODevice::errorString(). If no error has occurred, an empty - * string is returned. - */ - virtual QString errorString() const; - - /** - * Starts a CDATA section. Content sent with characters() will not be escaped - * except for ">" if occurring in "]]>". - * - * @returns @c false if failure occurs in writing to the QIODevice, otherwise - * @c true - */ - virtual bool startCDATA(); - - /** - * @returns @c false if failure occurs in writing to the QIODevice, otherwise - * @c true - */ - virtual bool endCDATA(); - - /** - * Creates a document type definition. - * - * For example, the code snippet: - * - * @code - * writer.startDTD("html", "-//W3C//DTD XHTML 1.0 Strict//EN", - * "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"); - * writer.endDTD(); - * @endcode - * - * would create: - * @verbatim - -@endverbatim - * - * @note A system identifier must always be specified, but a public identifier may - * be left out. - * - * A call to startDTD() must be followed by a call to endDTD(). - */ - virtual bool startDTD(const QString &name, - const QString &publicId, - const QString &systemId); - - /** - * Apart from closing the DTD, an new line is also added at end. - */ - virtual bool endDTD(); - - /** - * Creates a processing instruction by name @p target, and content - * @p data. - * - * @returns @c false if failure occurs in writing to the QIODevice, otherwise - * @c true - */ - virtual bool processingInstruction(const QString &target, - const QString &data); - - /** - * Declares a namespace which maps @p prefix to @p namespaceURI. For example, the call: - * - * @code - * startPrefixMapping("xhtml", "http://www.w3.org/1999/xhtml"); - * @endcode - * - * would result in: - * - * @code - * xmlns="http://www.w3.org/1999/xhtml" - * @endcode - */ - virtual bool startPrefixMapping(const QString &prefix, - const QString &namespaceURI); - - /** - * Creates a comment with content @p ch. @p ch is escaped, there's - * no need to do it manually. For example, calling comment() with @p ch - * set to "my comment", results in "" in the output. - * - * @note if @p ch contains double hyphen("--"), the produced XML will - * not be well formed. - * - * @returns @c false if failure occurs in writing to the QIODevice, otherwise - * @c true - */ - virtual bool comment(const QString &ch); - - virtual bool startEntity(const QString &name); - virtual bool endEntity(const QString &name); - - /** - * Sets the message which is added as a comment if addModificationMessage() - * is set to @c true. If no message is specified and addModificationMessage() - * is set to @c true, a default message is used. - * - * @see modificationMessage(), setAddMessage() - */ - virtual void setMessage(const QString &msg); - - /** - * The message that is added at the beginning of the XML events - * in a comment node. If no modificationMessage is set via modificationMessage(), - * and addModificationMessage is set to @c true, this message will be used: - * "NOTE: This file was automatically generated by [the application name] at - * [the current date time]. All changes to this file will be lost." - * - * @see setMessage() - */ - virtual QString modificationMessage() const; - - /** - * Closes the QIODevice XMLWriter writes to. - */ - virtual bool endDocument(); - - /** - * Serializes @p ch as if it was sent to characters(). - * - * @returns @c false if failure occurs in writing to the QIODevice, otherwise - * @c true - */ - virtual bool ignorableWhitespace(const QString &ch); - - /** - * This function is not used by XMLWriter, but is implemented - * in order to satisfy QXmlContentHandler's interface. - */ - virtual bool endPrefixMapping(const QString &prefix); - - /** - * This function is not used by XMLWriter, but is implemented - * in order to satisfy QXmlContentHandler's interface. - */ - virtual bool skippedEntity(const QString &name); - - /** - * This function is not used by XMLWriter, but is implemented - * in order to satisfy QXmlContentHandler's interface. - */ - virtual void setDocumentLocator(QXmlLocator *); - - /** - * @returns the device XMLWriter writes its output to. - * XMLWriter does not own the device. - */ - virtual QIODevice *device() const; - - /** - * Sets the QIODevice XMLWriter writes to, to @p device. A device must be specified - * either via this function or in the constructor before XMLWriter is used. - * - * XMLWriter does not claim ownership of @p device. - */ - virtual void setDevice(QIODevice *device); - - /** - * Determines whether the modification message should be inserted as a comment - * before the document element. The message returned by modificationMessage() is used. - * - * If @p toggle is @c true, the message will be added, otherwise not. - */ - virtual void setAddMessage(const bool toggle); - - /** - * Tells whether a modification message will be added. - * - * @see setAddMessage(), modificationMessage() - */ - virtual bool addModificationMessage() const; - - private: - Q_DISABLE_COPY(XMLWriter) - - class Private; - Private *d; - }; -} - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif -// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternsxqts/lib/XQTSTestCase.cpp b/tests/auto/xmlpatternsxqts/lib/XQTSTestCase.cpp deleted file mode 100644 index 6a8645b..0000000 --- a/tests/auto/xmlpatternsxqts/lib/XQTSTestCase.cpp +++ /dev/null @@ -1,286 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 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 -#include -#include - -#include "XQTSTestCase.h" - -using namespace QPatternistSDK; -using namespace QPatternist; - -XQTSTestCase::XQTSTestCase(const Scenario scen, - TreeItem *p, - const QXmlQuery::QueryLanguage lang) : m_isXPath(false) - , m_scenario(scen) - , m_parent(p) - , m_lang(lang) -{ -} - -XQTSTestCase::~XQTSTestCase() -{ - qDeleteAll(m_baseLines); -} - -QVariant XQTSTestCase::data(const Qt::ItemDataRole role, int column) const -{ - if(role == Qt::DisplayRole) - { - if(column == 0) - return title(); - - const TestResult *const tr = testResult(); - if(!tr) - { - if(column == 1) - return TestResult::displayName(TestResult::NotTested); - else - return QString(); - } - const TestResult::Status status = tr->status(); - - switch(column) - { - case 1: - return status == TestResult::Pass ? QString(QChar::fromLatin1('1')) - : QString(QChar::fromLatin1('0')); - case 2: - return status == TestResult::Fail ? QString(QChar::fromLatin1('1')) - : QString(QChar::fromLatin1('0')); - default: - return QString(); - } - } - - if(role != Qt::BackgroundRole) - return QVariant(); - - const TestResult *const tr = testResult(); - - if(!tr) - { - if(column == 0) - return Qt::yellow; - else - return QVariant(); - } - - const TestResult::Status status = tr->status(); - - if(status == TestResult::NotTested || status == TestResult::Unknown) - return Qt::yellow; - - switch(column) - { - case 1: - return status == TestResult::Pass ? Qt::green : QVariant(); - case 2: - return status == TestResult::Fail ? Qt::red : QVariant(); - default: - return QVariant(); - } -} - -QString XQTSTestCase::sourceCode(bool &ok) const -{ - QFile file(m_queryPath.toLocalFile()); - - QString err; - - if(!file.exists()) - err = QString::fromLatin1("Error: %1 does not exist.").arg(file.fileName()); - else if(!QFileInfo(file.fileName()).isFile()) - err = QString::fromLatin1("Error: %1 is not a file, cannot display it.").arg(file.fileName()); - else if(!file.open(QIODevice::ReadOnly)) - err = QString::fromLatin1("Error: Could not open %1. Likely a permission error.") - .arg(file.fileName()); - - if(err.isNull()) /* No errors. */ - { - ok = true; - /* Scary, we assume the query is stored in UTF-8. */ - return QString::fromUtf8(file.readAll()); - } - else - { - ok = false; - return err; - } -} - -int XQTSTestCase::columnCount() const -{ - return 2; -} - -void XQTSTestCase::addBaseLine(TestBaseLine *line) -{ - m_baseLines.append(line); -} - -QString XQTSTestCase::name() const -{ - return m_name; -} - -QString XQTSTestCase::creator() const -{ - return m_creator; -} - -QString XQTSTestCase::description() const -{ - return m_description; -} - -QDate XQTSTestCase::lastModified() const -{ - return m_lastModified; -} - -bool XQTSTestCase::isXPath() const -{ - return m_isXPath; -} - -TestCase::Scenario XQTSTestCase::scenario() const -{ - return m_scenario; -} - -void XQTSTestCase::setName(const QString &n) -{ - m_name = n; -} - -void XQTSTestCase::setCreator(const QString &ctor) -{ - m_creator = ctor; -} - -void XQTSTestCase::setDescription(const QString &descriptionP) -{ - m_description = descriptionP; -} - -void XQTSTestCase::setLastModified(const QDate &date) -{ - m_lastModified = date; -} - -void XQTSTestCase::setIsXPath(const bool isXPathP) -{ - m_isXPath = isXPathP; -} - -void XQTSTestCase::setQueryPath(const QUrl &uri) -{ - m_queryPath = uri; -} - -TreeItem *XQTSTestCase::parent() const -{ - return m_parent; -} - -QString XQTSTestCase::title() const -{ - return m_name; -} - -TestBaseLine::List XQTSTestCase::baseLines() const -{ - Q_ASSERT_X(!m_baseLines.isEmpty(), Q_FUNC_INFO, - qPrintable(QString::fromLatin1("The test %1 has no base lines, it should have at least one.").arg(name()))); - return m_baseLines; -} - -QUrl XQTSTestCase::testCasePath() const -{ - return m_queryPath; -} - -void XQTSTestCase::setExternalVariableLoader(const QPatternist::ExternalVariableLoader::Ptr &loader) -{ - m_externalVariableLoader = loader; -} - -QPatternist::ExternalVariableLoader::Ptr XQTSTestCase::externalVariableLoader() const -{ - return m_externalVariableLoader; -} - -void XQTSTestCase::setContextItemSource(const QUrl &uri) -{ - m_contextItemSource = uri; -} - -QUrl XQTSTestCase::contextItemSource() const -{ - return m_contextItemSource; -} - -QXmlQuery::QueryLanguage XQTSTestCase::language() const -{ - return m_lang; -} - -void XQTSTestCase::setParent(TreeItem *const p) -{ - m_parent = p; -} - -void XQTSTestCase::setInitialTemplateName(const QXmlName &name) -{ - m_initialTemplateName = name; -} - -QXmlName XQTSTestCase::initialTemplateName() const -{ - return m_initialTemplateName; -} - -// vim: et:ts=4:sw=4:sts=4 - diff --git a/tests/auto/xmlpatternsxqts/lib/XQTSTestCase.h b/tests/auto/xmlpatternsxqts/lib/XQTSTestCase.h deleted file mode 100644 index 8872b32..0000000 --- a/tests/auto/xmlpatternsxqts/lib/XQTSTestCase.h +++ /dev/null @@ -1,149 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 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$ -** -****************************************************************************/ - -#ifndef PatternistSDK_XQTSTestCase_H -#define PatternistSDK_XQTSTestCase_H - -#include -#include -#include - -#include "qexternalvariableloader_p.h" - -#include "TestBaseLine.h" -#include "TestCase.h" - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -namespace QPatternistSDK -{ - /** - * @short Represents a test case in a test suite in the XML Query Test Suite. - * - * TestCase is a memory representation of a test case, and maps - * to the @c test-case element in the XQuery Test Suite test - * case catalog. - * - * @ingroup PatternistSDK - * @author Frans Englich - */ - class Q_PATTERNISTSDK_EXPORT XQTSTestCase : public TestCase - { - public: - XQTSTestCase(const Scenario scen, TreeItem *parent, - const QXmlQuery::QueryLanguage lang = QXmlQuery::XQuery10); - virtual ~XQTSTestCase(); - - /** - * The identifier, the name of the test. For example, "Literals034". - * The name of a test case must be unique. - */ - virtual QString name() const; - virtual QString creator() const; - virtual QString description() const; - /** - * @returns the query inside the file, specified by testCasePath(). Loading - * of the file is not cached in order to avoid complications. - * @param ok is set to @c false if loading the query file fails - */ - virtual QString sourceCode(bool &ok) const; - virtual QUrl testCasePath() const; - virtual QDate lastModified() const; - - bool isXPath() const; - - /** - * What kind of test case this is, what kind of scenario it takes part - * of. For example, whether the test case should evaluate normally or fail. - */ - Scenario scenario() const; - - void setCreator(const QString &creator); - void setLastModified(const QDate &date); - void setDescription(const QString &description); - void setIsXPath(const bool isXPath); - void setName(const QString &name); - void setQueryPath(const QUrl &uri); - void setContextItemSource(const QUrl &uri); - void addBaseLine(TestBaseLine *lines); - void setInitialTemplateName(const QXmlName &name); - - virtual TreeItem *parent() const; - - virtual QVariant data(const Qt::ItemDataRole role, int column) const; - - virtual QString title() const; - virtual TestBaseLine::List baseLines() const; - - virtual int columnCount() const; - - void setExternalVariableLoader(const QPatternist::ExternalVariableLoader::Ptr &loader); - virtual QPatternist::ExternalVariableLoader::Ptr externalVariableLoader() const; - virtual QUrl contextItemSource() const; - virtual QXmlQuery::QueryLanguage language() const; - void setParent(TreeItem *const parent); - virtual QXmlName initialTemplateName() const; - - private: - QString m_name; - QString m_creator; - QString m_description; - QUrl m_queryPath; - bool m_isXPath; - QDate m_lastModified; - const Scenario m_scenario; - TreeItem * m_parent; - TestBaseLine::List m_baseLines; - QPatternist::ExternalVariableLoader::Ptr m_externalVariableLoader; - QUrl m_contextItemSource; - QXmlQuery::QueryLanguage m_lang; - QXmlName m_initialTemplateName; - }; -} - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif -// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternsxqts/lib/XSDTSTestCase.cpp b/tests/auto/xmlpatternsxqts/lib/XSDTSTestCase.cpp deleted file mode 100644 index 3cbb681..0000000 --- a/tests/auto/xmlpatternsxqts/lib/XSDTSTestCase.cpp +++ /dev/null @@ -1,375 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the autotests 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 -#include -#include - -#include "XSDTSTestCase.h" - -#include "qxmlschema.h" -#include "qxmlschemavalidator.h" - -using namespace QPatternistSDK; -using namespace QPatternist; - -XSDTSTestCase::XSDTSTestCase(const Scenario scen, TreeItem *p, TestType testType) - : m_scenario(scen) - , m_parent(p) - , m_testType(testType) -{ -} - -XSDTSTestCase::~XSDTSTestCase() -{ - qDeleteAll(m_baseLines); -} - -TestResult::List XSDTSTestCase::execute(const ExecutionStage, TestSuite*) -{ - ErrorHandler errHandler; - ErrorHandler::installQtMessageHandler(&errHandler); - - TestResult::List retval; - TestResult::Status resultStatus = TestResult::Unknown; - QString serialized; - - if (m_testType == SchemaTest) { - executeSchemaTest(resultStatus, serialized, &errHandler); - } else { - executeInstanceTest(resultStatus, serialized, &errHandler); - } - - resultStatus = TestBaseLine::scan(serialized, baseLines()); - Q_ASSERT(resultStatus != TestResult::Unknown); - - m_result = new TestResult(name(), resultStatus, 0, errHandler.messages(), - QPatternist::Item::List(), serialized); - retval.append(m_result); - ErrorHandler::installQtMessageHandler(0); - changed(this); - return retval; -} - -void XSDTSTestCase::executeSchemaTest(TestResult::Status &resultStatus, QString &serialized, QAbstractMessageHandler *handler) -{ - QFile file(m_schemaUri.path()); - if (!file.open(QIODevice::ReadOnly)) { - resultStatus = TestResult::Fail; - serialized = QString(); - return; - } - - QXmlSchema schema; - schema.setMessageHandler(handler); - schema.load(&file, m_schemaUri); - - if (schema.isValid()) { - resultStatus = TestResult::Pass; - serialized = QString::fromLatin1("true"); - } else { - resultStatus = TestResult::Pass; - serialized = QString::fromLatin1("false"); - } -} - -void XSDTSTestCase::executeInstanceTest(TestResult::Status &resultStatus, QString &serialized, QAbstractMessageHandler *handler) -{ - QFile instanceFile(m_instanceUri.path()); - if (!instanceFile.open(QIODevice::ReadOnly)) { - resultStatus = TestResult::Fail; - serialized = QString(); - return; - } - - QXmlSchema schema; - if (m_schemaUri.isValid()) { - QFile file(m_schemaUri.path()); - if (!file.open(QIODevice::ReadOnly)) { - resultStatus = TestResult::Fail; - serialized = QString(); - return; - } - - schema.setMessageHandler(handler); - schema.load(&file, m_schemaUri); - - if (!schema.isValid()) { - resultStatus = TestResult::Pass; - serialized = QString::fromLatin1("false"); - return; - } - } - - QXmlSchemaValidator validator(schema); - validator.setMessageHandler(handler); - - qDebug("check %s", qPrintable(m_instanceUri.path())); - if (validator.validate(&instanceFile, m_instanceUri)) { - resultStatus = TestResult::Pass; - serialized = QString::fromLatin1("true"); - } else { - resultStatus = TestResult::Pass; - serialized = QString::fromLatin1("false"); - } -} - -QVariant XSDTSTestCase::data(const Qt::ItemDataRole role, int column) const -{ - if(role == Qt::DisplayRole) - { - if(column == 0) - return title(); - - const TestResult *const tr = testResult(); - if(!tr) - { - if(column == 1) - return TestResult::displayName(TestResult::NotTested); - else - return QString(); - } - const TestResult::Status status = tr->status(); - - switch(column) - { - case 1: - return status == TestResult::Pass ? QString(QChar::fromLatin1('1')) - : QString(QChar::fromLatin1('0')); - case 2: - return status == TestResult::Fail ? QString(QChar::fromLatin1('1')) - : QString(QChar::fromLatin1('0')); - default: - return QString(); - } - } - - if(role != Qt::BackgroundRole) - return QVariant(); - - const TestResult *const tr = testResult(); - - if(!tr) - { - if(column == 0) - return Qt::yellow; - else - return QVariant(); - } - - const TestResult::Status status = tr->status(); - - if(status == TestResult::NotTested || status == TestResult::Unknown) - return Qt::yellow; - - switch(column) - { - case 1: - return status == TestResult::Pass ? Qt::green : QVariant(); - case 2: - return status == TestResult::Fail ? Qt::red : QVariant(); - default: - return QVariant(); - } -} - -QString XSDTSTestCase::sourceCode(bool &ok) const -{ - QFile file((m_testType == SchemaTest ? m_schemaUri : m_instanceUri).toLocalFile()); - - QString err; - - if(!file.exists()) - err = QString::fromLatin1("Error: %1 does not exist.").arg(file.fileName()); - else if(!QFileInfo(file.fileName()).isFile()) - err = QString::fromLatin1("Error: %1 is not a file, cannot display it.").arg(file.fileName()); - else if(!file.open(QIODevice::ReadOnly)) - err = QString::fromLatin1("Error: Could not open %1. Likely a permission error.") - .arg(file.fileName()); - - if(err.isNull()) /* No errors. */ - { - ok = true; - /* Scary, we assume the query is stored in UTF-8. */ - return QString::fromUtf8(file.readAll()); - } - else - { - ok = false; - return err; - } -} - -int XSDTSTestCase::columnCount() const -{ - return 2; -} - -void XSDTSTestCase::addBaseLine(TestBaseLine *line) -{ - m_baseLines.append(line); -} - -QString XSDTSTestCase::name() const -{ - return m_name; -} - -QString XSDTSTestCase::creator() const -{ - return m_creator; -} - -QString XSDTSTestCase::description() const -{ - return m_description; -} - -QDate XSDTSTestCase::lastModified() const -{ - return m_lastModified; -} - -bool XSDTSTestCase::isXPath() const -{ - return false; -} - -TestCase::Scenario XSDTSTestCase::scenario() const -{ - return m_scenario; -} - -void XSDTSTestCase::setName(const QString &n) -{ - m_name = n; -} - -void XSDTSTestCase::setCreator(const QString &ctor) -{ - m_creator = ctor; -} - -void XSDTSTestCase::setDescription(const QString &descriptionP) -{ - m_description = descriptionP; -} - -void XSDTSTestCase::setLastModified(const QDate &date) -{ - m_lastModified = date; -} - -void XSDTSTestCase::setSchemaUri(const QUrl &uri) -{ - m_schemaUri = uri; -} - -void XSDTSTestCase::setInstanceUri(const QUrl &uri) -{ - m_instanceUri = uri; -} - -TreeItem *XSDTSTestCase::parent() const -{ - return m_parent; -} - -QString XSDTSTestCase::title() const -{ - return m_name; -} - -TestBaseLine::List XSDTSTestCase::baseLines() const -{ - Q_ASSERT_X(!m_baseLines.isEmpty(), Q_FUNC_INFO, - qPrintable(QString::fromLatin1("The test %1 has no base lines, it should have at least one.").arg(name()))); - return m_baseLines; -} - -QUrl XSDTSTestCase::schemaUri() const -{ - return m_schemaUri; -} - -QUrl XSDTSTestCase::instanceUri() const -{ - return m_instanceUri; -} - -void XSDTSTestCase::setContextItemSource(const QUrl &uri) -{ - m_contextItemSource = uri; -} - -QUrl XSDTSTestCase::contextItemSource() const -{ - return m_contextItemSource; -} - -void XSDTSTestCase::setParent(TreeItem *const p) -{ - m_parent = p; -} - -QPatternist::ExternalVariableLoader::Ptr XSDTSTestCase::externalVariableLoader() const -{ - return QPatternist::ExternalVariableLoader::Ptr(); -} - -TestResult *XSDTSTestCase::testResult() const -{ - return m_result; -} - -TestItem::ResultSummary XSDTSTestCase::resultSummary() const -{ - if(m_result) - return ResultSummary(m_result->status() == TestResult::Pass ? 1 : 0, - 1); - - return ResultSummary(0, 1); -} - -// vim: et:ts=4:sw=4:sts=4 - diff --git a/tests/auto/xmlpatternsxqts/lib/XSDTSTestCase.h b/tests/auto/xmlpatternsxqts/lib/XSDTSTestCase.h deleted file mode 100644 index 947687a..0000000 --- a/tests/auto/xmlpatternsxqts/lib/XSDTSTestCase.h +++ /dev/null @@ -1,161 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the autotests 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$ -** -****************************************************************************/ - -#ifndef PatternistSDK_XSDTSTestCase_H -#define PatternistSDK_XSDTSTestCase_H - -#include -#include -#include - -#include "TestBaseLine.h" -#include "TestCase.h" - -QT_BEGIN_HEADER -QT_BEGIN_NAMESPACE - -namespace QPatternistSDK -{ - /** - * @short Represents a test case in a test suite in the XML Query Test Suite. - * - * TestCase is a memory representation of a test case, and maps - * to the @c test-case element in the XQuery Test Suite test - * case catalog. - * - * @ingroup PatternistSDK - * @author Frans Englich - */ - class Q_PATTERNISTSDK_EXPORT XSDTSTestCase : public TestCase - { - public: - enum TestType - { - SchemaTest, - InstanceTest - }; - - XSDTSTestCase(const Scenario scen, TreeItem *parent, TestType testType); - virtual ~XSDTSTestCase(); - - /** - * Executes the test, and returns the result. The returned list - * will always contain exactly one TestResult. - * - * @p stage is ignored when running out-of-process. - */ - virtual TestResult::List execute(const ExecutionStage stage, - TestSuite *ts); - /** - * The identifier, the name of the test. For example, "Literals034". - * The name of a test case must be unique. - */ - virtual QString name() const; - virtual QString creator() const; - virtual QString description() const; - /** - * @returns the query inside the file, specified by testCasePath(). Loading - * of the file is not cached in order to avoid complications. - * @param ok is set to @c false if loading the query file fails - */ - virtual QString sourceCode(bool &ok) const; - virtual QUrl schemaUri() const; - virtual QUrl instanceUri() const; - virtual QUrl testCasePath() const {return QUrl();} - virtual QDate lastModified() const; - - bool isXPath() const; - - /** - * What kind of test case this is, what kind of scenario it takes part - * of. For example, whether the test case should evaluate normally or fail. - */ - Scenario scenario() const; - - void setCreator(const QString &creator); - void setLastModified(const QDate &date); - void setDescription(const QString &description); - void setName(const QString &name); - void setSchemaUri(const QUrl &uri); - void setInstanceUri(const QUrl &uri); - void setTestCasePath(const QUrl & /* uri */) {} - void setContextItemSource(const QUrl &uri); - void addBaseLine(TestBaseLine *lines); - - virtual TreeItem *parent() const; - - virtual QVariant data(const Qt::ItemDataRole role, int column) const; - - virtual QString title() const; - virtual TestBaseLine::List baseLines() const; - - virtual int columnCount() const; - - virtual QUrl contextItemSource() const; - void setParent(TreeItem *const parent); - virtual QPatternist::ExternalVariableLoader::Ptr externalVariableLoader() const; - virtual TestResult *testResult() const; - virtual ResultSummary resultSummary() const; - - private: - void executeSchemaTest(TestResult::Status &resultStatus, QString &serialized, QAbstractMessageHandler *handler); - void executeInstanceTest(TestResult::Status &resultStatus, QString &serialized, QAbstractMessageHandler *handler); - - QString m_name; - QString m_creator; - QString m_description; - QUrl m_schemaUri; - QUrl m_instanceUri; - QDate m_lastModified; - const Scenario m_scenario; - TreeItem * m_parent; - TestBaseLine::List m_baseLines; - QUrl m_contextItemSource; - TestType m_testType; - QPointer m_result; - }; -} - -QT_END_NAMESPACE -QT_END_HEADER - -#endif -// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternsxqts/lib/XSDTestSuiteHandler.cpp b/tests/auto/xmlpatternsxqts/lib/XSDTestSuiteHandler.cpp deleted file mode 100644 index a868d19..0000000 --- a/tests/auto/xmlpatternsxqts/lib/XSDTestSuiteHandler.cpp +++ /dev/null @@ -1,910 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the autotests 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 "qacceltreeresourceloader_p.h" -#include "qnetworkaccessdelegator_p.h" - -#include "Global.h" -#include "TestBaseLine.h" -#include "TestGroup.h" - -#include "XSDTestSuiteHandler.h" -#include "XSDTSTestCase.h" - -using namespace QPatternistSDK; - -extern QNetworkAccessManager s_networkManager; - -XSDTestSuiteHandler::XSDTestSuiteHandler(const QUrl &catalogFile) : m_ts(0) - , m_catalogFile(catalogFile) - , m_inSchemaTest(false) - , m_inInstanceTest(false) - , m_inTestGroup(false) - , m_inDescription(false) - , m_schemaBlacklisted(false) - , m_counter(0) -{ - Q_ASSERT(!m_catalogFile.isRelative()); - m_ts = new TestSuite(); - m_topLevelGroup = new TestGroup(m_ts); - m_topLevelGroup->setTitle("XML Schema Test Suite"); - m_ts->appendChild(m_topLevelGroup); - - // exclude these test cases, as they break our current state machine - m_blackList << QLatin1String("addB099") - << QLatin1String("addB118") - << QLatin1String("elemJ003") - << QLatin1String("elemJ011") - << QLatin1String("elemZ004") - << QLatin1String("elemZ020") - << QLatin1String("groupH021v") - << QLatin1String("groupJ009v") - << QLatin1String("name00101m2") - << QLatin1String("schL5") - << QLatin1String("ste110") - << QLatin1String("stZ007") - << QLatin1String("stZ047") - << QLatin1String("stZ055") - << QLatin1String("addB049") - << QLatin1String("addB068") - << QLatin1String("addB078") - << QLatin1String("addB078A") - << QLatin1String("addB078B") - << QLatin1String("addB167") - << QLatin1String("addB191") - << QLatin1String("isDefault060_2") - << QLatin1String("isDefault069") - << QLatin1String("annotB025") - << QLatin1String("base64Binary_enumeration003_1321") - << QLatin1String("anyURI_a001_1336") - << QLatin1String("anyURI_a001_1336") - << QLatin1String("anyURI_a003_1338") - << QLatin1String("anyURI_a004_1339") - << QLatin1String("anyURI_b004_1354") - << QLatin1String("anyURI_b004_1354") - << QLatin1String("anyURI_b006_1356") - << QLatin1String("QName_length001_1357") - << QLatin1String("QName_length003_1359") - << QLatin1String("QName_minLength003_1362") - << QLatin1String("QName_maxLength001_1364") - << QLatin1String("NOTATION_length001_1372") - << QLatin1String("NOTATION_length003_1374") - << QLatin1String("NOTATION_minLength003_1377") - << QLatin1String("NOTATION_maxLength001_1379") - << QLatin1String("hexBinary003_2069") - << QLatin1String("QName009_2092") - << QLatin1String("dtZ107447_a_2245") - << QLatin1String("elemE001") - << QLatin1String("elemE002") - << QLatin1String("elemE003") - << QLatin1String("elemE004") - << QLatin1String("elemE005") - << QLatin1String("elemT026") - << QLatin1String("elemT027") - << QLatin1String("elemT028") - << QLatin1String("elemT029") - << QLatin1String("elemT054") - << QLatin1String("elemT055") - << QLatin1String("elemT056") - << QLatin1String("elemT057") - << QLatin1String("elemZ006") - << QLatin1String("elemZ007") - << QLatin1String("elemZ026") - << QLatin1String("elemZ027_c") - << QLatin1String("elemZ028c") - << QLatin1String("elemZ028d") - << QLatin1String("elemZ028f1") - << QLatin1String("elemZ028f1") - << QLatin1String("elemZ028f2") - << QLatin1String("elemZ028f2") - << QLatin1String("elemZ028f3") - << QLatin1String("elemZ028f3") - << QLatin1String("elemZ031") - << QLatin1String("errF001") - << QLatin1String("idC019") - << QLatin1String("idL100") - << QLatin1String("idZ011") - << QLatin1String("idZ015") - << QLatin1String("mgO013") - << QLatin1String("particlesA012") - << QLatin1String("particlesA013") - << QLatin1String("particlesA014") - << QLatin1String("particlesA015") - << QLatin1String("particlesHa161") - << QLatin1String("particlesHb008") - << QLatin1String("particlesHb011") - << QLatin1String("particlesIe003") - << QLatin1String("particlesIg003") - << QLatin1String("particlesIg004") - << QLatin1String("particlesJb003") - << QLatin1String("particlesJd003") - << QLatin1String("particlesJf003") - << QLatin1String("particlesJk003") - << QLatin1String("particlesOb001") - << QLatin1String("particlesOb002") - << QLatin1String("particlesOb004") - << QLatin1String("particlesOb008") - << QLatin1String("particlesOb009") - << QLatin1String("particlesOb013") - << QLatin1String("particlesOb018") - << QLatin1String("particlesQ005") - << QLatin1String("particlesS002") - << QLatin1String("particlesT002") - << QLatin1String("particlesT009") - << QLatin1String("particlesT014") - << QLatin1String("particlesV001") - << QLatin1String("particlesV002") - << QLatin1String("particlesV020") - << QLatin1String("particlesZ001") - << QLatin1String("particlesZ005") - << QLatin1String("particlesZ007") - << QLatin1String("particlesZ023") - << QLatin1String("particlesZ024") - << QLatin1String("particlesZ026") - << QLatin1String("particlesZ028") - << QLatin1String("particlesZ033_c") - << QLatin1String("particlesZ033_d") - << QLatin1String("particlesZ033_e") - << QLatin1String("particlesZ033_f") - << QLatin1String("particlesZ033_g") - << QLatin1String("particlesZ034_a1") - << QLatin1String("particlesZ034_a2") - << QLatin1String("particlesZ034_a3") - << QLatin1String("particlesZ034_b") - << QLatin1String("particlesZ035_a") - << QLatin1String("particlesZ035_b") - << QLatin1String("particlesZ036_a") - << QLatin1String("particlesZ036_b1") - << QLatin1String("particlesZ036_b2") - << QLatin1String("particlesZ036_c") -/* - << QLatin1String("reC65") - << QLatin1String("reC66") - << QLatin1String("reC67") - << QLatin1String("reC68") - << QLatin1String("reF58") - << QLatin1String("reG50") - << QLatin1String("reJ11") - << QLatin1String("reJ13") - << QLatin1String("reJ19") - << QLatin1String("reJ21") - << QLatin1String("reJ23") - << QLatin1String("reJ25") - << QLatin1String("reJ29") - << QLatin1String("reJ31") - << QLatin1String("reJ33") - << QLatin1String("reJ35") - << QLatin1String("reJ61") - << QLatin1String("reJ69") - << QLatin1String("reJ75") - << QLatin1String("reJ77") - << QLatin1String("reL98") - << QLatin1String("reL99") - << QLatin1String("reM98") - << QLatin1String("reN99") - << QLatin1String("reS21") - << QLatin1String("reS42") - << QLatin1String("reT63") - << QLatin1String("reT84") - << QLatin1String("reDG2") - << QLatin1String("RegexTest_9") - << QLatin1String("RegexTest_11") - << QLatin1String("RegexTest_14") - << QLatin1String("RegexTest_15") - << QLatin1String("RegexTest_16") - << QLatin1String("RegexTest_17") - << QLatin1String("RegexTest_23") - << QLatin1String("RegexTest_24") - << QLatin1String("RegexTest_25") - << QLatin1String("RegexTest_26") - << QLatin1String("RegexTest_27") - << QLatin1String("RegexTest_28") - << QLatin1String("RegexTest_30") - << QLatin1String("RegexTest_30") - << QLatin1String("RegexTest_33") - << QLatin1String("RegexTest_34") - << QLatin1String("RegexTest_34") - << QLatin1String("RegexTest_43") - << QLatin1String("RegexTest_44") - << QLatin1String("RegexTest_45") - << QLatin1String("RegexTest_46") - << QLatin1String("RegexTest_47") - << QLatin1String("RegexTest_48") - << QLatin1String("RegexTest_49") - << QLatin1String("RegexTest_50") - << QLatin1String("RegexTest_51") - << QLatin1String("RegexTest_52") - << QLatin1String("RegexTest_53") - << QLatin1String("RegexTest_54") - << QLatin1String("RegexTest_55") - << QLatin1String("RegexTest_56") - << QLatin1String("RegexTest_57") - << QLatin1String("RegexTest_57") - << QLatin1String("RegexTest_58") - << QLatin1String("RegexTest_58") - << QLatin1String("RegexTest_65") - << QLatin1String("RegexTest_113") - << QLatin1String("RegexTest_116") - << QLatin1String("RegexTest_119") - << QLatin1String("RegexTest_120") - << QLatin1String("RegexTest_121") - << QLatin1String("RegexTest_141") - << QLatin1String("RegexTest_142") - << QLatin1String("RegexTest_143") - << QLatin1String("RegexTest_145") - << QLatin1String("RegexTest_146") - << QLatin1String("RegexTest_147") - << QLatin1String("RegexTest_148") - << QLatin1String("RegexTest_149") - << QLatin1String("RegexTest_150") - << QLatin1String("RegexTest_151") - << QLatin1String("RegexTest_152") - << QLatin1String("RegexTest_154") - << QLatin1String("RegexTest_155") - << QLatin1String("RegexTest_156") - << QLatin1String("RegexTest_157") - << QLatin1String("RegexTest_158") - << QLatin1String("RegexTest_163") - << QLatin1String("RegexTest_164") - << QLatin1String("RegexTest_165") - << QLatin1String("RegexTest_166") - << QLatin1String("RegexTest_167") - << QLatin1String("RegexTest_168") - << QLatin1String("RegexTest_169") - << QLatin1String("RegexTest_170") - << QLatin1String("RegexTest_171") - << QLatin1String("RegexTest_172") - << QLatin1String("RegexTest_173") - << QLatin1String("RegexTest_174") - << QLatin1String("RegexTest_178") - << QLatin1String("RegexTest_194") - << QLatin1String("RegexTest_194") - << QLatin1String("RegexTest_195") - << QLatin1String("RegexTest_195") - << QLatin1String("RegexTest_196") - << QLatin1String("RegexTest_196") - << QLatin1String("RegexTest_197") - << QLatin1String("RegexTest_198") - << QLatin1String("RegexTest_199") - << QLatin1String("RegexTest_200") - << QLatin1String("RegexTest_200") - << QLatin1String("RegexTest_201") - << QLatin1String("RegexTest_201") - << QLatin1String("RegexTest_202") - << QLatin1String("RegexTest_202") - << QLatin1String("RegexTest_203") - << QLatin1String("RegexTest_204") - << QLatin1String("RegexTest_205") - << QLatin1String("RegexTest_206") - << QLatin1String("RegexTest_207") - << QLatin1String("RegexTest_208") - << QLatin1String("RegexTest_209") - << QLatin1String("RegexTest_209") - << QLatin1String("RegexTest_210") - << QLatin1String("RegexTest_210") - << QLatin1String("RegexTest_211") - << QLatin1String("RegexTest_211") - << QLatin1String("RegexTest_212") - << QLatin1String("RegexTest_213") - << QLatin1String("RegexTest_214") - << QLatin1String("RegexTest_215") - << QLatin1String("RegexTest_216") - << QLatin1String("RegexTest_217") - << QLatin1String("RegexTest_218") - << QLatin1String("RegexTest_220") - << QLatin1String("RegexTest_221") - << QLatin1String("RegexTest_222") - << QLatin1String("RegexTest_226") - << QLatin1String("RegexTest_230") - << QLatin1String("RegexTest_232") - << QLatin1String("RegexTest_233") - << QLatin1String("RegexTest_294") - << QLatin1String("RegexTest_294") - << QLatin1String("RegexTest_295") - << QLatin1String("RegexTest_295") - << QLatin1String("RegexTest_299") - << QLatin1String("RegexTest_300") - << QLatin1String("RegexTest_301") - << QLatin1String("RegexTest_302") - << QLatin1String("RegexTest_303") - << QLatin1String("RegexTest_304") - << QLatin1String("RegexTest_305") - << QLatin1String("RegexTest_306") - << QLatin1String("RegexTest_307") - << QLatin1String("RegexTest_308") - << QLatin1String("RegexTest_309") - << QLatin1String("RegexTest_310") - << QLatin1String("RegexTest_311") - << QLatin1String("RegexTest_312") - << QLatin1String("RegexTest_313") - << QLatin1String("RegexTest_314") - << QLatin1String("RegexTest_315") - << QLatin1String("RegexTest_315") - << QLatin1String("RegexTest_316") - << QLatin1String("RegexTest_316") - << QLatin1String("RegexTest_317") - << QLatin1String("RegexTest_317") - << QLatin1String("RegexTest_440") - << QLatin1String("RegexTest_441") - << QLatin1String("RegexTest_442") - << QLatin1String("RegexTest_443") - << QLatin1String("RegexTest_448") - << QLatin1String("RegexTest_449") - << QLatin1String("RegexTest_450") - << QLatin1String("RegexTest_451") - << QLatin1String("RegexTest_458") - << QLatin1String("RegexTest_464") - << QLatin1String("RegexTest_464") - << QLatin1String("RegexTest_465") - << QLatin1String("RegexTest_469") - << QLatin1String("RegexTest_470") - << QLatin1String("RegexTest_471") - << QLatin1String("RegexTest_472") - << QLatin1String("RegexTest_473") - << QLatin1String("RegexTest_477") - << QLatin1String("RegexTest_478") - << QLatin1String("RegexTest_478") - << QLatin1String("RegexTest_479") - << QLatin1String("RegexTest_480") - << QLatin1String("RegexTest_481") - << QLatin1String("RegexTest_482") - << QLatin1String("RegexTest_482") - << QLatin1String("RegexTest_483") - << QLatin1String("RegexTest_483") - << QLatin1String("RegexTest_484") - << QLatin1String("RegexTest_487") - << QLatin1String("RegexTest_516") - << QLatin1String("RegexTest_516") - << QLatin1String("RegexTest_517") - << QLatin1String("RegexTest_517") - << QLatin1String("RegexTest_518") - << QLatin1String("RegexTest_518") - << QLatin1String("RegexTest_519") - << QLatin1String("RegexTest_519") - << QLatin1String("RegexTest_521") - << QLatin1String("RegexTest_523") - << QLatin1String("RegexTest_524") - << QLatin1String("RegexTest_524") - << QLatin1String("RegexTest_586") - << QLatin1String("RegexTest_587") - << QLatin1String("RegexTest_592") - << QLatin1String("RegexTest_593") - << QLatin1String("RegexTest_594") - << QLatin1String("RegexTest_595") - << QLatin1String("RegexTest_596") - << QLatin1String("RegexTest_597") - << QLatin1String("RegexTest_598") - << QLatin1String("RegexTest_599") - << QLatin1String("RegexTest_600") - << QLatin1String("RegexTest_601") - << QLatin1String("RegexTest_602") - << QLatin1String("RegexTest_603") - << QLatin1String("RegexTest_604") - << QLatin1String("RegexTest_605") - << QLatin1String("RegexTest_648") - << QLatin1String("RegexTest_655") - << QLatin1String("RegexTest_688") - << QLatin1String("RegexTest_696") - << QLatin1String("RegexTest_697") - << QLatin1String("RegexTest_698") - << QLatin1String("RegexTest_700") - << QLatin1String("RegexTest_701") - << QLatin1String("RegexTest_702") - << QLatin1String("RegexTest_703") - << QLatin1String("RegexTest_704") - << QLatin1String("RegexTest_705") - << QLatin1String("RegexTest_706") - << QLatin1String("RegexTest_707") - << QLatin1String("RegexTest_717") - << QLatin1String("RegexTest_718") - << QLatin1String("RegexTest_719") - << QLatin1String("RegexTest_724") - << QLatin1String("RegexTest_725") - << QLatin1String("RegexTest_726") - << QLatin1String("RegexTest_727") - << QLatin1String("RegexTest_728") - << QLatin1String("RegexTest_729") - << QLatin1String("RegexTest_730") - << QLatin1String("RegexTest_731") - << QLatin1String("RegexTest_732") - << QLatin1String("RegexTest_733") - << QLatin1String("RegexTest_743") - << QLatin1String("RegexTest_755") - << QLatin1String("RegexTest_756") - << QLatin1String("RegexTest_761") - << QLatin1String("RegexTest_762") - << QLatin1String("RegexTest_781") - << QLatin1String("RegexTest_782") - << QLatin1String("RegexTest_783") - << QLatin1String("RegexTest_790") - << QLatin1String("RegexTest_791") - << QLatin1String("RegexTest_824") - << QLatin1String("RegexTest_826") - << QLatin1String("RegexTest_827") - << QLatin1String("RegexTest_836") - << QLatin1String("RegexTest_837") - << QLatin1String("RegexTest_841") - << QLatin1String("RegexTest_842") - << QLatin1String("RegexTest_843") - << QLatin1String("RegexTest_844") - << QLatin1String("RegexTest_845") - << QLatin1String("RegexTest_846") - << QLatin1String("RegexTest_847") - << QLatin1String("RegexTest_848") - << QLatin1String("RegexTest_851") - << QLatin1String("RegexTest_852") - << QLatin1String("RegexTest_853") - << QLatin1String("RegexTest_854") - << QLatin1String("RegexTest_855") - << QLatin1String("RegexTest_856") - << QLatin1String("RegexTest_857") - << QLatin1String("RegexTest_861") - << QLatin1String("RegexTest_862") - << QLatin1String("RegexTest_863") - << QLatin1String("RegexTest_864") - << QLatin1String("RegexTest_865") - << QLatin1String("RegexTest_866") - << QLatin1String("RegexTest_870") - << QLatin1String("RegexTest_879") - << QLatin1String("RegexTest_880") - << QLatin1String("RegexTest_888") - << QLatin1String("RegexTest_889") - << QLatin1String("RegexTest_890") - << QLatin1String("RegexTest_891") - << QLatin1String("RegexTest_892") - << QLatin1String("RegexTest_893") - << QLatin1String("RegexTest_894") - << QLatin1String("RegexTest_895") - << QLatin1String("RegexTest_896") - << QLatin1String("RegexTest_897") - << QLatin1String("RegexTest_898") - << QLatin1String("RegexTest_899") - << QLatin1String("RegexTest_900") - << QLatin1String("RegexTest_901") - << QLatin1String("RegexTest_902") - << QLatin1String("RegexTest_903") - << QLatin1String("RegexTest_904") - << QLatin1String("RegexTest_905") - << QLatin1String("RegexTest_906") - << QLatin1String("RegexTest_907") - << QLatin1String("RegexTest_908") - << QLatin1String("RegexTest_909") - << QLatin1String("RegexTest_910") - << QLatin1String("RegexTest_911") - << QLatin1String("RegexTest_912") - << QLatin1String("RegexTest_913") - << QLatin1String("RegexTest_914") - << QLatin1String("RegexTest_915") - << QLatin1String("RegexTest_916") - << QLatin1String("RegexTest_917") - << QLatin1String("RegexTest_918") - << QLatin1String("RegexTest_919") - << QLatin1String("RegexTest_920") - << QLatin1String("RegexTest_921") - << QLatin1String("RegexTest_922") - << QLatin1String("RegexTest_923") - << QLatin1String("RegexTest_924") - << QLatin1String("RegexTest_925") - << QLatin1String("RegexTest_926") - << QLatin1String("RegexTest_928") - << QLatin1String("RegexTest_929") - << QLatin1String("RegexTest_930") - << QLatin1String("RegexTest_936") - << QLatin1String("RegexTest_937") - << QLatin1String("RegexTest_938") - << QLatin1String("RegexTest_939") - << QLatin1String("RegexTest_940") - << QLatin1String("RegexTest_941") - << QLatin1String("RegexTest_942") - << QLatin1String("RegexTest_943") - << QLatin1String("RegexTest_944") - << QLatin1String("RegexTest_945") - << QLatin1String("RegexTest_946") - << QLatin1String("RegexTest_949") - << QLatin1String("RegexTest_950") - << QLatin1String("RegexTest_951") - << QLatin1String("RegexTest_952") - << QLatin1String("RegexTest_953") - << QLatin1String("RegexTest_954") - << QLatin1String("RegexTest_955") - << QLatin1String("RegexTest_956") - << QLatin1String("RegexTest_957") - << QLatin1String("RegexTest_958") - << QLatin1String("RegexTest_959") - << QLatin1String("RegexTest_960") - << QLatin1String("RegexTest_961") - << QLatin1String("RegexTest_962") - << QLatin1String("RegexTest_963") - << QLatin1String("RegexTest_964") - << QLatin1String("RegexTest_976") - << QLatin1String("RegexTest_977") - << QLatin1String("RegexTest_988") - << QLatin1String("RegexTest_989") - << QLatin1String("RegexTest_990") - << QLatin1String("RegexTest_991") - << QLatin1String("RegexTest_994") - << QLatin1String("RegexTest_995") - << QLatin1String("RegexTest_996") - << QLatin1String("RegexTest_997") - << QLatin1String("RegexTest_1000") - << QLatin1String("RegexTest_1001") - << QLatin1String("RegexTest_1002") - << QLatin1String("RegexTest_1003") - << QLatin1String("RegexTest_1004") - << QLatin1String("RegexTest_1007") - << QLatin1String("RegexTest_1008") - << QLatin1String("RegexTest_1009") - << QLatin1String("RegexTest_1010") - << QLatin1String("RegexTest_1011") - << QLatin1String("RegexTest_1012") - << QLatin1String("RegexTest_1013") - << QLatin1String("RegexTest_1014") - << QLatin1String("RegexTest_1015") - << QLatin1String("RegexTest_1016") - << QLatin1String("RegexTest_1017") - << QLatin1String("RegexTest_1018") - << QLatin1String("RegexTest_1019") - << QLatin1String("RegexTest_1070") - << QLatin1String("RegexTest_1071") - << QLatin1String("RegexTest_1076") - << QLatin1String("RegexTest_1077") - << QLatin1String("RegexTest_1078") - << QLatin1String("RegexTest_1079") - << QLatin1String("RegexTest_1080") - << QLatin1String("RegexTest_1081") - << QLatin1String("RegexTest_1082") - << QLatin1String("RegexTest_1083") - << QLatin1String("RegexTest_1084") - << QLatin1String("RegexTest_1085") - << QLatin1String("RegexTest_1086") - << QLatin1String("RegexTest_1087") - << QLatin1String("RegexTest_1088") - << QLatin1String("RegexTest_1089") - << QLatin1String("RegexTest_1132") - << QLatin1String("RegexTest_1139") - << QLatin1String("RegexTest_1172") - << QLatin1String("RegexTest_1180") - << QLatin1String("RegexTest_1181") - << QLatin1String("RegexTest_1182") - << QLatin1String("RegexTest_1184") - << QLatin1String("RegexTest_1185") - << QLatin1String("RegexTest_1186") - << QLatin1String("RegexTest_1187") - << QLatin1String("RegexTest_1188") - << QLatin1String("RegexTest_1189") - << QLatin1String("RegexTest_1190") - << QLatin1String("RegexTest_1191") - << QLatin1String("RegexTest_1201") - << QLatin1String("RegexTest_1202") - << QLatin1String("RegexTest_1203") - << QLatin1String("RegexTest_1208") - << QLatin1String("RegexTest_1209") - << QLatin1String("RegexTest_1210") - << QLatin1String("RegexTest_1211") - << QLatin1String("RegexTest_1212") - << QLatin1String("RegexTest_1213") - << QLatin1String("RegexTest_1214") - << QLatin1String("RegexTest_1215") - << QLatin1String("RegexTest_1216") - << QLatin1String("RegexTest_1217") - << QLatin1String("RegexTest_1227") - << QLatin1String("RegexTest_1239") - << QLatin1String("RegexTest_1240") - << QLatin1String("RegexTest_1245") - << QLatin1String("RegexTest_1246") - << QLatin1String("RegexTest_1265") - << QLatin1String("RegexTest_1266") - << QLatin1String("RegexTest_1267") - << QLatin1String("RegexTest_1274") - << QLatin1String("RegexTest_1275") - << QLatin1String("RegexTest_1308") - << QLatin1String("RegexTest_1310") - << QLatin1String("RegexTest_1311") - << QLatin1String("RegexTest_1320") - << QLatin1String("RegexTest_1321") - << QLatin1String("RegexTest_1322") - << QLatin1String("RegexTest_1323") - << QLatin1String("RegexTest_1324") - << QLatin1String("RegexTest_1325") - << QLatin1String("RegexTest_1326") - << QLatin1String("RegexTest_1327") - << QLatin1String("RegexTest_1328") - << QLatin1String("RegexTest_1329") - << QLatin1String("RegexTest_1330") - << QLatin1String("RegexTest_1331") - << QLatin1String("RegexTest_1332") - << QLatin1String("RegexTest_1335") - << QLatin1String("RegexTest_1336") - << QLatin1String("RegexTest_1337") - << QLatin1String("RegexTest_1338") - << QLatin1String("RegexTest_1339") - << QLatin1String("RegexTest_1340") - << QLatin1String("RegexTest_1341") - << QLatin1String("RegexTest_1345") - << QLatin1String("RegexTest_1346") - << QLatin1String("RegexTest_1347") - << QLatin1String("RegexTest_1348") - << QLatin1String("RegexTest_1349") - << QLatin1String("RegexTest_1350") - << QLatin1String("RegexTest_1354") - << QLatin1String("RegexTest_1363") - << QLatin1String("RegexTest_1364") - << QLatin1String("RegexTest_1365") - << QLatin1String("RegexTest_1372") - << QLatin1String("RegexTest_1373") - << QLatin1String("RegexTest_1374") - << QLatin1String("RegexTest_1375") - << QLatin1String("RegexTest_1376") - << QLatin1String("RegexTest_1377") - << QLatin1String("RegexTest_1378") - << QLatin1String("RegexTest_1379") - << QLatin1String("RegexTest_1380") - << QLatin1String("RegexTest_1381") - << QLatin1String("RegexTest_1382") - << QLatin1String("RegexTest_1383") - << QLatin1String("RegexTest_1384") - << QLatin1String("RegexTest_1385") - << QLatin1String("RegexTest_1386") - << QLatin1String("RegexTest_1387") - << QLatin1String("RegexTest_1388") - << QLatin1String("RegexTest_1389") - << QLatin1String("RegexTest_1390") - << QLatin1String("RegexTest_1391") - << QLatin1String("RegexTest_1392") - << QLatin1String("RegexTest_1393") - << QLatin1String("RegexTest_1394") - << QLatin1String("RegexTest_1395") - << QLatin1String("RegexTest_1396") - << QLatin1String("RegexTest_1397") - << QLatin1String("RegexTest_1398") - << QLatin1String("RegexTest_1399") - << QLatin1String("RegexTest_1400") - << QLatin1String("RegexTest_1401") - << QLatin1String("RegexTest_1402") - << QLatin1String("RegexTest_1403") - << QLatin1String("RegexTest_1404") - << QLatin1String("RegexTest_1405") - << QLatin1String("RegexTest_1406") - << QLatin1String("RegexTest_1407") - << QLatin1String("RegexTest_1408") - << QLatin1String("RegexTest_1409") - << QLatin1String("RegexTest_1410") - << QLatin1String("RegexTest_1412") - << QLatin1String("RegexTest_1413") - << QLatin1String("RegexTest_1414") - << QLatin1String("RegexTest_1420") - << QLatin1String("RegexTest_1421") - << QLatin1String("RegexTest_1422") - << QLatin1String("RegexTest_1423") - << QLatin1String("RegexTest_1424") - << QLatin1String("RegexTest_1425") - << QLatin1String("RegexTest_1426") - << QLatin1String("RegexTest_1427") - << QLatin1String("RegexTest_1428") - << QLatin1String("RegexTest_1429") - << QLatin1String("RegexTest_1430") - << QLatin1String("RegexTest_1433") - << QLatin1String("RegexTest_1434") - << QLatin1String("RegexTest_1435") - << QLatin1String("RegexTest_1436") - << QLatin1String("RegexTest_1437") - << QLatin1String("RegexTest_1438") - << QLatin1String("RegexTest_1439") - << QLatin1String("RegexTest_1440") - << QLatin1String("RegexTest_1441") - << QLatin1String("RegexTest_1442") - << QLatin1String("RegexTest_1443") - << QLatin1String("RegexTest_1444") - << QLatin1String("RegexTest_1445") - << QLatin1String("RegexTest_1446") - << QLatin1String("RegexTest_1447") - << QLatin1String("RegexTest_1448") - << QLatin1String("RegexTest_1451") - << QLatin1String("RegexTest_1452") - << QLatin1String("RegexTest_1453") - << QLatin1String("RegexTest_1454") - << QLatin1String("RegexTest_1455") - << QLatin1String("RegexTest_1456") - << QLatin1String("RegexTest_1472") - << QLatin1String("RegexTest_1473") - << QLatin1String("RegexTest_1474") - << QLatin1String("RegexTest_1475") - << QLatin1String("RegexTest_1478") - << QLatin1String("RegexTest_1479") - << QLatin1String("RegexTest_1480") - << QLatin1String("RegexTest_1481") - << QLatin1String("RegexTest_1484") - << QLatin1String("RegexTest_1485") - << QLatin1String("RegexTest_1486") - << QLatin1String("RegexTest_1487") - << QLatin1String("RegexTest_1488") - << QLatin1String("RegexTest_1491") - << QLatin1String("RegexTest_1492") - << QLatin1String("RegexTest_1493") - << QLatin1String("RegexTest_1494") - << QLatin1String("RegexTest_1495") - << QLatin1String("RegexTest_1496") - << QLatin1String("RegexTest_1497") - << QLatin1String("RegexTest_1498") - << QLatin1String("RegexTest_1499") - << QLatin1String("RegexTest_1500") - << QLatin1String("RegexTest_1501") - << QLatin1String("RegexTest_1502") - << QLatin1String("RegexTest_1503") - << QLatin1String("RegexTest_1543") - << QLatin1String("RegexTest_1544") - << QLatin1String("reZ001") -*/ - << QLatin1String("schA2") - << QLatin1String("schA5") - << QLatin1String("schA7") - << QLatin1String("schD8") - << QLatin1String("schG3") - << QLatin1String("schG6") - << QLatin1String("schG9") - << QLatin1String("schG11") - << QLatin1String("schG12") - << QLatin1String("schU1") - << QLatin1String("schU3") - << QLatin1String("schU4") - << QLatin1String("schU5") - << QLatin1String("schZ004") - << QLatin1String("schZ005") - << QLatin1String("schZ012_a") - << QLatin1String("stZ041") - << QLatin1String("wildZ010"); -} - -bool XSDTestSuiteHandler::startElement(const QString &namespaceURI, - const QString &localName, - const QString &/*qName*/, - const QXmlAttributes &atts) -{ - if(namespaceURI != QString::fromLatin1("http://www.w3.org/XML/2004/xml-schema-test-suite/")) - return true; - - if (localName == QLatin1String("testSet")) { - m_currentTestSet = new TestGroup(m_topLevelGroup); - Q_ASSERT(m_currentTestSet); - m_currentTestSet->setTitle(atts.value("name")); - m_topLevelGroup->appendChild(m_currentTestSet); - } else if (localName == QLatin1String("testGroup")) { - m_currentTestGroup = new TestGroup(m_currentTestSet); - Q_ASSERT(m_currentTestGroup); - m_currentTestGroup->setTitle(atts.value("name")); - m_currentTestSet->appendChild(m_currentTestGroup); - m_inTestGroup = true; - } else if (localName == QLatin1String("schemaTest")) { - if (m_blackList.contains(atts.value("name"))) { - m_currentTestCase = 0; - m_schemaBlacklisted = true; - return true; - } - m_schemaBlacklisted = false; - - m_currentTestCase = new XSDTSTestCase(TestCase::Standard, m_currentTestGroup, XSDTSTestCase::SchemaTest); - Q_ASSERT(m_currentTestCase); - m_counter++; - m_currentTestCase->setName(QString::number(m_counter) + atts.value("name")); - m_currentTestGroup->appendChild(m_currentTestCase); - m_currentTestCase->setParent(m_currentTestGroup); - - m_inSchemaTest = true; - } else if (localName == QLatin1String("instanceTest")) { - if (m_schemaBlacklisted) { - m_currentTestCase = 0; - return true; - } - - m_currentTestCase = new XSDTSTestCase(TestCase::Standard, m_currentTestGroup, XSDTSTestCase::InstanceTest); - Q_ASSERT(m_currentTestCase); - m_counter++; - m_currentTestCase->setName(QString::number(m_counter) + atts.value("name")); - m_currentTestGroup->appendChild(m_currentTestCase); - - m_inInstanceTest = true; - } else if (localName == QLatin1String("schemaDocument") || localName == QLatin1String("instanceDocument")) { - if (m_inSchemaTest) { - m_currentTestCase->setSchemaUri(QUrl(atts.value("xlink:href"))); - if (m_currentSchemaLink.isEmpty()) // we only use the first schema document for validation - m_currentSchemaLink = atts.value("xlink:href"); - } - if (m_inInstanceTest) { - m_currentTestCase->setInstanceUri(QUrl(atts.value("xlink:href"))); - m_currentTestCase->setSchemaUri(QUrl(m_currentSchemaLink)); - } - } else if (localName == QLatin1String("expected") && (m_inSchemaTest || m_inInstanceTest)) { - TestBaseLine *baseLine = new TestBaseLine(TestBaseLine::SchemaIsValid); - if (atts.value("validity") == QLatin1String("valid")) { - baseLine->setDetails(QLatin1String("true")); - m_currentTestCase->setName(m_currentTestCase->name() + QLatin1String(" tokoe:valid")); - } else { - baseLine->setDetails(QLatin1String("false")); - m_currentTestCase->setName(m_currentTestCase->name() + QLatin1String(" tokoe:invalid")); - } - - m_currentTestCase->addBaseLine(baseLine); - } else if (localName == QLatin1String("documentation") && m_inTestGroup) { - m_inDescription = true; - } - - return true; -} - -bool XSDTestSuiteHandler::endElement(const QString &/*namespaceURI*/, - const QString &localName, - const QString &/*qName*/) -{ - if (localName == QLatin1String("testGroup")) { - m_inTestGroup = false; - m_currentTestGroup->setDescription(m_documentation); - m_documentation.clear(); - m_currentSchemaLink.clear(); - - if (m_currentTestGroup->childCount() == 0) - m_currentTestSet->removeLast(); - } else if (localName == QLatin1String("schemaTest")) - m_inSchemaTest = false; - else if (localName == QLatin1String("instanceTest")) - m_inInstanceTest = false; - else if (localName == QLatin1String("documentation")) - m_inDescription = false; - - return true; -} - -bool XSDTestSuiteHandler::characters(const QString &ch) -{ - if (m_inDescription) - m_documentation += ch; - - return true; -} - -TestSuite *XSDTestSuiteHandler::testSuite() const -{ - return m_ts; -} - -// vim: et:ts=4:sw=4:sts=4 - diff --git a/tests/auto/xmlpatternsxqts/lib/XSDTestSuiteHandler.h b/tests/auto/xmlpatternsxqts/lib/XSDTestSuiteHandler.h deleted file mode 100644 index 5493c7d..0000000 --- a/tests/auto/xmlpatternsxqts/lib/XSDTestSuiteHandler.h +++ /dev/null @@ -1,121 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the autotests 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$ -** -****************************************************************************/ - -#ifndef PatternistSDK_XSDTestSuiteHandler_H -#define PatternistSDK_XSDTestSuiteHandler_H - -#include -#include - -#include "ExternalSourceLoader.h" -#include "TestSuite.h" -#include "XQTSTestCase.h" - -QT_BEGIN_HEADER -QT_BEGIN_NAMESPACE - -namespace QPatternistSDK -{ - class TestBaseLine; - class TestGroup; - class XSDTSTestCase; - - /** - * @short Creates a TestSuite from the XSD Test Suite. - * - * The created TestSuite can be retrieved via testSuite(). - * - * @note XSDTestSuiteHandler assumes the XML is valid by having been validated - * against the W3C XML Schema. It has no safety checks for that the XML format - * is correct but is hard coded for it. Thus, the behavior is undefined if - * the XML is invalid. - * - * @ingroup PatternistSDK - * @author Tobias Koenig - */ - class Q_PATTERNISTSDK_EXPORT XSDTestSuiteHandler : public QXmlDefaultHandler - { - public: - /** - * @param catalogFile the URI for the catalog file being parsed. This - * URI is used for creating absolute URIs for files mentioned in - * the catalog with relative URIs. - * @param useExclusionList whether excludeTestGroups.txt should be used to ignore - * test groups when loading - */ - XSDTestSuiteHandler(const QUrl &catalogFile); - virtual bool characters(const QString &ch); - - virtual bool endElement(const QString &namespaceURI, - const QString &localName, - const QString &qName); - virtual bool startElement(const QString &namespaceURI, - const QString &localName, - const QString &qName, - const QXmlAttributes &atts); - - virtual TestSuite *testSuite() const; - - private: - TestSuite* m_ts; - const QUrl m_catalogFile; - - TestGroup* m_topLevelGroup; - TestGroup* m_currentTestSet; - TestGroup* m_currentTestGroup; - XSDTSTestCase* m_currentTestCase; - bool m_inSchemaTest; - bool m_inInstanceTest; - bool m_inTestGroup; - bool m_inDescription; - bool m_schemaBlacklisted; - QString m_documentation; - QString m_currentSchemaLink; - int m_counter; - QSet m_blackList; - }; -} - -QT_END_NAMESPACE -QT_END_HEADER - -#endif -// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternsxqts/lib/XSLTTestSuiteHandler.cpp b/tests/auto/xmlpatternsxqts/lib/XSLTTestSuiteHandler.cpp deleted file mode 100644 index cfc3b2b..0000000 --- a/tests/auto/xmlpatternsxqts/lib/XSLTTestSuiteHandler.cpp +++ /dev/null @@ -1,234 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 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 "qacceltreeresourceloader_p.h" -#include "qnetworkaccessdelegator_p.h" - -#include "Global.h" -#include "TestBaseLine.h" -#include "TestGroup.h" - -#include "XSLTTestSuiteHandler.h" - -using namespace QPatternistSDK; - -extern QNetworkAccessManager s_networkManager; - -XSLTTestSuiteHandler::XSLTTestSuiteHandler(const QUrl &catalogFile) : m_ts(0) - , m_tc(0) - , m_baseLine(0) - , m_catalogFile(catalogFile) - , m_removeTestcase(false) -{ - const QPatternist::NetworkAccessDelegator::Ptr networkDelegator(new QPatternist::NetworkAccessDelegator(&s_networkManager, &s_networkManager)); - - m_resourceLoader = QPatternist::ResourceLoader::Ptr(new QPatternist::AccelTreeResourceLoader(Global::namePool(), - networkDelegator)); - Q_ASSERT(!m_catalogFile.isRelative()); -} - -bool XSLTTestSuiteHandler::startElement(const QString &namespaceURI, - const QString &localName, - const QString &/*qName*/, - const QXmlAttributes &atts) - { - if(namespaceURI != Global::xsltsCatalogNS) - return true; - - /* The elements are handled roughly in the order of highest occurrence in the catalog file. */ - if(localName == QLatin1String("testcase")) - { - /* We pass m_ts temporarily, and change it later. */ - m_tc = new XQTSTestCase(TestCase::Standard, 0, QXmlQuery::XSLT20); - - m_currentQueryPath = m_queryOffset.resolved(QUrl(atts.value(QLatin1String("FilePath")))); - m_currentBaselinePath = m_baselineOffset.resolved(QUrl(atts.value(QLatin1String("FilePath")))); - } - else if(localName == QLatin1String("stylesheet")) - m_tc->setQueryPath(m_currentQueryPath.resolved(atts.value(QLatin1String("file")))); - else if(localName == QLatin1String("error")) - { - m_baseLine = new TestBaseLine(TestBaseLine::ExpectedError); - m_baseLine->setDetails(atts.value(QLatin1String("error-id"))); - m_tc->addBaseLine(m_baseLine); - } - else if(localName == QLatin1String("testcases")) - { - m_ts = new TestSuite(); - m_ts->setVersion(atts.value(QLatin1String("testSuiteVersion"))); - - m_queryOffset = m_catalogFile.resolved(atts.value(QLatin1String("InputOffsetPath"))); - m_baselineOffset = m_catalogFile.resolved(atts.value(QLatin1String("ResultOffsetPath"))); - m_sourceOffset = m_catalogFile.resolved(atts.value(QLatin1String("InputOffsetPath"))); - } - else if(localName == QLatin1String("source-document")) - { - if(atts.value(QLatin1String("role")) == QLatin1String("principal")) - m_tc->setContextItemSource(m_sourceOffset.resolved(QUrl(atts.value(QLatin1String("file"))))); - } - else if(localName == QLatin1String("result-document")) - { - m_baseLine = new TestBaseLine(TestBaseLine::identifierFromString(atts.value(QLatin1String("type")))); - m_baseLine->setDetails(m_currentBaselinePath.resolved(atts.value(QLatin1String("file"))).toString()); - m_tc->addBaseLine(m_baseLine); - } - else if(localName == QLatin1String("discretionary-feature")) - { - const QString feature(atts.value(QLatin1String("name"))); - - m_removeTestcase = feature == QLatin1String("schema_aware") || - feature == QLatin1String("namespace_axis") || - feature == QLatin1String("disabling_output_escaping") || - feature == QLatin1String("XML_1.1"); - } - else if(localName == QLatin1String("discretionary-choice")) - { - m_baseLine = new TestBaseLine(TestBaseLine::ExpectedError); - m_baseLine->setDetails(atts.value(QLatin1String("name"))); - m_tc->addBaseLine(m_baseLine); - const QString feature(atts.value(QLatin1String("name"))); - - m_removeTestcase = feature == QLatin1String("schema_aware") || - feature == QLatin1String("namespace_axis") || - feature == QLatin1String("disabling_output_escaping") || - feature == QLatin1String("XML_1.1"); - } - else if(localName == QLatin1String("entry-named-template")) - { - const QString name(atts.value(QLatin1String("qname"))); - - if(!name.contains(QLatin1Char(':'))) - { - // TODO do namespace processing - const QXmlName complete(Global::namePool()->allocateQName(QString(), name)); - - m_tc->setInitialTemplateName(complete); - } - } - - return true; -} - -TestGroup *XSLTTestSuiteHandler::containerFor(const QString &name) -{ - TestGroup *& c = m_containers[name]; - - if(!c) - { - c = new TestGroup(m_ts); - c->setTitle(name); - Q_ASSERT(c); - m_ts->appendChild(c); - } - - return c; -} - -bool XSLTTestSuiteHandler::endElement(const QString &namespaceURI, - const QString &localName, - const QString &/*qName*/) -{ - if(namespaceURI != Global::xsltsCatalogNS) - return true; - - /* The elements are handled roughly in the order of highest occurrence in the catalog file. */ - if(localName == QLatin1String("description")) - { - if(m_tc) - { - /* We're inside a , so the belongs - * to the testcase. */ - m_tc->setDescription(m_ch.simplified()); - } - } - else if(localName == QLatin1String("testcase")) - { - Q_ASSERT(m_tc->baseLines().count() >= 1); - Q_ASSERT(m_resourceLoader); - // TODO can this be removed? - m_tc->setExternalVariableLoader(QPatternist::ExternalVariableLoader::Ptr - (new ExternalSourceLoader(m_tcSourceInputs, - m_resourceLoader))); - m_tcSourceInputs.clear(); - - if(!m_removeTestcase) - { - /* - TestContainer *const container = containerFor(m_currentCategory); - delete m_tc; - container->removeLast(); - */ - TestContainer *const container = containerFor(m_currentCategory); - m_tc->setParent(container); - Q_ASSERT(m_tc); - container->appendChild(m_tc); - } - - m_tc = 0; - m_removeTestcase = false; - } - else if(localName == QLatin1String("name")) - m_tc->setName(m_ch); - else if(localName == QLatin1String("creator")) - m_tc->setCreator(m_ch); - else if(localName == QLatin1String("contextItem")) - m_contextItemSource = m_ch; - else if(localName == QLatin1String("category")) - m_currentCategory = m_ch; - - return true; -} - -bool XSLTTestSuiteHandler::characters(const QString &ch) -{ - m_ch = ch; - return true; -} - -TestSuite *XSLTTestSuiteHandler::testSuite() const -{ - return m_ts; -} - -// vim: et:ts=4:sw=4:sts=4 - diff --git a/tests/auto/xmlpatternsxqts/lib/XSLTTestSuiteHandler.h b/tests/auto/xmlpatternsxqts/lib/XSLTTestSuiteHandler.h deleted file mode 100644 index 8614789..0000000 --- a/tests/auto/xmlpatternsxqts/lib/XSLTTestSuiteHandler.h +++ /dev/null @@ -1,158 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 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$ -** -****************************************************************************/ - -#ifndef PatternistSDK_XSLTTestSuiteHandler_H -#define PatternistSDK_XSLTTestSuiteHandler_H - -#include -#include -#include - -#include "ExternalSourceLoader.h" -#include "TestSuite.h" -#include "XQTSTestCase.h" - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -namespace QPatternistSDK -{ - class TestBaseLine; - class TestGroup; - - /** - * @short Creates a TestSuite from the XQuery Test Suite catalog. - * - * The created TestSuite can be retrieved via testSuite(). - * - * @note XSLTTestSuiteHandler assumes the XML is valid by having been validated - * against the W3C XML Schema. It has no safety checks for that the XML format - * is correct but is hard coded for it. Thus, the behavior is undefined if - * the XML is invalid. - * - * @see http://www.w3.org/XML/Group/xslt20-test/TestSuiteStagingArea/catalog.html - * @see http://www.w3.org/XML/Group/xslt20-test/Documentation/XSLT2Test.htm - * @ingroup PatternistSDK - * @author Frans Englich - */ - class Q_PATTERNISTSDK_EXPORT XSLTTestSuiteHandler : public QXmlDefaultHandler - { - public: - /** - * @param catalogFile the URI for the catalog file being parsed. This - * URI is used for creating absolute URIs for files mentioned in - * the catalog with relative URIs. - * @param useExclusionList whether excludeTestGroups.txt should be used to ignore - * test groups when loading - */ - XSLTTestSuiteHandler(const QUrl &catalogFile); - virtual bool characters(const QString &ch); - - virtual bool endElement(const QString &namespaceURI, - const QString &localName, - const QString &qName); - virtual bool startElement(const QString &namespaceURI, - const QString &localName, - const QString &qName, - const QXmlAttributes &atts); - - virtual TestSuite *testSuite() const; - - private: - TestGroup *containerFor(const QString &name); - - QHash m_containers; - - TestSuite * m_ts; - XQTSTestCase * m_tc; - TestBaseLine * m_baseLine; - QString m_ch; - const QUrl m_catalogFile; - - /** - * The base URI for where the XQuery query files are found. - * It is absolute, resolved against catalogFile. - */ - QUrl m_queryOffset; - - QUrl m_baselineOffset; - QUrl m_sourceOffset; - QUrl m_currentQueryPath; - QUrl m_currentBaselinePath; - - /** - * In the XQTSCatalog.xml, each source file in each test is referred to - * by a key, which can be fully looked up in the @c sources element. This QHash - * maps the keys to absolute URIs pointing to the source files. - */ - ExternalSourceLoader::SourceMap m_sourceMap; - - ExternalSourceLoader::VariableMap m_tcSourceInputs; - - QPatternist::ResourceLoader::Ptr m_resourceLoader; - - /** - * The current value of input-file/\@variable. - */ - QString m_currentInputVariable; - - /** - * The names of the test groups. - */ - QStack m_testGroupName; - - /** - * Holds the content of the current input-URI element. - */ - QString m_inputURI; - QString m_contextItemSource; - QString m_currentCategory; - bool m_removeTestcase; - }; -} - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif -// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternsxqts/lib/docs/XMLIndenterExample.cpp b/tests/auto/xmlpatternsxqts/lib/docs/XMLIndenterExample.cpp deleted file mode 100644 index 24ee158..0000000 --- a/tests/auto/xmlpatternsxqts/lib/docs/XMLIndenterExample.cpp +++ /dev/null @@ -1,63 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 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$ -** -****************************************************************************/ -QByteArray result; -QBuffer returnBuffer(&result); -XMLWriter writer(&returnBuffer); - -writer.startDocument(); - -writer.startDTD(QLatin1String("html"), QLatin1String("-//W3C//DTD XHTML 1.0 Strict//EN"), - QLatin1String("http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd")); -writer.endDTD(); - -writer.startPrefixMapping(QString(), QLatin1String("http://www.w3.org/1999/xhtml")); - -writer.startElement(QLatin1String("html"), QXmlAttributes()); -writer.startElement(QLatin1String("body"), QXmlAttributes()); -writer.startElement(QLatin1String("p"), QXmlAttributes()); - -writer.characters(QLatin1String("Hello World!")); - -writer.endElement(QLatin1String("p")); -writer.endElement(QLatin1String("body")); -writer.endElement(QLatin1String("html")); - -writer.endDocument(); diff --git a/tests/auto/xmlpatternsxqts/lib/docs/XMLIndenterExampleResult.xml b/tests/auto/xmlpatternsxqts/lib/docs/XMLIndenterExampleResult.xml deleted file mode 100644 index c5e7312..0000000 --- a/tests/auto/xmlpatternsxqts/lib/docs/XMLIndenterExampleResult.xml +++ /dev/null @@ -1,3 +0,0 @@ - - -

Hello World!

diff --git a/tests/auto/xmlpatternsxqts/lib/docs/XMLWriterExample.cpp b/tests/auto/xmlpatternsxqts/lib/docs/XMLWriterExample.cpp deleted file mode 100644 index 24ee158..0000000 --- a/tests/auto/xmlpatternsxqts/lib/docs/XMLWriterExample.cpp +++ /dev/null @@ -1,63 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 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$ -** -****************************************************************************/ -QByteArray result; -QBuffer returnBuffer(&result); -XMLWriter writer(&returnBuffer); - -writer.startDocument(); - -writer.startDTD(QLatin1String("html"), QLatin1String("-//W3C//DTD XHTML 1.0 Strict//EN"), - QLatin1String("http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd")); -writer.endDTD(); - -writer.startPrefixMapping(QString(), QLatin1String("http://www.w3.org/1999/xhtml")); - -writer.startElement(QLatin1String("html"), QXmlAttributes()); -writer.startElement(QLatin1String("body"), QXmlAttributes()); -writer.startElement(QLatin1String("p"), QXmlAttributes()); - -writer.characters(QLatin1String("Hello World!")); - -writer.endElement(QLatin1String("p")); -writer.endElement(QLatin1String("body")); -writer.endElement(QLatin1String("html")); - -writer.endDocument(); diff --git a/tests/auto/xmlpatternsxqts/lib/docs/XMLWriterExampleResult.xml b/tests/auto/xmlpatternsxqts/lib/docs/XMLWriterExampleResult.xml deleted file mode 100644 index c5e7312..0000000 --- a/tests/auto/xmlpatternsxqts/lib/docs/XMLWriterExampleResult.xml +++ /dev/null @@ -1,3 +0,0 @@ - - -

Hello World!

diff --git a/tests/auto/xmlpatternsxqts/lib/lib.pro b/tests/auto/xmlpatternsxqts/lib/lib.pro deleted file mode 100644 index f5b0a06..0000000 --- a/tests/auto/xmlpatternsxqts/lib/lib.pro +++ /dev/null @@ -1,88 +0,0 @@ -include (../../xmlpatterns.pri) - -TARGET = $$XMLPATTERNS_SDK -TEMPLATE = lib -DEFINES += Q_PATTERNISTSDK_BUILDING - -# lib_bundle ensures we get a framework on OS X, a library bundle. -CONFIG += resources - -mac { - CONFIG += absolute_library_soname - target.path=$$[QT_INSTALL_LIBS] - INSTALLS += target -} - -symbian { - TARGET.EPOCALLOWDLLDATA=1 - TARGET.CAPABILITY = All -Tcb - MMP_RULES += EXPORTUNFROZEN -} - -# We add gui, because xmlpatterns.pri pull it out. -QT += xmlpatterns xml network testlib gui - -DESTDIR = $$QT_BUILD_TREE/lib -!wince*:DLLDESTDIR = $$QT_BUILD_TREE/bin - -# syncqt doesn't copy headers in tools/ so let's manually ensure -# it works with shadow builds and source builds. -INCLUDEPATH += $$QT_BUILD_TREE/include/QtXmlPatterns/private \ - $$QT_SOURCE_TREE/include/QtXmlPatterns/private \ - $$QT_SOURCE_TREE/tools/xmlpatterns - -HEADERS = ASTItem.h \ - DebugExpressionFactory.h \ - ErrorHandler.h \ - ErrorItem.h \ - ExitCode.h \ - ExpressionInfo.h \ - ExpressionNamer.h \ - ExternalSourceLoader.h \ - Global.h \ - ResultThreader.h \ - TestBaseLine.h \ - TestCase.h \ - TestContainer.h \ - TestGroup.h \ - TestItem.h \ - TestResult.h \ - TestResultHandler.h \ - TestSuite.h \ - TestSuiteHandler.h \ - TestSuiteResult.h \ - TreeItem.h \ - TreeModel.h \ - Worker.h \ - XMLWriter.h \ - XQTSTestCase.h \ - XSDTestSuiteHandler.h \ - XSDTSTestCase.h \ - XSLTTestSuiteHandler.h - -SOURCES = ASTItem.cpp \ - DebugExpressionFactory.cpp \ - ErrorHandler.cpp \ - ErrorItem.cpp \ - ExpressionInfo.cpp \ - ExpressionNamer.cpp \ - ExternalSourceLoader.cpp \ - Global.cpp \ - ResultThreader.cpp \ - TestBaseLine.cpp \ - TestCase.cpp \ - TestContainer.cpp \ - TestGroup.cpp \ - TestResult.cpp \ - TestResultHandler.cpp \ - TestSuite.cpp \ - TestSuiteHandler.cpp \ - TestSuiteResult.cpp \ - TreeItem.cpp \ - TreeModel.cpp \ - Worker.cpp \ - XMLWriter.cpp \ - XQTSTestCase.cpp \ - XSDTestSuiteHandler.cpp \ - XSDTSTestCase.cpp \ - XSLTTestSuiteHandler.cpp diff --git a/tests/auto/xmlpatternsxqts/lib/tests/XMLWriterTest.cpp b/tests/auto/xmlpatternsxqts/lib/tests/XMLWriterTest.cpp deleted file mode 100644 index a10c01a..0000000 --- a/tests/auto/xmlpatternsxqts/lib/tests/XMLWriterTest.cpp +++ /dev/null @@ -1,186 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 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 "XMLWriter.h" - -#include "XMLWriterTest.h" -#include "XMLWriterTest.moc" - -using namespace QPatternistSDK; - -QTEST_MAIN(XMLWriterTest) - -void XMLWriterTest::serialize() -{ - QFETCH(QString, input); - QFETCH(QString, expectedResult); - - QByteArray result; - QBuffer returnBuffer(&result); - - XMLWriter writer(&returnBuffer); - - QXmlInputSource inputSource; - inputSource.setData(input); - - QXmlSimpleReader reader; - reader.setContentHandler(&writer); - - const bool parseSuccess = reader.parse(inputSource); - Q_ASSERT_X(parseSuccess, Q_FUNC_INFO, - "XMLWriter reported an error while serializing the input."); - - QCOMPARE(QString::fromLatin1(result), expectedResult); -} - -void XMLWriterTest::serialize_data() -{ - QTest::addColumn("input"); - QTest::addColumn("expectedResult"); - - /* ------------------- Elements ------------------- */ - QTest::newRow("Only an document element") - << "" - << "\n"; - - QTest::newRow("Document element containing a short closed element") - << "" - << "\n"; - QTest::newRow("Complex nested elements") - << "" - << "\n"; - /* ------------------------------------------------- */ - - /* ---------------- Element Content ---------------- */ - QTest::newRow("Element content with simple content") - << "content" - << "\ncontent"; - - QTest::newRow("Element content with tricky to escape content") - << ">>&'\"''/>" - << "\n>>&'\"''/>"; - /* ------------------------------------------------- */ - - /* ----------- Processing Instructions ------------- */ - QTest::newRow("Simple processing instruction.") - << "" - << "\n"; - /* ------------------------------------------------- */ - - /* --------------- 'xml' attributes ---------------- */ - QTest::newRow("Simple xml:space attribute.") - << "content" - << "\ncontent"; - - QTest::newRow("Many 'xml' attributes.") - << "content" - << "\n" - "content"; - /* ------------------------------------------------- */ - - /* ------------ namespace declarations ------------- */ - QTest::newRow("One simple namespace declaration.") - << "" - << "\n" - ""; - - QTest::newRow("Two simple namespace declarations.") - << "" - << "\n" - ""; - - QTest::newRow("A simple default namespace.") - << "" - << "\n" - ""; - /* ------------------------------------------------- */ - - /* -------- namespace declarations in use ---------- */ - QTest::newRow("Simple use of a namespace declaration.") - << "" - << "\n" - ""; - /* ------------------------------------------------- */ -} - -void XMLWriterTest::cdata() -{ - /* - QTest::newRow("Simple CDATA") - << "" - << "\n"; - - QTest::newRow("Complex CDATA") - << ">&'\";&987;]]>" - << "\n>&'\";&123;]]>"; - */ -} - -void XMLWriterTest::comments() -{ - /* - QTest::newRow("Simple comment") - << "" - << "\n"; - QTest::newRow("Comment") - << "" - << "\n"; - */ -} - -void XMLWriterTest::doxygenExample() -{ -#include "../docs/XMLWriterExample.cpp" - - /* When changing, remember to update the Doxygen in XMLWriter.h */ - const QByteArray expectedResult( - "\n" - "\n" - "

Hello World!

" - ); - - QCOMPARE(QString::fromLatin1(result), QString::fromLatin1(expectedResult)); -} - -// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternsxqts/lib/tests/XMLWriterTest.h b/tests/auto/xmlpatternsxqts/lib/tests/XMLWriterTest.h deleted file mode 100644 index f90aea2..0000000 --- a/tests/auto/xmlpatternsxqts/lib/tests/XMLWriterTest.h +++ /dev/null @@ -1,77 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 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$ -** -****************************************************************************/ - -#ifndef PatternistSDK_XMLWriterTest_H -#define PatternistSDK_XMLWriterTest_H - -#include - -QT_BEGIN_HEADER - -namespace QPatternistSDK -{ - /** - * @short QTestLib test for XMLWriter. - * - * @ingroup PatternistSDK - * @author Frans Englich - */ - class XMLWriterTest : public QObject - { - Q_OBJECT - private Q_SLOTS: - void serialize(); - void serialize_data(); - void comments(); - void cdata(); - - /** - * Ensure the example compiles, and that it does - * what it claims to. - */ - void doxygenExample(); - }; -} - -QT_END_HEADER - -#endif -// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternsxqts/test/test.pro b/tests/auto/xmlpatternsxqts/test/test.pro deleted file mode 100644 index a69838a..0000000 --- a/tests/auto/xmlpatternsxqts/test/test.pro +++ /dev/null @@ -1,26 +0,0 @@ -load(qttest_p4) -SOURCES += tst_xmlpatternsxqts.cpp ../../qxmlquery/TestFundament.cpp tst_suitetest.cpp - -include(../../xmlpatterns.pri) - -contains(QT_CONFIG,xmlpatterns) { - HEADERS += tst_suitetest.h - LIBS += -l$$XMLPATTERNS_SDK -} - -# syncqt doesn't copy headers in tools/ so let's manually ensure -# it works with shadow builds and source builds. -INCLUDEPATH += $$(QTDIR)/include/QtXmlPatterns/private \ - $$(QTSRCDIR)/include/QtXmlPatterns/private \ - $$(QTSRCDIR)/tools/xmlpatterns \ - $$(QTDIR)/tools/xmlpatterns \ - ../lib/ - -CONFIG += testlib -QT += xml -DESTDIR = .. -win32 { - CONFIG(debug, debug|release): DESTDIR = ../debug - else: DESTDIR = ../release -} -TARGET = tst_xmlpatternsxqts diff --git a/tests/auto/xmlpatternsxqts/test/tst_suitetest.cpp b/tests/auto/xmlpatternsxqts/test/tst_suitetest.cpp deleted file mode 100644 index 64120c7..0000000 --- a/tests/auto/xmlpatternsxqts/test/tst_suitetest.cpp +++ /dev/null @@ -1,175 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 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 - -#ifdef QTEST_XMLPATTERNS - -#include -#include "TestSuite.h" -#include "TestSuiteResult.h" -#include "XMLWriter.h" -#include "ExitCode.h" -#include "Worker.h" -#include "private/qautoptr_p.h" -#include "tst_suitetest.h" - -using namespace QPatternistSDK; - -tst_SuiteTest::tst_SuiteTest(const SuiteType suiteType, - const bool alwaysRun) : m_existingBaseline(inputFile(QLatin1String("Baseline.xml"))) - , m_candidateBaseline(inputFile(QLatin1String("CandidateBaseline.xml"))) - , m_abortRun(!alwaysRun && !QFile::exists(QLatin1String("runTests"))) - , m_suiteType(suiteType) -{ -} - -/*! - Returns an absolute path to the XQTS catalog, or flags a failure using - QTestLib's mechanisms. - - Finding the location of the catalog is done with `p4 where` such that we don't have - to care about where it is checked out. - */ -void tst_SuiteTest::initTestCase() -{ - catalogPath(m_catalogPath); -} - -/*! - Just runs the test suite and writes the result to m_candidateBaseline. - */ -void tst_SuiteTest::runTestSuite() const -{ - if(m_abortRun) - QSKIP("The test suite is not available, no tests are run.", SkipAll); - - QString errMsg; - const QFileInfo fi(m_catalogPath); - const QUrl catalogPath(QUrl::fromLocalFile(fi.absoluteFilePath())); - - TestSuite::SuiteType suiteType; - switch (m_suiteType) { - case XQuerySuite: suiteType = TestSuite::XQuerySuite; - case XsltSuite: suiteType = TestSuite::XsltSuite; - case XsdSuite: suiteType = TestSuite::XsdSuite; - default: break; - } - - TestSuite *const ts = TestSuite::openCatalog(catalogPath, errMsg, true, suiteType); - - QVERIFY2(ts, qPrintable(QString::fromLatin1("Failed to open the catalog, maybe it doesn't exist or is broken: %1").arg(errMsg))); - - /* Run the tests, and serialize the result(as according to XQTSResult.xsd) to standard out. */ - TestSuiteResult *const result = ts->runSuite(); - Q_ASSERT(result); - - QFile out(m_candidateBaseline); - QVERIFY(out.open(QIODevice::WriteOnly)); - - XMLWriter serializer(&out); - result->toXML(serializer); - - delete result; - delete ts; -} - -void tst_SuiteTest::checkTestSuiteResult() const -{ - if(m_abortRun) - QSKIP("This test takes too long time to run on the majority of platforms.", SkipAll); - - typedef QList QFileInfoList; - - const QFileInfo baseline(m_existingBaseline); - const QFileInfo result(m_candidateBaseline); - QFileInfoList list; - list.append(baseline); - list.append(result); - - const QFileInfoList::const_iterator end(list.constEnd()); - - QEventLoop eventLoop; - const QPatternist::AutoPtr worker(new Worker(eventLoop, m_existingBaseline, result)); - - /* Passed to ResultThreader so it knows what kind of file it is handling. */ - ResultThreader::Type type = ResultThreader::Baseline; - - QProcess::execute(QLatin1String("p4 edit ") + m_existingBaseline); - - for(QFileInfoList::const_iterator it(list.constBegin()); it != end; ++it) - { - QFileInfo i(*it); - i.makeAbsolute(); - - QVERIFY2(i.exists(), qPrintable(QString::fromLatin1("File %1 does not exist.") - .arg(i.fileName()))); - - QFile *const file = new QFile(i.absoluteFilePath(), worker.data()); - - QVERIFY2(file->open(QIODevice::ReadOnly), qPrintable(QString::fromLatin1("Could not open file %1 for reading.") - .arg(i.fileName()))); - - ResultThreader *handler = new ResultThreader(eventLoop, file, type, worker.data()); - - QObject::connect(handler, SIGNAL(finished()), worker.data(), SLOT(threadFinished())); - - handler->start(); /* Start the thread. It now parses the file - and emits threadFinished() when done. */ - type = ResultThreader::Result; - } - - const int exitCode = eventLoop.exec(); - - QProcess::execute(QLatin1String("p4 revert -a ") + m_existingBaseline); - - QCOMPARE(exitCode, 0); -} - -bool tst_SuiteTest::dontRun() const -{ - return m_abortRun; -} -#endif - - -// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternsxqts/test/tst_suitetest.h b/tests/auto/xmlpatternsxqts/test/tst_suitetest.h deleted file mode 100644 index 22e384a..0000000 --- a/tests/auto/xmlpatternsxqts/test/tst_suitetest.h +++ /dev/null @@ -1,107 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 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$ -** -****************************************************************************/ - - -#ifndef Q_tst_SuiteTest -#define Q_tst_SuiteTest - -#include -#include "../../qxmlquery/TestFundament.h" - -/*! - \class tst_SuiteTest - \internal - \since 4.5 - \brief Base class for tst_XmlPatternsXQTS, tst_XmlPatternsXSLTS and tst_XmlPatternsXSDTS. - */ -class tst_SuiteTest : public QObject - , private TestFundament -{ - Q_OBJECT - -public: - enum SuiteType - { - XQuerySuite, - XsltSuite, - XsdSuite - }; - -protected: - /** - * @p isXSLT is @c true if the catalog opened is an - * XSL-T test suite. - * - * @p alwaysRun is @c true if the test should always be run, - * regardless of if the file runTests exists. - */ - tst_SuiteTest(SuiteType type, - const bool alwaysRun = false); - - /** - * The reason why we pass in a mutable reference and have void as return - * value instead of simply returning the string, is that we in some - * implementations use QTestLib's macros such as QVERIFY, which contains - * return statements. Yay for QTestLib. - */ - virtual void catalogPath(QString &write) const = 0; - - bool dontRun() const; - -private Q_SLOTS: - void initTestCase(); - void runTestSuite() const; - void checkTestSuiteResult() const; - -private: - /** - * An absolute path to the catalog. - */ - QString m_catalogPath; - const QString m_existingBaseline; - const QString m_candidateBaseline; - const bool m_abortRun; - const SuiteType m_suiteType; -}; - -#endif - -// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternsxqts/test/tst_xmlpatternsxqts.cpp b/tests/auto/xmlpatternsxqts/test/tst_xmlpatternsxqts.cpp deleted file mode 100644 index 890234e..0000000 --- a/tests/auto/xmlpatternsxqts/test/tst_xmlpatternsxqts.cpp +++ /dev/null @@ -1,106 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 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 - -#ifdef QTEST_XMLPATTERNS - -#include "tst_suitetest.h" - -/*! - \class tst_XmlPatternsXQTS - \internal - \since 4.4 - \brief Tests the actual engine by running W3C's conformance test suite. - */ -class tst_XmlPatternsXQTS : public tst_SuiteTest -{ - Q_OBJECT -public: - tst_XmlPatternsXQTS(); -public: - virtual void catalogPath(QString &write) const; -}; - -tst_XmlPatternsXQTS::tst_XmlPatternsXQTS() : tst_SuiteTest(tst_SuiteTest::XQuerySuite) -{ -} - -void tst_XmlPatternsXQTS::catalogPath(QString &write) const -{ - if(dontRun()) - QSKIP("This test takes too long time to run on the majority of platforms.", SkipAll); - - QProcess p4; - - QStringList arguments; - arguments << QLatin1String("where") - << QLatin1String("//depot/autotests/4.4/tests/auto/xmlpatternsxqts/XQTS/XQTSCatalog.xml"); - p4.start(QLatin1String("p4"), arguments); - QVERIFY(p4.waitForFinished()); - QCOMPARE(p4.exitCode(), 0); - QCOMPARE(p4.exitStatus(), QProcess::NormalExit); - - /* `p4 where' prints for instance: - * - * //depot/qt/4.4/tests/auto/xmlpatternsxqts/... //fenglich-englich/qt-4.4/tests/auto/xmlpatternsxqts/... /home/fenglich/dev/autotests/4.4/tests/auto/xmlpatternsxqts/XQTS/XQTSCatalog.xml - * - * so we want the last string. - */ - write = QString::fromLocal8Bit(p4.readAllStandardOutput()).split(QLatin1Char(' ')).last().trimmed(); - - if(write.isEmpty() || !QFile::exists(write)) - { - QEXPECT_FAIL("", "//depot/autotests/4.4/tests/auto/xmlpatternsxqts/XQTS/ must be part of the perforce client spec, " - "checked out at an arbitrary location, for this test to run. The test suite will now be skipped.", Abort); - QVERIFY(false); - } -} - -QTEST_MAIN(tst_XmlPatternsXQTS) - -#include "tst_xmlpatternsxqts.moc" -#else -QTEST_NOOP_MAIN -#endif - -// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternsxqts/tst_suitetest.cpp b/tests/auto/xmlpatternsxqts/tst_suitetest.cpp new file mode 100644 index 0000000..64120c7 --- /dev/null +++ b/tests/auto/xmlpatternsxqts/tst_suitetest.cpp @@ -0,0 +1,175 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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 + +#ifdef QTEST_XMLPATTERNS + +#include +#include "TestSuite.h" +#include "TestSuiteResult.h" +#include "XMLWriter.h" +#include "ExitCode.h" +#include "Worker.h" +#include "private/qautoptr_p.h" +#include "tst_suitetest.h" + +using namespace QPatternistSDK; + +tst_SuiteTest::tst_SuiteTest(const SuiteType suiteType, + const bool alwaysRun) : m_existingBaseline(inputFile(QLatin1String("Baseline.xml"))) + , m_candidateBaseline(inputFile(QLatin1String("CandidateBaseline.xml"))) + , m_abortRun(!alwaysRun && !QFile::exists(QLatin1String("runTests"))) + , m_suiteType(suiteType) +{ +} + +/*! + Returns an absolute path to the XQTS catalog, or flags a failure using + QTestLib's mechanisms. + + Finding the location of the catalog is done with `p4 where` such that we don't have + to care about where it is checked out. + */ +void tst_SuiteTest::initTestCase() +{ + catalogPath(m_catalogPath); +} + +/*! + Just runs the test suite and writes the result to m_candidateBaseline. + */ +void tst_SuiteTest::runTestSuite() const +{ + if(m_abortRun) + QSKIP("The test suite is not available, no tests are run.", SkipAll); + + QString errMsg; + const QFileInfo fi(m_catalogPath); + const QUrl catalogPath(QUrl::fromLocalFile(fi.absoluteFilePath())); + + TestSuite::SuiteType suiteType; + switch (m_suiteType) { + case XQuerySuite: suiteType = TestSuite::XQuerySuite; + case XsltSuite: suiteType = TestSuite::XsltSuite; + case XsdSuite: suiteType = TestSuite::XsdSuite; + default: break; + } + + TestSuite *const ts = TestSuite::openCatalog(catalogPath, errMsg, true, suiteType); + + QVERIFY2(ts, qPrintable(QString::fromLatin1("Failed to open the catalog, maybe it doesn't exist or is broken: %1").arg(errMsg))); + + /* Run the tests, and serialize the result(as according to XQTSResult.xsd) to standard out. */ + TestSuiteResult *const result = ts->runSuite(); + Q_ASSERT(result); + + QFile out(m_candidateBaseline); + QVERIFY(out.open(QIODevice::WriteOnly)); + + XMLWriter serializer(&out); + result->toXML(serializer); + + delete result; + delete ts; +} + +void tst_SuiteTest::checkTestSuiteResult() const +{ + if(m_abortRun) + QSKIP("This test takes too long time to run on the majority of platforms.", SkipAll); + + typedef QList QFileInfoList; + + const QFileInfo baseline(m_existingBaseline); + const QFileInfo result(m_candidateBaseline); + QFileInfoList list; + list.append(baseline); + list.append(result); + + const QFileInfoList::const_iterator end(list.constEnd()); + + QEventLoop eventLoop; + const QPatternist::AutoPtr worker(new Worker(eventLoop, m_existingBaseline, result)); + + /* Passed to ResultThreader so it knows what kind of file it is handling. */ + ResultThreader::Type type = ResultThreader::Baseline; + + QProcess::execute(QLatin1String("p4 edit ") + m_existingBaseline); + + for(QFileInfoList::const_iterator it(list.constBegin()); it != end; ++it) + { + QFileInfo i(*it); + i.makeAbsolute(); + + QVERIFY2(i.exists(), qPrintable(QString::fromLatin1("File %1 does not exist.") + .arg(i.fileName()))); + + QFile *const file = new QFile(i.absoluteFilePath(), worker.data()); + + QVERIFY2(file->open(QIODevice::ReadOnly), qPrintable(QString::fromLatin1("Could not open file %1 for reading.") + .arg(i.fileName()))); + + ResultThreader *handler = new ResultThreader(eventLoop, file, type, worker.data()); + + QObject::connect(handler, SIGNAL(finished()), worker.data(), SLOT(threadFinished())); + + handler->start(); /* Start the thread. It now parses the file + and emits threadFinished() when done. */ + type = ResultThreader::Result; + } + + const int exitCode = eventLoop.exec(); + + QProcess::execute(QLatin1String("p4 revert -a ") + m_existingBaseline); + + QCOMPARE(exitCode, 0); +} + +bool tst_SuiteTest::dontRun() const +{ + return m_abortRun; +} +#endif + + +// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternsxqts/tst_suitetest.h b/tests/auto/xmlpatternsxqts/tst_suitetest.h new file mode 100644 index 0000000..70e56af --- /dev/null +++ b/tests/auto/xmlpatternsxqts/tst_suitetest.h @@ -0,0 +1,107 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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$ +** +****************************************************************************/ + + +#ifndef Q_tst_SuiteTest +#define Q_tst_SuiteTest + +#include +#include "../qxmlquery/TestFundament.h" + +/*! + \class tst_SuiteTest + \internal + \since 4.5 + \brief Base class for tst_XmlPatternsXQTS, tst_XmlPatternsXSLTS and tst_XmlPatternsXSDTS. + */ +class tst_SuiteTest : public QObject + , private TestFundament +{ + Q_OBJECT + +public: + enum SuiteType + { + XQuerySuite, + XsltSuite, + XsdSuite + }; + +protected: + /** + * @p isXSLT is @c true if the catalog opened is an + * XSL-T test suite. + * + * @p alwaysRun is @c true if the test should always be run, + * regardless of if the file runTests exists. + */ + tst_SuiteTest(SuiteType type, + const bool alwaysRun = false); + + /** + * The reason why we pass in a mutable reference and have void as return + * value instead of simply returning the string, is that we in some + * implementations use QTestLib's macros such as QVERIFY, which contains + * return statements. Yay for QTestLib. + */ + virtual void catalogPath(QString &write) const = 0; + + bool dontRun() const; + +private Q_SLOTS: + void initTestCase(); + void runTestSuite() const; + void checkTestSuiteResult() const; + +private: + /** + * An absolute path to the catalog. + */ + QString m_catalogPath; + const QString m_existingBaseline; + const QString m_candidateBaseline; + const bool m_abortRun; + const SuiteType m_suiteType; +}; + +#endif + +// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternsxqts/tst_xmlpatternsxqts.cpp b/tests/auto/xmlpatternsxqts/tst_xmlpatternsxqts.cpp new file mode 100644 index 0000000..890234e --- /dev/null +++ b/tests/auto/xmlpatternsxqts/tst_xmlpatternsxqts.cpp @@ -0,0 +1,106 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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 + +#ifdef QTEST_XMLPATTERNS + +#include "tst_suitetest.h" + +/*! + \class tst_XmlPatternsXQTS + \internal + \since 4.4 + \brief Tests the actual engine by running W3C's conformance test suite. + */ +class tst_XmlPatternsXQTS : public tst_SuiteTest +{ + Q_OBJECT +public: + tst_XmlPatternsXQTS(); +public: + virtual void catalogPath(QString &write) const; +}; + +tst_XmlPatternsXQTS::tst_XmlPatternsXQTS() : tst_SuiteTest(tst_SuiteTest::XQuerySuite) +{ +} + +void tst_XmlPatternsXQTS::catalogPath(QString &write) const +{ + if(dontRun()) + QSKIP("This test takes too long time to run on the majority of platforms.", SkipAll); + + QProcess p4; + + QStringList arguments; + arguments << QLatin1String("where") + << QLatin1String("//depot/autotests/4.4/tests/auto/xmlpatternsxqts/XQTS/XQTSCatalog.xml"); + p4.start(QLatin1String("p4"), arguments); + QVERIFY(p4.waitForFinished()); + QCOMPARE(p4.exitCode(), 0); + QCOMPARE(p4.exitStatus(), QProcess::NormalExit); + + /* `p4 where' prints for instance: + * + * //depot/qt/4.4/tests/auto/xmlpatternsxqts/... //fenglich-englich/qt-4.4/tests/auto/xmlpatternsxqts/... /home/fenglich/dev/autotests/4.4/tests/auto/xmlpatternsxqts/XQTS/XQTSCatalog.xml + * + * so we want the last string. + */ + write = QString::fromLocal8Bit(p4.readAllStandardOutput()).split(QLatin1Char(' ')).last().trimmed(); + + if(write.isEmpty() || !QFile::exists(write)) + { + QEXPECT_FAIL("", "//depot/autotests/4.4/tests/auto/xmlpatternsxqts/XQTS/ must be part of the perforce client spec, " + "checked out at an arbitrary location, for this test to run. The test suite will now be skipped.", Abort); + QVERIFY(false); + } +} + +QTEST_MAIN(tst_XmlPatternsXQTS) + +#include "tst_xmlpatternsxqts.moc" +#else +QTEST_NOOP_MAIN +#endif + +// vim: et:ts=4:sw=4:sts=4 diff --git a/tests/auto/xmlpatternsxqts/xmlpatternsxqts.pro b/tests/auto/xmlpatternsxqts/xmlpatternsxqts.pro index 3f49ccc..e81888a 100644 --- a/tests/auto/xmlpatternsxqts/xmlpatternsxqts.pro +++ b/tests/auto/xmlpatternsxqts/xmlpatternsxqts.pro @@ -1,13 +1,21 @@ -TEMPLATE = subdirs +load(qttest_p4) +SOURCES += tst_xmlpatternsxqts.cpp ../qxmlquery/TestFundament.cpp tst_suitetest.cpp + +include(../xmlpatterns.pri) + contains(QT_CONFIG,xmlpatterns) { - SUBDIRS += lib - test.depends = lib + HEADERS += tst_suitetest.h + LIBS += -l$$XMLPATTERNS_SDK } -SUBDIRS += test - -# Needed on the win32-g++ setup and on the test machine arsia. -INCLUDEPATH += $$QT_BUILD_TREE/include/QtXmlPatterns/private \ - ../../../include/QtXmlPatterns/private -requires(contains(QT_CONFIG,private_tests)) +# syncqt doesn't copy headers in tools/ so let's manually ensure +# it works with shadow builds and source builds. +INCLUDEPATH += $$(QTDIR)/include/QtXmlPatterns/private \ + $$(QTSRCDIR)/include/QtXmlPatterns/private \ + $$(QTSRCDIR)/tools/xmlpatterns \ + $$(QTDIR)/tools/xmlpatterns \ + ../xmlpatternssdk/ +CONFIG += testlib +QT += xml +TARGET = tst_xmlpatternsxqts diff --git a/tests/auto/xmlpatternsxslts/xmlpatternsxslts.pro b/tests/auto/xmlpatternsxslts/xmlpatternsxslts.pro index 9b63a52..940cc31 100644 --- a/tests/auto/xmlpatternsxslts/xmlpatternsxslts.pro +++ b/tests/auto/xmlpatternsxslts/xmlpatternsxslts.pro @@ -5,17 +5,17 @@ SOURCES += tst_xmlpatternsxslts.cpp \ include (../xmlpatterns.pri) contains(QT_CONFIG,xmlpatterns) { -HEADERS += ../xmlpatternsxqts/test/tst_suitetest.h -SOURCES += ../xmlpatternsxqts/test/tst_suitetest.cpp +HEADERS += ../xmlpatternsxqts/tst_suitetest.h +SOURCES += ../xmlpatternsxqts/tst_suitetest.cpp LIBS += -l$$XMLPATTERNS_SDK } QT += xml -INCLUDEPATH += $$(QTSRCDIR)/tests/auto/xmlpatternsxqts/lib/ \ - $$(QTDIR)/include/QtXmlPatterns/private \ - $$(QTSRCDIR)/tests/auto/xmlpatternsxqts/test \ - ../xmlpatternsxqts/test \ - ../xmlpatternsxqts/lib +INCLUDEPATH += $$(QTSRCDIR)/tests/auto/xmlpatternssdk \ + $$(QTDIR)/include/QtXmlPatterns/private \ + $$(QTSRCDIR)/tests/auto/xmlpatternsxqts \ + ../xmlpatternsxqts \ + ../xmlpatternssdk wince*: { testdata.sources = XSLTS Baseline.xml -- cgit v0.12 From cc583fef7b9839be7173e039a1162541449e18c2 Mon Sep 17 00:00:00 2001 From: Rohan McGovern Date: Tue, 16 Feb 2010 16:57:27 +1000 Subject: Fixed compile of qlibrary test with vcproj generator. COPY and DESTDIR_TARGET are defined by qmake when generating makefiles, but not when generating vcproj files. We need to do something different for the vcproj generator. --- tests/auto/qlibrary/lib2/lib2.pro | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/auto/qlibrary/lib2/lib2.pro b/tests/auto/qlibrary/lib2/lib2.pro index da30a2d..4654f4d 100644 --- a/tests/auto/qlibrary/lib2/lib2.pro +++ b/tests/auto/qlibrary/lib2/lib2.pro @@ -16,14 +16,19 @@ win32-borland: DEFINES += WIN32_BORLAND !symbian { win32 { - src = $(DESTDIR_TARGET) + # vcproj and Makefile generators refer to target differently + contains(TEMPLATE,vc.*) { + src = $(TargetPath) + } else { + src = $(DESTDIR_TARGET) + } files = mylib.dl2 system.trolltech.test.mylib.dll } else { src = $(DESTDIR)$(TARGET) files = libmylib.so2 system.trolltech.test.mylib.so } for(file, files) { - QMAKE_POST_LINK += $(COPY) $$src ..$$QMAKE_DIR_SEP$$file && + QMAKE_POST_LINK += $$QMAKE_COPY $$src ..$$QMAKE_DIR_SEP$$file && CLEAN_FILES += ../$$file } QMAKE_POST_LINK = $$member(QMAKE_POST_LINK, 0, -2) -- cgit v0.12 From 87613a0fb5149b934642c455cf8cae6a373598e3 Mon Sep 17 00:00:00 2001 From: Rohan McGovern Date: Tue, 16 Feb 2010 17:02:37 +1000 Subject: Fixed compile of compilerwarnings test with vcproj generator. Rename the test C++ file from `test.cpp' to `test_cpp.txt'. When named `test.cpp', the build system will attempt to build it, which we don't want. --- tests/auto/compilerwarnings/compilerwarnings.qrc | 2 +- tests/auto/compilerwarnings/test.cpp | 67 ---------------------- tests/auto/compilerwarnings/test_cpp.txt | 67 ++++++++++++++++++++++ .../auto/compilerwarnings/tst_compilerwarnings.cpp | 4 +- 4 files changed, 70 insertions(+), 70 deletions(-) delete mode 100644 tests/auto/compilerwarnings/test.cpp create mode 100644 tests/auto/compilerwarnings/test_cpp.txt diff --git a/tests/auto/compilerwarnings/compilerwarnings.qrc b/tests/auto/compilerwarnings/compilerwarnings.qrc index 40fa8f1..3fa313c 100644 --- a/tests/auto/compilerwarnings/compilerwarnings.qrc +++ b/tests/auto/compilerwarnings/compilerwarnings.qrc @@ -1,5 +1,5 @@ - test.cpp + test_cpp.txt diff --git a/tests/auto/compilerwarnings/test.cpp b/tests/auto/compilerwarnings/test.cpp deleted file mode 100644 index 62b35eb..0000000 --- a/tests/auto/compilerwarnings/test.cpp +++ /dev/null @@ -1,67 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 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 -#include -#include - -#ifndef QT_NO_OPENGL -#include -#endif - -#include - -#include - -#if !defined(QT_NO_DBUS) && defined(Q_OS_UNIX) -#include -#endif - -#ifndef Q_OS_MAC -int main(int, char **) -{ - return 0; -} -#endif - diff --git a/tests/auto/compilerwarnings/test_cpp.txt b/tests/auto/compilerwarnings/test_cpp.txt new file mode 100644 index 0000000..62b35eb --- /dev/null +++ b/tests/auto/compilerwarnings/test_cpp.txt @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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 +#include +#include + +#ifndef QT_NO_OPENGL +#include +#endif + +#include + +#include + +#if !defined(QT_NO_DBUS) && defined(Q_OS_UNIX) +#include +#endif + +#ifndef Q_OS_MAC +int main(int, char **) +{ + return 0; +} +#endif + diff --git a/tests/auto/compilerwarnings/tst_compilerwarnings.cpp b/tests/auto/compilerwarnings/tst_compilerwarnings.cpp index 27624e9..f910a18 100644 --- a/tests/auto/compilerwarnings/tst_compilerwarnings.cpp +++ b/tests/auto/compilerwarnings/tst_compilerwarnings.cpp @@ -148,7 +148,7 @@ void tst_CompilerWarnings::warnings() if (tmpSourceFile.isEmpty()) { tmpQSourceFile.open(QIODevice::ReadWrite | QIODevice::Truncate); tmpSourceFile = tmpQSourceFile.fileName(); - QFile cppSource(":/test.cpp"); + QFile cppSource(":/test_cpp.txt"); bool openResult = cppSource.open(QIODevice::ReadOnly); if (openResult) { @@ -158,7 +158,7 @@ void tst_CompilerWarnings::warnings() } } tmpQSourceFile.close(); - QVERIFY2(openResult, "Need resource temporary \"test.cpp\""); + QVERIFY2(openResult, "Need resource temporary \"test_cpp.txt\""); QStringList args; QString compilerName; -- cgit v0.12 From 4a1bca54c48087dd7f0f6d0a88c87b9b41283fcf Mon Sep 17 00:00:00 2001 From: Rohan McGovern Date: Wed, 17 Feb 2010 11:26:09 +1000 Subject: Fixed failure of maketestselftest with vcproj generator. --- tests/auto/maketestselftest/tst_maketestselftest.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/auto/maketestselftest/tst_maketestselftest.cpp b/tests/auto/maketestselftest/tst_maketestselftest.cpp index ef92c56..1dde44b 100644 --- a/tests/auto/maketestselftest/tst_maketestselftest.cpp +++ b/tests/auto/maketestselftest/tst_maketestselftest.cpp @@ -92,7 +92,9 @@ void tst_MakeTestSelfTest::auto_dot_pro_data() QStringList subdirs = dir.entryList(QDir::AllDirs|QDir::NoDotAndDotDot); foreach (const QString& subdir, subdirs) { - if (subdir == QString::fromLatin1("tmp")) { + if (subdir == QString::fromLatin1("tmp") + || subdir.startsWith(".")) + { continue; } QTest::newRow(qPrintable(subdir)) << subdir; -- cgit v0.12 From baa7c3bdecc7fbcf7673b4b1807e742ede2e7bd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20R=C3=B8dal?= Date: Tue, 16 Feb 2010 15:20:29 +0100 Subject: Fixed autotest failure in tst_QGraphicsScene::render on Maemo. The fixed point code in the raster paint engine's drawEllipse() function causes rendering errors on ARM. Remove untested code and use the vector path fallback instead. Reviewed-by: Gunnar Sletta --- src/gui/painting/qpaintengine_raster.cpp | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/src/gui/painting/qpaintengine_raster.cpp b/src/gui/painting/qpaintengine_raster.cpp index bc56ed0..4a4792a 100644 --- a/src/gui/painting/qpaintengine_raster.cpp +++ b/src/gui/painting/qpaintengine_raster.cpp @@ -1827,6 +1827,7 @@ void QRasterPaintEngine::fill(const QVectorPath &path, const QBrush &brush) } } +#ifndef FLOATING_POINT_BUGGY_OR_NO_FPU if (path.shape() == QVectorPath::EllipseHint) { if (!s->flags.antialiased && s->matrix.type() <= QTransform::TxScale) { const qreal *p = path.points(); @@ -1846,6 +1847,7 @@ void QRasterPaintEngine::fill(const QVectorPath &path, const QBrush &brush) } } } +#endif // ### Optimize for non transformed ellipses and rectangles... QRectF cpRect = path.controlPointRect(); @@ -3672,6 +3674,7 @@ void QRasterPaintEngine::drawLines(const QLineF *lines, int lineCount) */ void QRasterPaintEngine::drawEllipse(const QRectF &rect) { +#ifndef FLOATING_POINT_BUGGY_OR_NO_FPU Q_D(QRasterPaintEngine); QRasterPaintEngineState *s = state(); @@ -3679,9 +3682,6 @@ void QRasterPaintEngine::drawEllipse(const QRectF &rect) if (((qpen_style(s->lastPen) == Qt::SolidLine && s->flags.fast_pen) || (qpen_style(s->lastPen) == Qt::NoPen && !s->flags.antialiased)) && qMax(rect.width(), rect.height()) < QT_RASTER_COORD_LIMIT -#ifdef FLOATING_POINT_BUGGY_OR_NO_FPU - && qMax(rect.width(), rect.height()) < 128 // integer math breakdown -#endif && s->matrix.type() <= QTransform::TxScale) // no shear { ensureBrush(); @@ -3697,6 +3697,7 @@ void QRasterPaintEngine::drawEllipse(const QRectF &rect) return; } } +#endif QPaintEngineEx::drawEllipse(rect); } @@ -6054,15 +6055,9 @@ static void drawEllipse_midpoint_i(const QRect &rect, const QRect &clip, ProcessSpans pen_func, ProcessSpans brush_func, QSpanData *pen_data, QSpanData *brush_data) { -#ifdef FLOATING_POINT_BUGGY_OR_NO_FPU // no fpu, so use fixed point - const QFixed a = QFixed(rect.width()) >> 1; - const QFixed b = QFixed(rect.height()) >> 1; - QFixed d = b*b - (a*a*b) + ((a*a) >> 2); -#else const qreal a = qreal(rect.width()) / 2; const qreal b = qreal(rect.height()) / 2; qreal d = b*b - (a*a*b) + 0.25*a*a; -#endif int x = 0; int y = (rect.height() + 1) / 2; @@ -6085,12 +6080,7 @@ static void drawEllipse_midpoint_i(const QRect &rect, const QRect &clip, pen_func, brush_func, pen_data, brush_data); // region 2 -#ifdef FLOATING_POINT_BUGGY_OR_NO_FPU - d = b*b*(x + (QFixed(1) >> 1))*(x + (QFixed(1) >> 1)) - + a*a*((y - 1)*(y - 1) - b*b); -#else d = b*b*(x + 0.5)*(x + 0.5) + a*a*((y - 1)*(y - 1) - b*b); -#endif const int miny = rect.height() & 0x1; while (y > miny) { if (d < 0) { // select SE -- cgit v0.12 From dd745238e17dbdc52417e11a70e74cf6f8e15d04 Mon Sep 17 00:00:00 2001 From: Peter Hartmann Date: Wed, 17 Feb 2010 11:41:03 +0100 Subject: HTTP backend: remove comment the date header always needs to be updated in the cache. Task-number: QTBUG-7466 --- src/network/access/qnetworkaccesshttpbackend.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/network/access/qnetworkaccesshttpbackend.cpp b/src/network/access/qnetworkaccesshttpbackend.cpp index 61a95fe..af971a7 100644 --- a/src/network/access/qnetworkaccesshttpbackend.cpp +++ b/src/network/access/qnetworkaccesshttpbackend.cpp @@ -976,7 +976,7 @@ QNetworkCacheMetaData QNetworkAccessHttpBackend::fetchCacheMetaData(const QNetwo // of writes to disk when using a QNetworkDiskCache (i.e. don't // write to disk when only the date changes). // However, without the date we cannot calculate the age of the page - // anymore. Consider a proper fix of that problem for 4.6.1. + // anymore. //if (header == "date") //continue; -- cgit v0.12 From 729d67cb35830a812c8c41a02a7b16a077dc14fb Mon Sep 17 00:00:00 2001 From: Janne Anttila Date: Wed, 17 Feb 2010 13:04:07 +0200 Subject: Support for dynamic localization in Symbian softkeys. This commit adds support for dynamic i.e. runtime localization of S60 softkeys. Note that translations are not provided yet with qt.sis (QTBUG-4919), meaning that localization does not actually happen unless application developer provides its own translation (including translation for softkeys). Task-number: QTBUG-6785 Reviewed-by: Jason Barron --- src/gui/itemviews/qabstractitemview.cpp | 5 +++++ src/gui/kernel/qsoftkeymanager.cpp | 17 ++++++++--------- src/gui/kernel/qsoftkeymanager_p.h | 2 +- src/gui/widgets/qcombobox.cpp | 4 ++++ src/gui/widgets/qmainwindow.cpp | 5 +++++ src/gui/widgets/qmenu.cpp | 20 +++++++++++++++++--- 6 files changed, 40 insertions(+), 13 deletions(-) diff --git a/src/gui/itemviews/qabstractitemview.cpp b/src/gui/itemviews/qabstractitemview.cpp index cbd9a8a..adf3ce3 100644 --- a/src/gui/itemviews/qabstractitemview.cpp +++ b/src/gui/itemviews/qabstractitemview.cpp @@ -1540,6 +1540,11 @@ bool QAbstractItemView::event(QEvent *event) case QEvent::FontChange: d->doDelayedItemsLayout(); // the size of the items will change break; +#ifdef QT_SOFTKEYS_ENABLED + case QEvent::LanguageChange: + d->doneSoftKey->setText(QSoftKeyManager::standardSoftKeyText(QSoftKeyManager::DoneSoftKey)); + break; +#endif default: break; } diff --git a/src/gui/kernel/qsoftkeymanager.cpp b/src/gui/kernel/qsoftkeymanager.cpp index 6d108b0..7412b06 100644 --- a/src/gui/kernel/qsoftkeymanager.cpp +++ b/src/gui/kernel/qsoftkeymanager.cpp @@ -55,24 +55,24 @@ QT_BEGIN_NAMESPACE QSoftKeyManager *QSoftKeyManagerPrivate::self = 0; -const char *QSoftKeyManager::standardSoftKeyText(StandardSoftKey standardKey) +QString QSoftKeyManager::standardSoftKeyText(StandardSoftKey standardKey) { - const char *softKeyText = 0; + QString softKeyText; switch (standardKey) { case OkSoftKey: - softKeyText = QT_TRANSLATE_NOOP("QSoftKeyManager", "Ok"); + softKeyText = QSoftKeyManager::tr("Ok"); break; case SelectSoftKey: - softKeyText = QT_TRANSLATE_NOOP("QSoftKeyManager", "Select"); + softKeyText = QSoftKeyManager::tr("Select"); break; case DoneSoftKey: - softKeyText = QT_TRANSLATE_NOOP("QSoftKeyManager", "Done"); + softKeyText = QSoftKeyManager::tr("Done"); break; case MenuSoftKey: - softKeyText = QT_TRANSLATE_NOOP("QSoftKeyManager", "Options"); + softKeyText = QSoftKeyManager::tr("Options"); break; case CancelSoftKey: - softKeyText = QT_TRANSLATE_NOOP("QSoftKeyManager", "Cancel"); + softKeyText = QSoftKeyManager::tr("Cancel"); break; default: break; @@ -100,8 +100,7 @@ QSoftKeyManager::QSoftKeyManager() : QAction *QSoftKeyManager::createAction(StandardSoftKey standardKey, QWidget *actionWidget) { - const char* text = standardSoftKeyText(standardKey); - QAction *action = new QAction(QSoftKeyManager::tr(text), actionWidget); + QAction *action = new QAction(standardSoftKeyText(standardKey), actionWidget); QAction::SoftKeyRole softKeyRole = QAction::NoSoftKey; switch (standardKey) { case MenuSoftKey: // FALL-THROUGH diff --git a/src/gui/kernel/qsoftkeymanager_p.h b/src/gui/kernel/qsoftkeymanager_p.h index ce902fe..a6fe17e 100644 --- a/src/gui/kernel/qsoftkeymanager_p.h +++ b/src/gui/kernel/qsoftkeymanager_p.h @@ -87,6 +87,7 @@ public: static QAction *createAction(StandardSoftKey standardKey, QWidget *actionWidget); static QAction *createKeyedAction(StandardSoftKey standardKey, Qt::Key key, QWidget *actionWidget); + static QString standardSoftKeyText(StandardSoftKey standardKey); protected: bool event(QEvent *e); @@ -94,7 +95,6 @@ protected: private: QSoftKeyManager(); static QSoftKeyManager *instance(); - static const char *standardSoftKeyText(StandardSoftKey standardKey); bool appendSoftkeys(const QWidget &source, int level); QWidget *softkeySource(QWidget *previousSource, bool& recursiveMerging); bool handleUpdateSoftKeys(); diff --git a/src/gui/widgets/qcombobox.cpp b/src/gui/widgets/qcombobox.cpp index 72f32dc..c4340e2 100644 --- a/src/gui/widgets/qcombobox.cpp +++ b/src/gui/widgets/qcombobox.cpp @@ -607,7 +607,11 @@ void QComboBoxPrivateContainer::changeEvent(QEvent *e) view->setMouseTracking(combo->style()->styleHint(QStyle::SH_ComboBox_ListMouseTracking, &opt, combo) || combo->style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, combo)); setFrameStyle(combo->style()->styleHint(QStyle::SH_ComboBox_PopupFrameStyle, &opt, combo)); + } else if (e->type() == QEvent::LanguageChange) { + selectAction->setText(QSoftKeyManager::standardSoftKeyText(QSoftKeyManager::SelectSoftKey)); + cancelAction->setText(QSoftKeyManager::standardSoftKeyText(QSoftKeyManager::CancelSoftKey)); } + QWidget::changeEvent(e); } diff --git a/src/gui/widgets/qmainwindow.cpp b/src/gui/widgets/qmainwindow.cpp index 269cd12..e7c4f45 100644 --- a/src/gui/widgets/qmainwindow.cpp +++ b/src/gui/widgets/qmainwindow.cpp @@ -1426,6 +1426,11 @@ bool QMainWindow::event(QEvent *event) } break; #endif +#ifdef QT_SOFTKEYS_ENABLED + case QEvent::LanguageChange: + d->menuBarAction->setText(QSoftKeyManager::standardSoftKeyText(QSoftKeyManager::MenuSoftKey)); + break; +#endif default: break; } diff --git a/src/gui/widgets/qmenu.cpp b/src/gui/widgets/qmenu.cpp index 8ce7cc0..42b7406 100644 --- a/src/gui/widgets/qmenu.cpp +++ b/src/gui/widgets/qmenu.cpp @@ -117,7 +117,7 @@ public: if (parentWidget->parentWidget()) parentWidget = parentWidget->parentWidget(); setParent(parentWidget, Qt::Window | Qt::Tool); - setAttribute(Qt::WA_DeleteOnClose, true); + setAttribute(Qt::WA_DeleteOnClose, true); setAttribute(Qt::WA_X11NetWmWindowTypeMenu, true); setWindowTitle(p->windowTitle()); setEnabled(p->isEnabled()); @@ -1226,7 +1226,7 @@ void QMenu::initStyleOption(QStyleOptionMenuItem *option, const QAction *action) else if (action->isSeparator()) option->menuItemType = QStyleOptionMenuItem::Separator; else if (d->defaultAction == action) - option->menuItemType = QStyleOptionMenuItem::DefaultItem; + option->menuItemType = QStyleOptionMenuItem::DefaultItem; else option->menuItemType = QStyleOptionMenuItem::Normal; if (action->isIconVisibleInMenu()) @@ -1719,7 +1719,14 @@ bool QMenu::isEmpty() const void QMenu::clear() { QList acts = actions(); + for(int i = 0; i < acts.size(); i++) { +#ifdef QT_SOFTKEYS_ENABLED + Q_D(QMenu); + // Lets not touch to our internal softkey actions + if(acts[i] == d->selectAction || acts[i] == d->cancelAction) + continue; +#endif removeAction(acts[i]); if (acts[i]->parent() == this && acts[i]->d_func()->widgets.isEmpty()) delete acts[i]; @@ -2408,6 +2415,13 @@ QMenu::event(QEvent *e) } return true; #endif +#ifdef QT_SOFTKEYS_ENABLED + case QEvent::LanguageChange: { + d->selectAction->setText(QSoftKeyManager::standardSoftKeyText(QSoftKeyManager::SelectSoftKey)); + d->cancelAction->setText(QSoftKeyManager::standardSoftKeyText(QSoftKeyManager::CancelSoftKey)); + } + break; +#endif default: break; } @@ -2919,7 +2933,7 @@ void QMenu::actionEvent(QActionEvent *e) #endif if (isVisible()) { d->updateActionRects(); - resize(sizeHint()); + resize(sizeHint()); update(); } } -- cgit v0.12 From 095496e02610c66d34cf3ee0fc329abed2be47e3 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Tue, 16 Feb 2010 17:28:40 +0100 Subject: Change all ptrdiff_t to qptrdiff. Reviewed-By: Bradley T. Hughes --- src/corelib/concurrent/qfuture.h | 2 +- src/corelib/tools/qcontiguouscache.h | 2 +- src/corelib/tools/qhash.h | 6 +++--- src/corelib/tools/qlinkedlist.h | 6 +++--- src/corelib/tools/qlist.h | 6 +++--- src/corelib/tools/qmap.h | 6 +++--- src/corelib/tools/qset.h | 7 +++---- src/corelib/tools/qsharedpointer_impl.h | 4 ++-- src/corelib/tools/qvector.h | 6 +++--- 9 files changed, 22 insertions(+), 23 deletions(-) diff --git a/src/corelib/concurrent/qfuture.h b/src/corelib/concurrent/qfuture.h index e402335..02ae40a 100644 --- a/src/corelib/concurrent/qfuture.h +++ b/src/corelib/concurrent/qfuture.h @@ -111,7 +111,7 @@ public: { public: typedef std::bidirectional_iterator_tag iterator_category; - typedef ptrdiff_t difference_type; + typedef qptrdiff difference_type; typedef T value_type; typedef const T *pointer; typedef const T &reference; diff --git a/src/corelib/tools/qcontiguouscache.h b/src/corelib/tools/qcontiguouscache.h index aa5603d..f767962 100644 --- a/src/corelib/tools/qcontiguouscache.h +++ b/src/corelib/tools/qcontiguouscache.h @@ -97,7 +97,7 @@ public: typedef const value_type* const_pointer; typedef value_type& reference; typedef const value_type& const_reference; - typedef ptrdiff_t difference_type; + typedef qptrdiff difference_type; typedef int size_type; explicit QContiguousCache(int capacity = 0); diff --git a/src/corelib/tools/qhash.h b/src/corelib/tools/qhash.h index 5e93523..05eae42 100644 --- a/src/corelib/tools/qhash.h +++ b/src/corelib/tools/qhash.h @@ -329,7 +329,7 @@ public: public: typedef std::bidirectional_iterator_tag iterator_category; - typedef ptrdiff_t difference_type; + typedef qptrdiff difference_type; typedef T value_type; typedef T *pointer; typedef T &reference; @@ -394,7 +394,7 @@ public: public: typedef std::bidirectional_iterator_tag iterator_category; - typedef ptrdiff_t difference_type; + typedef qptrdiff difference_type; typedef T value_type; typedef const T *pointer; typedef const T &reference; @@ -478,7 +478,7 @@ public: // STL compatibility typedef T mapped_type; typedef Key key_type; - typedef ptrdiff_t difference_type; + typedef qptrdiff difference_type; typedef int size_type; inline bool empty() const { return isEmpty(); } diff --git a/src/corelib/tools/qlinkedlist.h b/src/corelib/tools/qlinkedlist.h index f6de966..bfcf24f 100644 --- a/src/corelib/tools/qlinkedlist.h +++ b/src/corelib/tools/qlinkedlist.h @@ -113,7 +113,7 @@ public: { public: typedef std::bidirectional_iterator_tag iterator_category; - typedef ptrdiff_t difference_type; + typedef qptrdiff difference_type; typedef T value_type; typedef T *pointer; typedef T &reference; @@ -146,7 +146,7 @@ public: { public: typedef std::bidirectional_iterator_tag iterator_category; - typedef ptrdiff_t difference_type; + typedef qptrdiff difference_type; typedef T value_type; typedef const T *pointer; typedef const T &reference; @@ -212,7 +212,7 @@ public: typedef const value_type *const_pointer; typedef value_type &reference; typedef const value_type &const_reference; - typedef ptrdiff_t difference_type; + typedef qptrdiff difference_type; #ifndef QT_NO_STL static inline QLinkedList fromStdList(const std::list &list) diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h index 120442d..1ad7528 100644 --- a/src/corelib/tools/qlist.h +++ b/src/corelib/tools/qlist.h @@ -163,7 +163,7 @@ public: public: Node *i; typedef std::random_access_iterator_tag iterator_category; - typedef ptrdiff_t difference_type; + typedef qptrdiff difference_type; typedef T value_type; typedef T *pointer; typedef T &reference; @@ -210,7 +210,7 @@ public: public: Node *i; typedef std::random_access_iterator_tag iterator_category; - typedef ptrdiff_t difference_type; + typedef qptrdiff difference_type; typedef T value_type; typedef const T *pointer; typedef const T &reference; @@ -289,7 +289,7 @@ public: typedef const value_type *const_pointer; typedef value_type &reference; typedef const value_type &const_reference; - typedef ptrdiff_t difference_type; + typedef qptrdiff difference_type; #ifdef QT3_SUPPORT inline QT3_SUPPORT iterator remove(iterator pos) { return erase(pos); } diff --git a/src/corelib/tools/qmap.h b/src/corelib/tools/qmap.h index e71064c..4679812 100644 --- a/src/corelib/tools/qmap.h +++ b/src/corelib/tools/qmap.h @@ -213,7 +213,7 @@ public: public: typedef std::bidirectional_iterator_tag iterator_category; - typedef ptrdiff_t difference_type; + typedef qptrdiff difference_type; typedef T value_type; typedef T *pointer; typedef T &reference; @@ -281,7 +281,7 @@ public: public: typedef std::bidirectional_iterator_tag iterator_category; - typedef ptrdiff_t difference_type; + typedef qptrdiff difference_type; typedef T value_type; typedef const T *pointer; typedef const T &reference; @@ -384,7 +384,7 @@ public: // STL compatibility typedef Key key_type; typedef T mapped_type; - typedef ptrdiff_t difference_type; + typedef qptrdiff difference_type; typedef int size_type; inline bool empty() const { return isEmpty(); } diff --git a/src/corelib/tools/qset.h b/src/corelib/tools/qset.h index 6525880..b266deb 100644 --- a/src/corelib/tools/qset.h +++ b/src/corelib/tools/qset.h @@ -97,7 +97,7 @@ public: public: typedef std::bidirectional_iterator_tag iterator_category; - typedef ptrdiff_t difference_type; + typedef qptrdiff difference_type; typedef T value_type; typedef const T *pointer; typedef const T &reference; @@ -132,7 +132,7 @@ public: public: typedef std::bidirectional_iterator_tag iterator_category; - typedef ptrdiff_t difference_type; + typedef qptrdiff difference_type; typedef T value_type; typedef const T *pointer; typedef const T &reference; @@ -188,11 +188,10 @@ public: typedef const value_type *const_pointer; typedef value_type &reference; typedef const value_type &const_reference; - typedef ptrdiff_t difference_type; + typedef qptrdiff difference_type; typedef int size_type; inline bool empty() const { return isEmpty(); } - // comfort inline QSet &operator<<(const T &value) { insert(value); return *this; } inline QSet &operator|=(const QSet &other) { unite(other); return *this; } diff --git a/src/corelib/tools/qsharedpointer_impl.h b/src/corelib/tools/qsharedpointer_impl.h index 8fbfcda..964b279 100644 --- a/src/corelib/tools/qsharedpointer_impl.h +++ b/src/corelib/tools/qsharedpointer_impl.h @@ -132,7 +132,7 @@ namespace QtSharedPointer { typedef const value_type *const_pointer; typedef value_type &reference; typedef const value_type &const_reference; - typedef ptrdiff_t difference_type; + typedef qptrdiff difference_type; inline T *data() const { return value; } inline bool isNull() const { return !data(); } @@ -541,7 +541,7 @@ public: typedef const value_type *const_pointer; typedef value_type &reference; typedef const value_type &const_reference; - typedef ptrdiff_t difference_type; + typedef qptrdiff difference_type; inline bool isNull() const { return d == 0 || d->strongref == 0 || value == 0; } #ifndef Q_CC_NOKIAX86 diff --git a/src/corelib/tools/qvector.h b/src/corelib/tools/qvector.h index 90b7442..ac7c795 100644 --- a/src/corelib/tools/qvector.h +++ b/src/corelib/tools/qvector.h @@ -163,7 +163,7 @@ public: public: T *i; typedef std::random_access_iterator_tag iterator_category; - typedef ptrdiff_t difference_type; + typedef qptrdiff difference_type; typedef T value_type; typedef T *pointer; typedef T &reference; @@ -196,7 +196,7 @@ public: public: T *i; typedef std::random_access_iterator_tag iterator_category; - typedef ptrdiff_t difference_type; + typedef qptrdiff difference_type; typedef T value_type; typedef const T *pointer; typedef const T &reference; @@ -260,7 +260,7 @@ public: typedef const value_type* const_pointer; typedef value_type& reference; typedef const value_type& const_reference; - typedef ptrdiff_t difference_type; + typedef qptrdiff difference_type; typedef iterator Iterator; typedef const_iterator ConstIterator; typedef int size_type; -- cgit v0.12 From fc1f21b62243bc377889bf142da3b6ecad05aff0 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Wed, 17 Feb 2010 10:04:19 +0100 Subject: Fix handling of Evaluation licenses on the Windows configure.exe Reviewed-By: Marius Storm-Olsen --- configure.exe | Bin 1180160 -> 1179136 bytes tools/configure/tools.cpp | 3 ++- 2 files changed, 2 insertions(+), 1 deletion(-) mode change 100644 => 100755 configure.exe diff --git a/configure.exe b/configure.exe old mode 100644 new mode 100755 index 8913de1..09f4ef2 Binary files a/configure.exe and b/configure.exe differ diff --git a/tools/configure/tools.cpp b/tools/configure/tools.cpp index aea2713..c4625af 100644 --- a/tools/configure/tools.cpp +++ b/tools/configure/tools.cpp @@ -146,6 +146,7 @@ void Tools::checkLicense(QMap &dictionary, QMap &dictionary, QMap Date: Wed, 17 Feb 2010 15:11:50 +0100 Subject: Added note to make QList destructor virtual in version 5 Reviewed-by: TrustMe --- src/corelib/tools/qlist.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h index 1ad7528..a549f2f 100644 --- a/src/corelib/tools/qlist.h +++ b/src/corelib/tools/qlist.h @@ -112,7 +112,7 @@ class QList public: inline QList() : d(&QListData::shared_null) { d->ref.ref(); } inline QList(const QList &l) : d(l.d) { d->ref.ref(); if (!d->sharable) detach_helper(); } - ~QList(); + ~QList(); // ### Qt5: make this destructor virtual QList &operator=(const QList &l); bool operator==(const QList &l) const; inline bool operator!=(const QList &l) const { return !(*this == l); } -- cgit v0.12 From ac523359aa630c05df21d4c09970cb0b89a5b05f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Nilsen?= Date: Wed, 17 Feb 2010 15:21:46 +0100 Subject: Stabilize QGraphicsItem benchmarks. The benchmark must report stable numbers in order to be useful. E.g. we can not accept instability of +-20% between each run (with the same configuration in the same environment). --- .../qgraphicsitem/tst_qgraphicsitem.cpp | 30 +++++++++++++++++----- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/tests/benchmarks/gui/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/benchmarks/gui/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp index ac51072..d452593 100644 --- a/tests/benchmarks/gui/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp +++ b/tests/benchmarks/gui/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp @@ -55,6 +55,7 @@ public: virtual ~tst_QGraphicsItem(); public slots: + void initTestCase(); void init(); void cleanup(); @@ -82,8 +83,23 @@ tst_QGraphicsItem::~tst_QGraphicsItem() { } +static inline void processEvents() +{ + QApplication::flush(); + QApplication::processEvents(); + QApplication::processEvents(); +} + +void tst_QGraphicsItem::initTestCase() +{ + QApplication::flush(); + QTest::qWait(1500); + processEvents(); +} + void tst_QGraphicsItem::init() { + processEvents(); } void tst_QGraphicsItem::cleanup() @@ -152,10 +168,10 @@ void tst_QGraphicsItem::setPos() QGraphicsScene scene; QGraphicsRectItem *rect = scene.addRect(QRectF(0, 0, 100, 100)); + processEvents(); QBENCHMARK { rect->setPos(10, 10); - rect->transform(); // prevent lazy optimizing } } @@ -177,10 +193,10 @@ void tst_QGraphicsItem::setTransform() QGraphicsScene scene; QGraphicsRectItem *item = scene.addRect(QRectF(0, 0, 100, 100)); + processEvents(); QBENCHMARK { item->setTransform(transform); - item->transform(); // prevent lazy optimizing } } @@ -188,10 +204,10 @@ void tst_QGraphicsItem::rotate() { QGraphicsScene scene; QGraphicsItem *item = scene.addRect(QRectF(0, 0, 100, 100)); + processEvents(); QBENCHMARK { item->rotate(45); - item->transform(); // prevent lazy optimizing } } @@ -199,10 +215,10 @@ void tst_QGraphicsItem::scale() { QGraphicsScene scene; QGraphicsItem *item = scene.addRect(QRectF(0, 0, 100, 100)); + processEvents(); QBENCHMARK { item->scale(2, 2); - item->transform(); // prevent lazy optimizing } } @@ -210,10 +226,10 @@ void tst_QGraphicsItem::shear() { QGraphicsScene scene; QGraphicsItem *item = scene.addRect(QRectF(0, 0, 100, 100)); + processEvents(); QBENCHMARK { item->shear(1.5, 1.5); - item->transform(); // prevent lazy optimizing } } @@ -221,10 +237,10 @@ void tst_QGraphicsItem::translate() { QGraphicsScene scene; QGraphicsItem *item = scene.addRect(QRectF(0, 0, 100, 100)); + processEvents(); QBENCHMARK { item->translate(100, 100); - item->transform(); // prevent lazy optimizing } } @@ -232,10 +248,10 @@ void tst_QGraphicsItem::setRotation() { QGraphicsScene scene; QGraphicsItem *item = scene.addRect(QRectF(0, 0, 100, 100)); + processEvents(); QBENCHMARK { item->setRotation(45); - item->transform(); // prevent lazy optimizing } } -- cgit v0.12 From 2c53e6c50e7f47fa60b6cf8293651f8eaf05ebf1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Nilsen?= Date: Wed, 17 Feb 2010 15:35:36 +0100 Subject: Remove unstable test case from QGraphicsItem::setTransform benchmark. The item's transform is identity by default, so trying to set an indentiy transform again does too little in order to measure it with stable results. --- tests/benchmarks/gui/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/benchmarks/gui/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/benchmarks/gui/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp index d452593..ec77eb0 100644 --- a/tests/benchmarks/gui/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp +++ b/tests/benchmarks/gui/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp @@ -179,7 +179,6 @@ void tst_QGraphicsItem::setTransform_data() { QTest::addColumn("transform"); - QTest::newRow("id") << QTransform(); QTest::newRow("rotate 45z") << QTransform().rotate(45); QTest::newRow("scale 2x2") << QTransform().scale(2, 2); QTest::newRow("translate 100, 100") << QTransform().translate(100, 100); -- cgit v0.12 From 9531f924478d78f0a679305cd2e5f1b4c4dd849e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Nilsen?= Date: Wed, 17 Feb 2010 15:50:44 +0100 Subject: Remove unusable test case from QGraphicsItem benchmark. setRotation() is already covered by the rotate() test case. --- .../gui/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/tests/benchmarks/gui/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/benchmarks/gui/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp index ec77eb0..e17cf1c 100644 --- a/tests/benchmarks/gui/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp +++ b/tests/benchmarks/gui/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp @@ -72,7 +72,6 @@ private slots: void scale(); void shear(); void translate(); - void setRotation(); }; tst_QGraphicsItem::tst_QGraphicsItem() @@ -243,16 +242,5 @@ void tst_QGraphicsItem::translate() } } -void tst_QGraphicsItem::setRotation() -{ - QGraphicsScene scene; - QGraphicsItem *item = scene.addRect(QRectF(0, 0, 100, 100)); - processEvents(); - - QBENCHMARK { - item->setRotation(45); - } -} - QTEST_MAIN(tst_QGraphicsItem) #include "tst_qgraphicsitem.moc" -- cgit v0.12 From 59b646dfde1923bbd1f24d7cbb1920d56af7a0b1 Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Wed, 17 Feb 2010 15:51:44 +0100 Subject: Doc fix, ensure that the \obsolete tag is placed correctly If its not placed in the right place then it will cause the doc to lose the line that \obsolete is on Reviewed-by: TrustMe --- src/gui/graphicsview/qgraphicsview.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/gui/graphicsview/qgraphicsview.cpp b/src/gui/graphicsview/qgraphicsview.cpp index 96b9373..06b7438 100644 --- a/src/gui/graphicsview/qgraphicsview.cpp +++ b/src/gui/graphicsview/qgraphicsview.cpp @@ -3609,6 +3609,8 @@ void QGraphicsView::drawForeground(QPainter *painter, const QRectF &rect) } /*! + \obsolete + Draws the items \a items in the scene using \a painter, after the background and before the foreground are drawn. \a numItems is the number of items in \a items and options in \a options. \a options is a list of @@ -3617,7 +3619,7 @@ void QGraphicsView::drawForeground(QPainter *painter, const QRectF &rect) The default implementation calls the scene's drawItems() function. - \obsolete Since Qt 4.6, this function is not called anymore unless + Since Qt 4.6, this function is not called anymore unless the QGraphicsView::IndirectPainting flag is given as an Optimization flag. -- cgit v0.12 From cafcb49b3f46915fef5106cfaa14a01079e537bc Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Wed, 17 Feb 2010 19:26:37 +0100 Subject: Fix compilation on Mac 32-bit. Reviewed-By: Trust Me --- src/corelib/codecs/qtextcodec.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/corelib/codecs/qtextcodec.h b/src/corelib/codecs/qtextcodec.h index 23c91c7..169fe82 100644 --- a/src/corelib/codecs/qtextcodec.h +++ b/src/corelib/codecs/qtextcodec.h @@ -170,7 +170,7 @@ private: friend class QXmlStreamWriter; friend class QXmlStreamWriterPrivate; -#if defined Q_XMLSTREAM_RENAME_SYMBOLS +#if defined(Q_OS_MAC32) || defined(Q_OS_AIX) friend class QCoreXmlStreamWriter; friend class QCoreXmlStreamWriterPrivate; #endif -- cgit v0.12 From ce2f1065693e6944df40d2e04e20e83d59544a15 Mon Sep 17 00:00:00 2001 From: Iain Date: Wed, 17 Feb 2010 18:46:51 +0000 Subject: Use correct (forward slash) separators in qmake-generated bld.inf We should always use forward slash as a directory separator in include paths - it's not OS dependant. Task-number: QTBUG-8308 Reviewed-by: Alessandro Portale --- qmake/generators/symbian/symmake.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qmake/generators/symbian/symmake.cpp b/qmake/generators/symbian/symmake.cpp index 61988d3..2055f81 100644 --- a/qmake/generators/symbian/symmake.cpp +++ b/qmake/generators/symbian/symmake.cpp @@ -1348,7 +1348,7 @@ void SymbianMakefileGenerator::writeBldInfContent(QTextStream &t, bool addDeploy removeSpecialCharacters(bldinfDefine); t << "#ifndef " << bldinfDefine << endl; - t << "\t#include \"" << QDir::toNativeSeparators(bldinfFilename) << "\"" << endl; + t << "\t#include \"" << bldinfFilename << "\"" << endl; t << "#endif // " << bldinfDefine << endl; } -- cgit v0.12 From 884ea10d037d855b91ea5ef947b5c23d2f09aead Mon Sep 17 00:00:00 2001 From: Dirk Mueller Date: Wed, 17 Feb 2010 23:04:34 +0100 Subject: Fix undefined sequence point compiler warning level = ++level is not guaranteed to work, as the increment is not required to happen before the assignment. Change this code to be less obscure and use standard defined behavior. Merge-request: 471 Reviewed-by: Thiago Macieira --- src/gui/kernel/qsoftkeymanager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/kernel/qsoftkeymanager.cpp b/src/gui/kernel/qsoftkeymanager.cpp index 6d108b0..d89276f 100644 --- a/src/gui/kernel/qsoftkeymanager.cpp +++ b/src/gui/kernel/qsoftkeymanager.cpp @@ -215,7 +215,7 @@ bool QSoftKeyManager::handleUpdateSoftKeys() if (source) { bool added = appendSoftkeys(*source, level); source = softkeySource(source, recursiveMerging); - level = added ? ++level : level; + level = added ? level + 1 : level; } } while (source); -- cgit v0.12 From cdf4701f442149546043b155cddcc53116875f1c Mon Sep 17 00:00:00 2001 From: Dirk Mueller Date: Wed, 17 Feb 2010 23:17:36 +0100 Subject: Fix s390(x) atomic ops related crashes The s390 implementation of the pointer related atomic ops never worked before, and the memory barrier was mixed up between the Acquire and the Relaxed variant. This fixes both. Merge-request: 2312 Reviewed-by: Thiago Macieira --- src/corelib/arch/qatomic_s390.h | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/corelib/arch/qatomic_s390.h b/src/corelib/arch/qatomic_s390.h index 21f5037..273c17b 100644 --- a/src/corelib/arch/qatomic_s390.h +++ b/src/corelib/arch/qatomic_s390.h @@ -366,11 +366,9 @@ template Q_INLINE_TEMPLATE T* QBasicAtomicPointer::fetchAndStoreRelaxed(T *newValue) { #ifndef __s390x__ - return (T*)__CS_OLD_LOOP(reinterpret_cast(_q_value), (int)newValue, "lr", - "", "bcr 15,0\n"); + return (T*)__CS_OLD_LOOP(&_q_value, (int)newValue, "lr", "", ""); #else - return (T*)__CSG_OLD_LOOP(reinterpret_cast(_q_value), (long)newValue, "lgr", - "", "bcr 15,0\n"); + return (T*)__CSG_OLD_LOOP(&_q_value, (long)newValue, "lgr", "", ""); #endif } @@ -378,9 +376,9 @@ template Q_INLINE_TEMPLATE T* QBasicAtomicPointer::fetchAndStoreAcquire(T *newValue) { #ifndef __s390x__ - return (T*)__CS_OLD_LOOP(reinterpret_cast(_q_value), (int)newValue, "lr", "", ""); + return (T*)__CS_OLD_LOOP(&_q_value, (int)newValue, "lr", "", "bcr 15,0 \n"); #else - return (T*)__CSG_OLD_LOOP(reinterpret_cast(_q_value), (long)newValue, "lgr", "", ""); + return (T*)__CSG_OLD_LOOP(&_q_value, (long)newValue, "lgr", "", "bcr 15,0 \n"); #endif } @@ -388,11 +386,9 @@ template Q_INLINE_TEMPLATE T* QBasicAtomicPointer::fetchAndStoreRelease(T *newValue) { #ifndef __s390x__ - return (T*)__CS_OLD_LOOP(reinterpret_cast(_q_value), (int)newValue, "lr", - "bcr 15,0 \n", ""); + return (T*)__CS_OLD_LOOP(&_q_value, (int)newValue, "lr", "bcr 15,0 \n", ""); #else - return (T*)__CSG_OLD_LOOP(reinterpret_cast(_q_value), (long)newValue, "lgr", - "bcr 15,0\n", ""); + return (T*)__CSG_OLD_LOOP(&_q_value, (long)newValue, "lgr", "bcr 15,0\n", ""); #endif } -- cgit v0.12 From 48d25e6c9fcb5644ff6d9fdbe876c0a49413c583 Mon Sep 17 00:00:00 2001 From: Janne Anttila Date: Thu, 18 Feb 2010 09:52:54 +0200 Subject: Fixed softkey localizaton to comile also on platforms without softkeys. Task-number: QTBUG-6785 Reviewed-by: TrustMe --- src/gui/widgets/qcombobox.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/gui/widgets/qcombobox.cpp b/src/gui/widgets/qcombobox.cpp index c4340e2..585db70 100644 --- a/src/gui/widgets/qcombobox.cpp +++ b/src/gui/widgets/qcombobox.cpp @@ -607,9 +607,11 @@ void QComboBoxPrivateContainer::changeEvent(QEvent *e) view->setMouseTracking(combo->style()->styleHint(QStyle::SH_ComboBox_ListMouseTracking, &opt, combo) || combo->style()->styleHint(QStyle::SH_ComboBox_Popup, &opt, combo)); setFrameStyle(combo->style()->styleHint(QStyle::SH_ComboBox_PopupFrameStyle, &opt, combo)); +#ifdef QT_SOFTKEYS_ENABLED } else if (e->type() == QEvent::LanguageChange) { selectAction->setText(QSoftKeyManager::standardSoftKeyText(QSoftKeyManager::SelectSoftKey)); cancelAction->setText(QSoftKeyManager::standardSoftKeyText(QSoftKeyManager::CancelSoftKey)); +#endif } QWidget::changeEvent(e); -- cgit v0.12 From c07f8354bec3c7b6d78f798589119ed0ab4f1332 Mon Sep 17 00:00:00 2001 From: ck Date: Fri, 12 Feb 2010 11:29:20 +0100 Subject: Help system: Handle all Clucene exceptions. Reviewed-by: kh1 --- .../lib/qhelpsearchindexwriter_clucene.cpp | 230 ++++++++++----------- 1 file changed, 112 insertions(+), 118 deletions(-) diff --git a/tools/assistant/lib/qhelpsearchindexwriter_clucene.cpp b/tools/assistant/lib/qhelpsearchindexwriter_clucene.cpp index e3cc2b0..2eeefb5 100644 --- a/tools/assistant/lib/qhelpsearchindexwriter_clucene.cpp +++ b/tools/assistant/lib/qhelpsearchindexwriter_clucene.cpp @@ -613,67 +613,69 @@ void QHelpSearchIndexWriter::optimizeIndex() void QHelpSearchIndexWriter::run() { - QMutexLocker mutexLocker(&mutex); +#if !defined(QT_NO_EXCEPTIONS) + try { +#endif + QMutexLocker mutexLocker(&mutex); - if (m_cancel) - return; + if (m_cancel) + return; - const bool reindex = this->m_reindex; - const QString collectionFile(this->m_collectionFile); + const bool reindex = this->m_reindex; + const QString collectionFile(this->m_collectionFile); - mutexLocker.unlock(); + mutexLocker.unlock(); - QHelpEngineCore engine(collectionFile, 0); - if (!engine.setupData()) - return; + QHelpEngineCore engine(collectionFile, 0); + if (!engine.setupData()) + return; - const QLatin1String key("CluceneIndexedNamespaces"); - if (reindex) - engine.setCustomValue(key, QLatin1String("")); - - QMap indexMap; - const QLatin1String oldKey("CluceneSearchNamespaces"); - if (!engine.customValue(oldKey, QString()).isNull()) { - // old style qhc file < 4.4.2, need to convert... - const QStringList indexedNamespaces = engine.customValue(oldKey). - toString().split(QLatin1String("|"), QString::SkipEmptyParts); - foreach (const QString &nameSpace, indexedNamespaces) - indexMap.insert(nameSpace, QDateTime()); - engine.removeCustomValue(oldKey); - } else { - QDataStream dataStream(engine.customValue(key).toByteArray()); - dataStream >> indexMap; - } + const QLatin1String key("CluceneIndexedNamespaces"); + if (reindex) + engine.setCustomValue(key, QLatin1String("")); + + QMap indexMap; + const QLatin1String oldKey("CluceneSearchNamespaces"); + if (!engine.customValue(oldKey, QString()).isNull()) { + // old style qhc file < 4.4.2, need to convert... + const QStringList indexedNamespaces + = engine.customValue(oldKey).toString() + .split(QLatin1String("|"), QString::SkipEmptyParts); + foreach (const QString &nameSpace, indexedNamespaces) + indexMap.insert(nameSpace, QDateTime()); + engine.removeCustomValue(oldKey); + } else { + QDataStream dataStream(engine.customValue(key).toByteArray()); + dataStream >> indexMap; + } - QString indexPath = m_indexFilesFolder; + QString indexPath = m_indexFilesFolder; - QFileInfo fInfo(indexPath); - if (fInfo.exists() && !fInfo.isWritable()) { - qWarning("Full Text Search, could not create index (missing permissions for '%s').", qPrintable(indexPath)); - return; - } + QFileInfo fInfo(indexPath); + if (fInfo.exists() && !fInfo.isWritable()) { + qWarning("Full Text Search, could not create index (missing permissions for '%s').", + qPrintable(indexPath)); + return; + } - emit indexingStarted(); + emit indexingStarted(); - QCLuceneIndexWriter *writer = 0; - QCLuceneStandardAnalyzer analyzer; - const QStringList registeredDocs = engine.registeredDocumentations(); + QCLuceneIndexWriter *writer = 0; + QCLuceneStandardAnalyzer analyzer; + const QStringList registeredDocs = engine.registeredDocumentations(); - QLocalSocket localSocket; - localSocket.connectToServer(QString(QLatin1String("QtAssistant%1")) - .arg(QLatin1String(QT_VERSION_STR))); + QLocalSocket localSocket; + localSocket.connectToServer(QString(QLatin1String("QtAssistant%1")) + .arg(QLatin1String(QT_VERSION_STR))); - QLocalServer localServer; - bool otherInstancesRunning = true; - if (!localSocket.waitForConnected()) { - otherInstancesRunning = false; - localServer.listen(QString(QLatin1String("QtAssistant%1")) - .arg(QLatin1String(QT_VERSION_STR))); - } + QLocalServer localServer; + bool otherInstancesRunning = true; + if (!localSocket.waitForConnected()) { + otherInstancesRunning = false; + localServer.listen(QString(QLatin1String("QtAssistant%1")) + .arg(QLatin1String(QT_VERSION_STR))); + } -#if !defined(QT_NO_EXCEPTIONS) - try { -#endif // check if it's locked, and if the other instance is running if (!otherInstancesRunning && QCLuceneIndexReader::isLocked(indexPath)) QCLuceneIndexReader::unlock(indexPath); @@ -705,7 +707,8 @@ void QHelpSearchIndexWriter::run() removeDocuments(indexPath, namespaceName); } else { QString path = engine.documentationFileName(namespaceName); - if (indexMap.value(namespaceName) < QFileInfo(path).lastModified()) { + if (indexMap.value(namespaceName) + < QFileInfo(path).lastModified()) { // make sure we remove some outdated indexed stuff indexMap.remove(namespaceName); removeDocuments(indexPath, namespaceName); @@ -728,94 +731,85 @@ void QHelpSearchIndexWriter::run() indexMap.clear(); writer = new QCLuceneIndexWriter(indexPath, analyzer, true); } -#if !defined(QT_NO_EXCEPTIONS) - } catch (...) { - qWarning("Full Text Search, could not create index writer in '%s'.", - qPrintable(indexPath)); - return; - } -#endif -#if !defined(QT_NO_EXCEPTIONS) - try { -#endif writer->setMergeFactor(100); writer->setMinMergeDocs(1000); writer->setMaxFieldLength(QCLuceneIndexWriter::DEFAULT_MAX_FIELD_LENGTH); -#if !defined(QT_NO_EXCEPTIONS) - } catch (...) { - qWarning("Full Text Search, could not set writer properties."); - return; - } -#endif - QStringList namespaces; - foreach(const QString &namespaceName, registeredDocs) { - mutexLocker.relock(); - if (m_cancel) { - closeIndexWriter(writer); - emit indexingFinished(); - return; - } - mutexLocker.unlock(); + QStringList namespaces; + foreach(const QString &namespaceName, registeredDocs) { + mutexLocker.relock(); + if (m_cancel) { + closeIndexWriter(writer); + emit indexingFinished(); + return; + } + mutexLocker.unlock(); - namespaces.append(namespaceName); - if (indexMap.contains(namespaceName)) - continue; + namespaces.append(namespaceName); + if (indexMap.contains(namespaceName)) + continue; - const QList attributeSets = - engine.filterAttributeSets(namespaceName); + const QList attributeSets = + engine.filterAttributeSets(namespaceName); - if (attributeSets.isEmpty()) { - const QList docFiles = indexableFiles(&engine, namespaceName, - QStringList()); - if (!addDocuments(docFiles, engine, QStringList(), namespaceName, - writer, analyzer)) - break; - } else { - bool bail = false; - foreach (const QStringList &attributes, attributeSets) { - const QList docFiles = indexableFiles(&engine, - namespaceName, attributes); - if (!addDocuments(docFiles, engine, attributes, namespaceName, - writer, analyzer)) { - bail = true; + if (attributeSets.isEmpty()) { + const QList docFiles = indexableFiles(&engine, namespaceName, + QStringList()); + if (!addDocuments(docFiles, engine, QStringList(), namespaceName, + writer, analyzer)) break; + } else { + bool bail = false; + foreach (const QStringList &attributes, attributeSets) { + const QList docFiles = indexableFiles(&engine, + namespaceName, attributes); + if (!addDocuments(docFiles, engine, attributes, namespaceName, + writer, analyzer)) { + bail = true; + break; + } } + if (bail) + break; } - if (bail) - break; - } - mutexLocker.relock(); - if (!m_cancel) { - QString path(engine.documentationFileName(namespaceName)); - indexMap.insert(namespaceName, QFileInfo(path).lastModified()); - writeIndexMap(engine, indexMap); + mutexLocker.relock(); + if (!m_cancel) { + QString path(engine.documentationFileName(namespaceName)); + indexMap.insert(namespaceName, QFileInfo(path).lastModified()); + writeIndexMap(engine, indexMap); + } + mutexLocker.unlock(); } - mutexLocker.unlock(); - } - closeIndexWriter(writer); + closeIndexWriter(writer); - mutexLocker.relock(); - if (!m_cancel) { - mutexLocker.unlock(); - - QStringList indexedNamespaces = indexMap.keys(); - foreach(const QString &namespaceName, indexedNamespaces) { - mutexLocker.relock(); - if (m_cancel) - break; + mutexLocker.relock(); + if (!m_cancel) { mutexLocker.unlock(); - if (!namespaces.contains(namespaceName)) { - indexMap.remove(namespaceName); - writeIndexMap(engine, indexMap); - removeDocuments(indexPath, namespaceName); + QStringList indexedNamespaces = indexMap.keys(); + foreach(const QString &namespaceName, indexedNamespaces) { + mutexLocker.relock(); + if (m_cancel) + break; + mutexLocker.unlock(); + + if (!namespaces.contains(namespaceName)) { + indexMap.remove(namespaceName); + writeIndexMap(engine, indexMap); + removeDocuments(indexPath, namespaceName); + } } } + +#if !defined(QT_NO_EXCEPTIONS) + } catch (...) { + qWarning("%s: Failed because of CLucene exception.", Q_FUNC_INFO); } +#endif + emit indexingFinished(); } -- cgit v0.12 From 342b916ab4fb1a9c6f3a2608e7c5a43d6a763981 Mon Sep 17 00:00:00 2001 From: Iain Date: Thu, 18 Feb 2010 09:03:49 +0000 Subject: Use correct include path for qglobal.h Reviewed-by: Shane Kearns --- src/corelib/arch/qatomic_symbian.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/corelib/arch/qatomic_symbian.h b/src/corelib/arch/qatomic_symbian.h index f1d332f..fa4e4a9 100644 --- a/src/corelib/arch/qatomic_symbian.h +++ b/src/corelib/arch/qatomic_symbian.h @@ -42,7 +42,7 @@ #ifndef QATOMIC_SYMBIAN_H #define QATOMIC_SYMBIAN_H -#include +#include #include QT_BEGIN_HEADER -- cgit v0.12 From 92465142116ed140b4323c4a8f5bc325c45cdccf Mon Sep 17 00:00:00 2001 From: Sami Merila Date: Thu, 18 Feb 2010 11:06:49 +0200 Subject: QWebView scrolling doesn't clear old elements before painting again Author: Petri Date: Wed Feb 10 12:27:19 2010 +0200 Patch to QTBUG-7286 QWebView scrolling doesn't clear old elements before painting on top of them. The bug exists only if web page does not set its backgroung color. Solution is to set White color as a default color for web page backgrounds. White color was causing some visibility problem (at least with lineedit) and it was solved by editing ::canDrawThemeBackground Task-number: QTBUG-7286 Reviewed-by: Sami Merila --- src/gui/styles/qs60style.cpp | 23 ++++++++++++++++------- src/gui/styles/qs60style_p.h | 3 ++- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/gui/styles/qs60style.cpp b/src/gui/styles/qs60style.cpp index ea7399f..74707af 100644 --- a/src/gui/styles/qs60style.cpp +++ b/src/gui/styles/qs60style.cpp @@ -120,6 +120,8 @@ QPixmap *QS60StylePrivate::m_background = 0; // theme palette QPalette *QS60StylePrivate::m_themePalette = 0; +qint64 QS60StylePrivate::m_webPaletteKey = 0; + const struct QS60StylePrivate::frameElementCenter QS60StylePrivate::m_frameElementsData[] = { {SE_ButtonNormal, QS60StyleEnums::SP_QsnFrButtonTbCenter}, {SE_ButtonPressed, QS60StyleEnums::SP_QsnFrButtonTbCenterPressed}, @@ -807,8 +809,12 @@ void QS60StylePrivate::setThemePaletteHash(QPalette *palette) const QPalette webPalette = *palette; webPalette.setColor(QPalette::WindowText, Qt::black); webPalette.setColor(QPalette::Text, Qt::black); + webPalette.setBrush(QPalette::Base, Qt::white); + QApplication::setPalette(webPalette, "QWebView"); QApplication::setPalette(webPalette, "QGraphicsWebView"); + + m_webPaletteKey = webPalette.cacheKey(); } QSize QS60StylePrivate::partSize(QS60StyleEnums::SkinParts part, SkinElementFlags flags) @@ -896,8 +902,11 @@ QSize QS60StylePrivate::partSize(QS60StyleEnums::SkinParts part, SkinElementFlag return result; } -bool QS60StylePrivate::canDrawThemeBackground(const QBrush &backgroundBrush) +bool QS60StylePrivate::canDrawThemeBackground(const QBrush &backgroundBrush, const QWidget *widget) { + // Always return true for web pages. + if (widget && m_webPaletteKey == QApplication::palette(widget).cacheKey()) + return true; //If brush is not changed from style's default values, draw theme graphics. return (backgroundBrush.color() == Qt::transparent || backgroundBrush.style() == Qt::NoBrush) ? true : false; @@ -1901,7 +1910,7 @@ void QS60Style::drawControl(ControlElement element, const QStyleOption *option, case CE_ShapedFrame: if (const QTextEdit *textEdit = qobject_cast(widget)) { const QStyleOptionFrame *frame = qstyleoption_cast(option); - if (QS60StylePrivate::canDrawThemeBackground(frame->palette.base())) + if (QS60StylePrivate::canDrawThemeBackground(frame->palette.base(), widget)) QS60StylePrivate::drawSkinElement(QS60StylePrivate::SE_Editor, painter, option->rect, flags); else QCommonStyle::drawControl(element, option, painter, widget); @@ -2013,7 +2022,7 @@ void QS60Style::drawPrimitive(PrimitiveElement element, const QStyleOption *opti if (widget && qobject_cast(widget->parentWidget())) break; #endif - if (QS60StylePrivate::canDrawThemeBackground(option->palette.base())) + if (QS60StylePrivate::canDrawThemeBackground(option->palette.base(), widget)) QS60StylePrivate::drawSkinElement(QS60StylePrivate::SE_FrameLineEdit, painter, option->rect, flags); else commonStyleDraws = true; @@ -2093,7 +2102,7 @@ void QS60Style::drawPrimitive(PrimitiveElement element, const QStyleOption *opti case PE_PanelButtonTool: case PE_PanelButtonBevel: case PE_FrameButtonBevel: - if (QS60StylePrivate::canDrawThemeBackground(option->palette.base())) { + if (QS60StylePrivate::canDrawThemeBackground(option->palette.base(), widget)) { const bool isPressed = option->state & State_Sunken; const QS60StylePrivate::SkinElements skinElement = isPressed ? QS60StylePrivate::SE_ButtonPressed : QS60StylePrivate::SE_ButtonNormal; @@ -2125,7 +2134,7 @@ void QS60Style::drawPrimitive(PrimitiveElement element, const QStyleOption *opti case PE_IndicatorSpinDown: case PE_IndicatorSpinUp: if (const QStyleOptionSpinBox *spinBox = qstyleoption_cast(option)) { - if (QS60StylePrivate::canDrawThemeBackground(spinBox->palette.base())) { + if (QS60StylePrivate::canDrawThemeBackground(spinBox->palette.base(), widget)) { QStyleOptionSpinBox optionSpinBox = *spinBox; const QS60StyleEnums::SkinParts part = (element == PE_IndicatorSpinUp) ? QS60StyleEnums::SP_QgnGrafScrollArrowUp : @@ -2140,7 +2149,7 @@ void QS60Style::drawPrimitive(PrimitiveElement element, const QStyleOption *opti #endif //QT_NO_SPINBOX #ifndef QT_NO_COMBOBOX if (const QStyleOptionFrame *cmb = qstyleoption_cast(option)) { - if (QS60StylePrivate::canDrawThemeBackground( option->palette.base())) { + if (QS60StylePrivate::canDrawThemeBackground( option->palette.base(), widget)) { // We want to draw down arrow here for comboboxes as well. QStyleOptionFrame optionsComboBox = *cmb; const QS60StyleEnums::SkinParts part = QS60StyleEnums::SP_QgnGrafScrollArrowDown; @@ -2179,7 +2188,7 @@ void QS60Style::drawPrimitive(PrimitiveElement element, const QStyleOption *opti #endif //QT_NO_MENU ) { //Need extra check since dialogs have their own theme background - if (QS60StylePrivate::canDrawThemeBackground(option->palette.base()) && + if (QS60StylePrivate::canDrawThemeBackground(option->palette.base(), widget) && option->palette.window().texture().cacheKey() == QS60StylePrivate::m_themePalette->window().texture().cacheKey()) QS60StylePrivate::drawSkinElement(QS60StylePrivate::SE_OptionsMenu, painter, option->rect, flags); diff --git a/src/gui/styles/qs60style_p.h b/src/gui/styles/qs60style_p.h index ea30b81..16d82e7 100644 --- a/src/gui/styles/qs60style_p.h +++ b/src/gui/styles/qs60style_p.h @@ -542,7 +542,7 @@ public: //Checks that the current brush is transparent or has BrushStyle NoBrush, //so that theme graphic background can be drawn. - static bool canDrawThemeBackground(const QBrush &backgroundBrush); + static bool canDrawThemeBackground(const QBrush &backgroundBrush, const QWidget *widget); static int currentAnimationFrame(QS60StyleEnums::SkinParts part); #ifdef Q_WS_S60 @@ -596,6 +596,7 @@ private: QPalette m_originalPalette; QPointer m_focusFrame; + static qint64 m_webPaletteKey; #ifdef Q_WS_S60 //list of progress bars having animation running -- cgit v0.12 From a359db8f939ccbe8ce49c2ef71ff4585ab69c15e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20R=C3=B8dal?= Date: Wed, 17 Feb 2010 17:12:57 +0100 Subject: Fixed autotest failure in tst_QPainter::drawEllipse on Maemo. The previous fix (baa7c3bdecc) attempted to fall back to path drawing in QPainter::drawEllipse, however we have some specific filling rules for aliased ellipse drawing in the raster paint engine. We should use the (now free of fixed point math) drawEllipse_midpoint_i function on all platforms. Reviewed-by: Gunnar Sletta --- src/gui/painting/qpaintengine_raster.cpp | 8 -------- tests/auto/qpainter/tst_qpainter.cpp | 2 -- 2 files changed, 10 deletions(-) diff --git a/src/gui/painting/qpaintengine_raster.cpp b/src/gui/painting/qpaintengine_raster.cpp index 4a4792a..3c2cc8c 100644 --- a/src/gui/painting/qpaintengine_raster.cpp +++ b/src/gui/painting/qpaintengine_raster.cpp @@ -100,10 +100,6 @@ #endif #include -#if defined(QT_NO_FPU) || (_MSC_VER >= 1300 && _MSC_VER < 1400) -# define FLOATING_POINT_BUGGY_OR_NO_FPU -#endif - QT_BEGIN_NAMESPACE extern bool qt_scaleForTransform(const QTransform &transform, qreal *scale); // qtransform.cpp @@ -1827,7 +1823,6 @@ void QRasterPaintEngine::fill(const QVectorPath &path, const QBrush &brush) } } -#ifndef FLOATING_POINT_BUGGY_OR_NO_FPU if (path.shape() == QVectorPath::EllipseHint) { if (!s->flags.antialiased && s->matrix.type() <= QTransform::TxScale) { const qreal *p = path.points(); @@ -1847,7 +1842,6 @@ void QRasterPaintEngine::fill(const QVectorPath &path, const QBrush &brush) } } } -#endif // ### Optimize for non transformed ellipses and rectangles... QRectF cpRect = path.controlPointRect(); @@ -3674,7 +3668,6 @@ void QRasterPaintEngine::drawLines(const QLineF *lines, int lineCount) */ void QRasterPaintEngine::drawEllipse(const QRectF &rect) { -#ifndef FLOATING_POINT_BUGGY_OR_NO_FPU Q_D(QRasterPaintEngine); QRasterPaintEngineState *s = state(); @@ -3697,7 +3690,6 @@ void QRasterPaintEngine::drawEllipse(const QRectF &rect) return; } } -#endif QPaintEngineEx::drawEllipse(rect); } diff --git a/tests/auto/qpainter/tst_qpainter.cpp b/tests/auto/qpainter/tst_qpainter.cpp index 104728d..beb83a1 100644 --- a/tests/auto/qpainter/tst_qpainter.cpp +++ b/tests/auto/qpainter/tst_qpainter.cpp @@ -1580,10 +1580,8 @@ void tst_QPainter::drawClippedEllipse_data() void tst_QPainter::drawClippedEllipse() { QFETCH(QRect, rect); -#if defined(Q_OS_WINCE) || defined(Q_OS_SYMBIAN) if (sizeof(qreal) != sizeof(double)) QSKIP("Test only works for qreal==double", SkipAll); -#endif QImage image(rect.width() + 1, rect.height() + 1, QImage::Format_ARGB32_Premultiplied); QRect expected = QRect(rect.x(), rect.y(), rect.width()+1, rect.height()+1) -- cgit v0.12 From 08a40e6d4ef085c13d95c300c4df6b19caf7c483 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20R=C3=B8dal?= Date: Thu, 18 Feb 2010 10:10:39 +0100 Subject: Documented behavior of blur effect radius and drop shadow offset. Our graphics effects are always done in device coordinates (unless they can be done in logical coordinates with the same result as an optimization, e.g. opacity effects). Reviewed-by: Andy Shaw --- src/gui/effects/qgraphicseffect.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/gui/effects/qgraphicseffect.cpp b/src/gui/effects/qgraphicseffect.cpp index 7d1d03d..ce4ce6a 100644 --- a/src/gui/effects/qgraphicseffect.cpp +++ b/src/gui/effects/qgraphicseffect.cpp @@ -726,7 +726,8 @@ void QGraphicsColorizeEffect::draw(QPainter *painter) elements. The level of detail can be modified using the setBlurRadius() function. Use setBlurHints() to choose the blur hints. - By default, the blur radius is 5 pixels. + By default, the blur radius is 5 pixels. The blur radius is specified in + device coordinates. \img graphicseffect-blur.png @@ -781,6 +782,9 @@ QGraphicsBlurEffect::~QGraphicsBlurEffect() radius results in a more blurred appearance. By default, the blur radius is 5 pixels. + + The radius is given in device coordinates, meaning it is + unaffected by scale. */ qreal QGraphicsBlurEffect::blurRadius() const { @@ -884,7 +888,8 @@ void QGraphicsBlurEffect::draw(QPainter *painter) By default, the drop shadow is a semi-transparent dark gray (QColor(63, 63, 63, 180)) shadow, blurred with a radius of 1 at an offset - of 8 pixels towards the lower right. + of 8 pixels towards the lower right. The drop shadow offset is specified + in device coordinates. \img graphicseffect-drop-shadow.png @@ -913,6 +918,9 @@ QGraphicsDropShadowEffect::~QGraphicsDropShadowEffect() By default, the offset is 8 pixels towards the lower right. + The offset is given in device coordinates, which means it is + unaffected by scale. + \sa xOffset(), yOffset(), blurRadius(), color() */ QPointF QGraphicsDropShadowEffect::offset() const -- cgit v0.12 From 4971430290ecb11012ef5cbf8ef041da0ec3a824 Mon Sep 17 00:00:00 2001 From: Zeno Albisser Date: Thu, 18 Feb 2010 11:16:26 +0100 Subject: Revert "Added note to make QList destructor virtual in version 5" Virtual functions should not be used with copyable types due to slicing. This reverts commit c1db6c2c5a3bbe96a628207af169a032d535426f. --- src/corelib/tools/qlist.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h index a549f2f..1ad7528 100644 --- a/src/corelib/tools/qlist.h +++ b/src/corelib/tools/qlist.h @@ -112,7 +112,7 @@ class QList public: inline QList() : d(&QListData::shared_null) { d->ref.ref(); } inline QList(const QList &l) : d(l.d) { d->ref.ref(); if (!d->sharable) detach_helper(); } - ~QList(); // ### Qt5: make this destructor virtual + ~QList(); QList &operator=(const QList &l); bool operator==(const QList &l) const; inline bool operator!=(const QList &l) const { return !(*this == l); } -- cgit v0.12 From 2e8af9b06f7c25710253e517325644b5fa1ba17f Mon Sep 17 00:00:00 2001 From: ck Date: Thu, 18 Feb 2010 11:21:11 +0100 Subject: Help system: Remove hard-coded qt namespace. Task-number: QTBUG-7821 Reviewed-by: kh1 --- tools/assistant/lib/qhelpsearchengine.cpp | 6 +++--- tools/assistant/lib/qhelpsearchindexreader.cpp | 6 ++---- tools/assistant/lib/qhelpsearchindexreader_clucene.cpp | 10 ++++------ tools/assistant/lib/qhelpsearchindexreader_clucene_p.h | 10 ++++------ tools/assistant/lib/qhelpsearchindexreader_default.cpp | 10 ++++------ tools/assistant/lib/qhelpsearchindexreader_default_p.h | 10 ++++------ tools/assistant/lib/qhelpsearchindexreader_p.h | 6 ++---- tools/assistant/lib/qhelpsearchindexwriter_clucene.cpp | 10 ++++------ tools/assistant/lib/qhelpsearchindexwriter_clucene_p.h | 9 ++++----- tools/assistant/lib/qhelpsearchindexwriter_default.cpp | 10 ++++------ tools/assistant/lib/qhelpsearchindexwriter_default_p.h | 10 ++++------ 11 files changed, 39 insertions(+), 58 deletions(-) diff --git a/tools/assistant/lib/qhelpsearchengine.cpp b/tools/assistant/lib/qhelpsearchengine.cpp index 7c2635d..9914efa 100644 --- a/tools/assistant/lib/qhelpsearchengine.cpp +++ b/tools/assistant/lib/qhelpsearchengine.cpp @@ -63,9 +63,9 @@ QT_BEGIN_NAMESPACE #if defined(QT_CLUCENE_SUPPORT) - using namespace qt::fulltextsearch::clucene; + using namespace fulltextsearch::clucene; #else - using namespace qt::fulltextsearch::std; + using namespace fulltextsearch::std; #endif class QHelpSearchEnginePrivate : public QObject @@ -195,7 +195,7 @@ private: QHelpSearchQueryWidget *queryWidget; QHelpSearchResultWidget *resultWidget; - qt::fulltextsearch::QHelpSearchIndexReader *indexReader; + fulltextsearch::QHelpSearchIndexReader *indexReader; QHelpSearchIndexWriter *indexWriter; QPointer helpEngine; diff --git a/tools/assistant/lib/qhelpsearchindexreader.cpp b/tools/assistant/lib/qhelpsearchindexreader.cpp index 92d7658..e79fca6 100644 --- a/tools/assistant/lib/qhelpsearchindexreader.cpp +++ b/tools/assistant/lib/qhelpsearchindexreader.cpp @@ -43,8 +43,7 @@ QT_BEGIN_NAMESPACE -namespace qt { - namespace fulltextsearch { +namespace fulltextsearch { QHelpSearchIndexReader::QHelpSearchIndexReader() : QThread() @@ -100,7 +99,6 @@ QList QHelpSearchIndexReader::hits(int start, } - } // namespace fulltextsearch -} // namespace qt +} // namespace fulltextsearch QT_END_NAMESPACE diff --git a/tools/assistant/lib/qhelpsearchindexreader_clucene.cpp b/tools/assistant/lib/qhelpsearchindexreader_clucene.cpp index b5bec44..b050361 100644 --- a/tools/assistant/lib/qhelpsearchindexreader_clucene.cpp +++ b/tools/assistant/lib/qhelpsearchindexreader_clucene.cpp @@ -55,9 +55,8 @@ QT_BEGIN_NAMESPACE -namespace qt { - namespace fulltextsearch { - namespace clucene { +namespace fulltextsearch { +namespace clucene { QHelpSearchIndexReaderClucene::QHelpSearchIndexReaderClucene() : QHelpSearchIndexReader() @@ -387,8 +386,7 @@ void QHelpSearchIndexReaderClucene::boostSearchHits(const QHelpEngineCore &engin } } - } // namespace clucene - } // namespace fulltextsearch -} // namespace qt +} // namespace clucene +} // namespace fulltextsearch QT_END_NAMESPACE diff --git a/tools/assistant/lib/qhelpsearchindexreader_clucene_p.h b/tools/assistant/lib/qhelpsearchindexreader_clucene_p.h index 3e3b9dd..8f51cb1 100644 --- a/tools/assistant/lib/qhelpsearchindexreader_clucene_p.h +++ b/tools/assistant/lib/qhelpsearchindexreader_clucene_p.h @@ -60,9 +60,8 @@ QT_BEGIN_NAMESPACE -namespace qt { - namespace fulltextsearch { - namespace clucene { +namespace fulltextsearch { +namespace clucene { class QHelpSearchIndexReaderClucene : public QHelpSearchIndexReader { @@ -84,9 +83,8 @@ private: const QList &queryList); }; - } // namespace clucene - } // namespace fulltextsearch -} // namespace qt +} // namespace clucene +} // namespace fulltextsearch QT_END_NAMESPACE diff --git a/tools/assistant/lib/qhelpsearchindexreader_default.cpp b/tools/assistant/lib/qhelpsearchindexreader_default.cpp index d2241a5..11a50d9 100644 --- a/tools/assistant/lib/qhelpsearchindexreader_default.cpp +++ b/tools/assistant/lib/qhelpsearchindexreader_default.cpp @@ -52,9 +52,8 @@ QT_BEGIN_NAMESPACE -namespace qt { - namespace fulltextsearch { - namespace std { +namespace fulltextsearch { +namespace std { namespace { QStringList split( const QString &str ) @@ -607,8 +606,7 @@ void QHelpSearchIndexReaderDefault::run() emit searchingFinished(hitList.count()); } - } // namespace std - } // namespace fulltextsearch -} // namespace qt +} // namespace std +} // namespace fulltextsearch QT_END_NAMESPACE diff --git a/tools/assistant/lib/qhelpsearchindexreader_default_p.h b/tools/assistant/lib/qhelpsearchindexreader_default_p.h index 8c80608..b30fa4b 100644 --- a/tools/assistant/lib/qhelpsearchindexreader_default_p.h +++ b/tools/assistant/lib/qhelpsearchindexreader_default_p.h @@ -64,9 +64,8 @@ QT_BEGIN_NAMESPACE struct Entry; struct PosEntry; -namespace qt { - namespace fulltextsearch { - namespace std { +namespace fulltextsearch { +namespace std { class Reader { @@ -127,9 +126,8 @@ private: Reader m_reader; }; - } // namespace std - } // namespace fulltextsearch -} // namespace qt +} // namespace std +} // namespace fulltextsearch QT_END_NAMESPACE diff --git a/tools/assistant/lib/qhelpsearchindexreader_p.h b/tools/assistant/lib/qhelpsearchindexreader_p.h index b309f46..4d27c0f 100644 --- a/tools/assistant/lib/qhelpsearchindexreader_p.h +++ b/tools/assistant/lib/qhelpsearchindexreader_p.h @@ -66,8 +66,7 @@ QT_BEGIN_NAMESPACE class QHelpEngineCore; -namespace qt { - namespace fulltextsearch { +namespace fulltextsearch { class QHelpSearchIndexReader : public QThread { @@ -100,8 +99,7 @@ private: virtual void run()=0; }; - } // namespace fulltextsearch -} // namespace qt +} // namespace fulltextsearch QT_END_NAMESPACE diff --git a/tools/assistant/lib/qhelpsearchindexwriter_clucene.cpp b/tools/assistant/lib/qhelpsearchindexwriter_clucene.cpp index 2eeefb5..59067cf 100644 --- a/tools/assistant/lib/qhelpsearchindexwriter_clucene.cpp +++ b/tools/assistant/lib/qhelpsearchindexwriter_clucene.cpp @@ -63,9 +63,8 @@ QT_BEGIN_NAMESPACE -namespace qt { - namespace fulltextsearch { - namespace clucene { +namespace fulltextsearch { +namespace clucene { // taken from qtexthtmlparser static const struct QTextHtmlEntity @@ -895,8 +894,7 @@ void QHelpSearchIndexWriter::closeIndexWriter(QCLuceneIndexWriter *writer) #endif } - } // namespace clucene - } // namespace fulltextsearch -} // namespace qt +} // namespace clucene +} // namespace fulltextsearch QT_END_NAMESPACE diff --git a/tools/assistant/lib/qhelpsearchindexwriter_clucene_p.h b/tools/assistant/lib/qhelpsearchindexwriter_clucene_p.h index 91b8abd..db1e533 100644 --- a/tools/assistant/lib/qhelpsearchindexwriter_clucene_p.h +++ b/tools/assistant/lib/qhelpsearchindexwriter_clucene_p.h @@ -69,9 +69,8 @@ QT_BEGIN_NAMESPACE class QCLuceneIndexWriter; -namespace qt { - namespace fulltextsearch { - namespace clucene { +namespace fulltextsearch { +namespace clucene { class QHelpSearchIndexWriter : public QThread { @@ -116,9 +115,9 @@ private: QString m_indexFilesFolder; }; - } // namespace clucene - } // namespace fulltextsearch } // namespace clucene +} // namespace fulltextsearch + QT_END_NAMESPACE diff --git a/tools/assistant/lib/qhelpsearchindexwriter_default.cpp b/tools/assistant/lib/qhelpsearchindexwriter_default.cpp index 6d09fb8..cb3e49c 100644 --- a/tools/assistant/lib/qhelpsearchindexwriter_default.cpp +++ b/tools/assistant/lib/qhelpsearchindexwriter_default.cpp @@ -55,9 +55,8 @@ QT_BEGIN_NAMESPACE -namespace qt { - namespace fulltextsearch { - namespace std { +namespace fulltextsearch { +namespace std { Writer::Writer(const QString &path) : indexPath(path) @@ -379,8 +378,7 @@ QString QHelpSearchIndexWriter::removeNamespace(const QString namespaces, return value; } - } // namespace std - } // namespace fulltextsearch -} // namespace qt +} // namespace std +} // namespace fulltextsearch QT_END_NAMESPACE diff --git a/tools/assistant/lib/qhelpsearchindexwriter_default_p.h b/tools/assistant/lib/qhelpsearchindexwriter_default_p.h index b222203..625cb84 100644 --- a/tools/assistant/lib/qhelpsearchindexwriter_default_p.h +++ b/tools/assistant/lib/qhelpsearchindexwriter_default_p.h @@ -65,9 +65,8 @@ QT_BEGIN_NAMESPACE -namespace qt { - namespace fulltextsearch { - namespace std { +namespace fulltextsearch { +namespace std { class Writer { @@ -123,9 +122,8 @@ private: QString m_indexFilesFolder; }; - } // namespace std - } // namespace fulltextsearch -} // namespace qt +} // namespace std +} // namespace fulltextsearch QT_END_NAMESPACE -- cgit v0.12 From a4332ce058cf3fe567b386d300ba740442a69f44 Mon Sep 17 00:00:00 2001 From: Markus Goetz Date: Wed, 17 Feb 2010 16:36:40 +0100 Subject: QNAM HTTP: Always set channel.reply to 0 when done This will help us to track down a sporadic bug that made requests being sent again even if they were already done. Reviewed-by: Peter Hartmann --- src/network/access/qhttpnetworkconnection.cpp | 12 +----------- src/network/access/qhttpnetworkconnection_p.h | 5 ----- src/network/access/qhttpnetworkconnectionchannel.cpp | 17 ++++++++++++++--- src/network/access/qhttpnetworkreply.cpp | 13 ++++++++++--- src/network/access/qhttpnetworkreply_p.h | 2 ++ 5 files changed, 27 insertions(+), 22 deletions(-) diff --git a/src/network/access/qhttpnetworkconnection.cpp b/src/network/access/qhttpnetworkconnection.cpp index cc6a1c8..327d2db 100644 --- a/src/network/access/qhttpnetworkconnection.cpp +++ b/src/network/access/qhttpnetworkconnection.cpp @@ -404,6 +404,7 @@ QHttpNetworkReply* QHttpNetworkConnectionPrivate::queueRequest(const QHttpNetwor QHttpNetworkReply *reply = new QHttpNetworkReply(request.url()); reply->setRequest(request); reply->d_func()->connection = q; + reply->d_func()->connectionChannel = &channels[0]; // will have the correct one set later HttpMessagePair pair = qMakePair(request, reply); switch (request.priority()) { @@ -861,17 +862,6 @@ QNetworkProxy QHttpNetworkConnection::transparentProxy() const // SSL support below #ifndef QT_NO_OPENSSL -QSslConfiguration QHttpNetworkConnectionPrivate::sslConfiguration(const QHttpNetworkReply &reply) const -{ - if (!encrypt) - return QSslConfiguration(); - - for (int i = 0; i < channelCount; ++i) - if (channels[i].reply == &reply) - return static_cast(channels[0].socket)->sslConfiguration(); - return QSslConfiguration(); // pending or done request -} - void QHttpNetworkConnection::setSslConfiguration(const QSslConfiguration &config) { Q_D(QHttpNetworkConnection); diff --git a/src/network/access/qhttpnetworkconnection_p.h b/src/network/access/qhttpnetworkconnection_p.h index 03cf09c..823774e 100644 --- a/src/network/access/qhttpnetworkconnection_p.h +++ b/src/network/access/qhttpnetworkconnection_p.h @@ -210,11 +210,6 @@ public: void emitReplyError(QAbstractSocket *socket, QHttpNetworkReply *reply, QNetworkReply::NetworkError errorCode); bool handleAuthenticateChallenge(QAbstractSocket *socket, QHttpNetworkReply *reply, bool isProxy, bool &resend); - -#ifndef QT_NO_OPENSSL - QSslConfiguration sslConfiguration(const QHttpNetworkReply &reply) const; -#endif - #ifndef QT_NO_NETWORKPROXY QNetworkProxy networkProxy; void emitProxyAuthenticationRequired(const QHttpNetworkConnectionChannel *chan, const QNetworkProxy &proxy, QAuthenticator* auth); diff --git a/src/network/access/qhttpnetworkconnectionchannel.cpp b/src/network/access/qhttpnetworkconnectionchannel.cpp index 2a3036b..89fd032 100644 --- a/src/network/access/qhttpnetworkconnectionchannel.cpp +++ b/src/network/access/qhttpnetworkconnectionchannel.cpp @@ -137,6 +137,7 @@ bool QHttpNetworkConnectionChannel::sendRequest() if (reply) { reply->d_func()->clear(); reply->d_func()->connection = connection; + reply->d_func()->connectionChannel = this; reply->d_func()->autoDecompress = request.d->autoDecompress; reply->d_func()->pipeliningUsed = false; } @@ -568,7 +569,8 @@ void QHttpNetworkConnectionChannel::allDone() handleStatus(); // ### at this point there should be no more data on the socket // close if server requested - if (reply->d_func()->isConnectionCloseEnabled()) + bool connectionCloseEnabled = reply->d_func()->isConnectionCloseEnabled(); + if (connectionCloseEnabled) close(); // queue the finished signal, this is required since we might send new requests from // slot connected to it. The socket will not fire readyRead signal, if we are already @@ -579,14 +581,22 @@ void QHttpNetworkConnectionChannel::allDone() // in case of failures, each channel will attempt two reconnects before emitting error. reconnectAttempts = 2; + detectPipeliningSupport(); + // now the channel can be seen as free/idle again, all signal emissions for the reply have been done this->state = QHttpNetworkConnectionChannel::IdleState; - detectPipeliningSupport(); + // if it does not need to be sent again we can set it to 0 + // the previous code did not do that and we had problems with accidental re-sending of a + // finished request. + // Note that this may trigger a segfault at some other point. But then we can fix the underlying + // problem. + if (!resendCurrent) + reply = 0; // move next from pipeline to current request if (!alreadyPipelinedRequests.isEmpty()) { - if (resendCurrent || reply->d_func()->isConnectionCloseEnabled() || socket->state() != QAbstractSocket::ConnectedState) { + if (resendCurrent || connectionCloseEnabled || socket->state() != QAbstractSocket::ConnectedState) { // move the pipelined ones back to the main queue requeueCurrentlyPipelinedRequests(); close(); @@ -745,6 +755,7 @@ void QHttpNetworkConnectionChannel::pipelineInto(HttpMessagePair &pair) if (reply) { reply->d_func()->clear(); reply->d_func()->connection = connection; + reply->d_func()->connectionChannel = this; reply->d_func()->autoDecompress = request.d->autoDecompress; reply->d_func()->pipeliningUsed = true; } diff --git a/src/network/access/qhttpnetworkreply.cpp b/src/network/access/qhttpnetworkreply.cpp index 512c045..984f557 100644 --- a/src/network/access/qhttpnetworkreply.cpp +++ b/src/network/access/qhttpnetworkreply.cpp @@ -230,6 +230,7 @@ void QHttpNetworkReplyPrivate::clear() currentChunkRead = 0; connectionCloseEnabled = true; connection = 0; + connectionChannel = 0; #ifndef QT_NO_COMPRESS if (initInflate) inflateEnd(&inflateStrm); @@ -803,9 +804,15 @@ void QHttpNetworkReplyPrivate::eraseData() QSslConfiguration QHttpNetworkReply::sslConfiguration() const { Q_D(const QHttpNetworkReply); - if (d->connection) - return d->connection->d_func()->sslConfiguration(*this); - return QSslConfiguration(); + + if (!d->connectionChannel) + return QSslConfiguration(); + + QSslSocket *sslSocket = qobject_cast(d->connectionChannel->socket); + if (!sslSocket) + return QSslConfiguration(); + + return sslSocket->sslConfiguration(); } void QHttpNetworkReply::setSslConfiguration(const QSslConfiguration &config) diff --git a/src/network/access/qhttpnetworkreply_p.h b/src/network/access/qhttpnetworkreply_p.h index af9266b..fa240ec 100644 --- a/src/network/access/qhttpnetworkreply_p.h +++ b/src/network/access/qhttpnetworkreply_p.h @@ -86,6 +86,7 @@ static const unsigned char gz_magic[2] = {0x1f, 0x8b}; // gzip magic header QT_BEGIN_NAMESPACE class QHttpNetworkConnection; +class QHttpNetworkConnectionChannel; class QHttpNetworkRequest; class QHttpNetworkConnectionPrivate; class QHttpNetworkReplyPrivate; @@ -218,6 +219,7 @@ public: qint64 currentChunkSize; qint64 currentChunkRead; QPointer connection; + QPointer connectionChannel; bool initInflate; bool streamEnd; #ifndef QT_NO_COMPRESS -- cgit v0.12 From a6eac63470ad8dd3f1687fcd4039a5312c44a5d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Nilsen?= Date: Wed, 17 Feb 2010 15:59:49 +0100 Subject: Compiler warning, unusable variable in tst_QGraphicsScene benchmark. --- tests/benchmarks/gui/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/benchmarks/gui/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp b/tests/benchmarks/gui/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp index 5bd07f9..9531619 100644 --- a/tests/benchmarks/gui/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp +++ b/tests/benchmarks/gui/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp @@ -209,7 +209,6 @@ void tst_QGraphicsScene::itemAt() if (!sceneRect.isNull()) scene.setSceneRect(sceneRect); - QGraphicsItem *item = 0; for (int y = 0; y < numItems_Y; ++y) { for (int x = 0; x < numItems_X; ++x) { QGraphicsRectItem *item = new QGraphicsRectItem(itemRect); -- cgit v0.12 From 5c4363a0fa3cd654413ff2637cb70aeec7a590ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Nilsen?= Date: Wed, 17 Feb 2010 16:12:09 +0100 Subject: Stabilize QGraphicsScene benchmarks. --- .../gui/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/tests/benchmarks/gui/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp b/tests/benchmarks/gui/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp index 9531619..10d73d5 100644 --- a/tests/benchmarks/gui/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp +++ b/tests/benchmarks/gui/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp @@ -75,8 +75,16 @@ tst_QGraphicsScene::~tst_QGraphicsScene() { } +static inline void processEvents() +{ + QApplication::flush(); + QApplication::processEvents(); + QApplication::processEvents(); +} + void tst_QGraphicsScene::init() { + processEvents(); } void tst_QGraphicsScene::cleanup() @@ -148,6 +156,8 @@ void tst_QGraphicsScene::addItem() if (!sceneRect.isNull()) scene.setSceneRect(sceneRect); + processEvents(); + QBENCHMARK { QGraphicsItem *item = 0; for (int y = 0; y < numItems_Y; ++y) { @@ -218,9 +228,11 @@ void tst_QGraphicsScene::itemAt() } scene.itemAt(0, 0); // triggers indexing + processEvents(); + QGraphicsItem *item = 0; QBENCHMARK { - scene.itemAt(0, 0); + item = scene.itemAt(0, 0); } //let QGraphicsScene::_q_polishItems be called so ~QGraphicsItem doesn't spend all his time cleaning the unpolished list -- cgit v0.12 From b77624c18896e149f338cb512369215b11bba685 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Nilsen?= Date: Wed, 17 Feb 2010 16:30:52 +0100 Subject: Compiler warnings in QGraphicsView benchmark. --- .../gui/graphicsview/qgraphicsview/tst_qgraphicsview.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/benchmarks/gui/graphicsview/qgraphicsview/tst_qgraphicsview.cpp b/tests/benchmarks/gui/graphicsview/qgraphicsview/tst_qgraphicsview.cpp index 10e00a6..267fecc 100644 --- a/tests/benchmarks/gui/graphicsview/qgraphicsview/tst_qgraphicsview.cpp +++ b/tests/benchmarks/gui/graphicsview/qgraphicsview/tst_qgraphicsview.cpp @@ -560,7 +560,7 @@ void tst_QGraphicsView::imageRiver() #else for (int i = 0; i < 100; ++i) { #endif - AnimatedPixmapItem *item; + AnimatedPixmapItem *item = 0; if (direction == 0) item = new AnimatedPixmapItem((i % 4) + 1, 0, rotation, scale); if (direction == 1) item = new AnimatedPixmapItem(0, (i % 4) + 1, rotation, scale); if (direction == 2) item = new AnimatedPixmapItem((i % 4) + 1, (i % 4) + 1, rotation, scale); @@ -682,7 +682,7 @@ void tst_QGraphicsView::textRiver() #else for (int i = 0; i < 100; ++i) { #endif - AnimatedTextItem *item; + AnimatedTextItem *item = 0; if (direction == 0) item = new AnimatedTextItem((i % 4) + 1, 0, rotation, scale); if (direction == 1) item = new AnimatedTextItem(0, (i % 4) + 1, rotation, scale); if (direction == 2) item = new AnimatedTextItem((i % 4) + 1, (i % 4) + 1, rotation, scale); @@ -792,7 +792,7 @@ void tst_QGraphicsView::moveItemCache() #else for (int i = 0; i < 50; ++i) { #endif - AnimatedPixmapCacheItem *item; + AnimatedPixmapCacheItem *item = 0; if (direction == 0) item = new AnimatedPixmapCacheItem((i % 4) + 1, 0); if (direction == 1) item = new AnimatedPixmapCacheItem(0, (i % 4) + 1); if (direction == 2) item = new AnimatedPixmapCacheItem((i % 4) + 1, (i % 4) + 1); @@ -843,6 +843,7 @@ public: protected: void advance(int i) { + Q_UNUSED(i); if (partial) update(QRectF(boundingRect().center().x(), boundingRect().center().x(), 30, 30)); else -- cgit v0.12 From f9a790fcac5222c89797e896ed14cd5b4ccd1fea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Nilsen?= Date: Wed, 17 Feb 2010 16:43:04 +0100 Subject: Remove platform dependent code from QGraphicsView benchmark. First, it doesn't make much sense to have platform specific code like this in a benchmark. Second, the Q_OS_SYMBIAN specific values makes more sense anyways, so we can use them on all platforms. --- .../qgraphicsview/tst_qgraphicsview.cpp | 34 +--------------------- 1 file changed, 1 insertion(+), 33 deletions(-) diff --git a/tests/benchmarks/gui/graphicsview/qgraphicsview/tst_qgraphicsview.cpp b/tests/benchmarks/gui/graphicsview/qgraphicsview/tst_qgraphicsview.cpp index 267fecc..235afef 100644 --- a/tests/benchmarks/gui/graphicsview/qgraphicsview/tst_qgraphicsview.cpp +++ b/tests/benchmarks/gui/graphicsview/qgraphicsview/tst_qgraphicsview.cpp @@ -170,11 +170,7 @@ void tst_QGraphicsView::paintSingleItem() } } -#ifdef Q_OS_SYMBIAN -# define DEEP_STACKING_COUNT 85 -#else -# define DEEP_STACKING_COUNT 1000 -#endif +#define DEEP_STACKING_COUNT 85 void tst_QGraphicsView::paintDeepStackingItems() { @@ -555,11 +551,7 @@ void tst_QGraphicsView::imageRiver() QFile file(":/random.data"); QVERIFY(file.open(QIODevice::ReadOnly)); QDataStream str(&file); -#if defined(Q_OS_SYMBIAN) for (int i = 0; i < 50; ++i) { -#else - for (int i = 0; i < 100; ++i) { -#endif AnimatedPixmapItem *item = 0; if (direction == 0) item = new AnimatedPixmapItem((i % 4) + 1, 0, rotation, scale); if (direction == 1) item = new AnimatedPixmapItem(0, (i % 4) + 1, rotation, scale); @@ -578,11 +570,7 @@ void tst_QGraphicsView::imageRiver() #ifdef CALLGRIND_DEBUG CALLGRIND_START_INSTRUMENTATION #endif -#if defined(Q_OS_SYMBIAN) for (int i = 0; i < 50; ++i) { -#else - for (int i = 0; i < 100; ++i) { -#endif scene.advance(); while (view.count < (i+1)) qApp->processEvents(); @@ -677,11 +665,7 @@ void tst_QGraphicsView::textRiver() QFile file(":/random.data"); QVERIFY(file.open(QIODevice::ReadOnly)); QDataStream str(&file); -#if defined(Q_OS_SYMBIAN) for (int i = 0; i < 50; ++i) { -#else - for (int i = 0; i < 100; ++i) { -#endif AnimatedTextItem *item = 0; if (direction == 0) item = new AnimatedTextItem((i % 4) + 1, 0, rotation, scale); if (direction == 1) item = new AnimatedTextItem(0, (i % 4) + 1, rotation, scale); @@ -699,11 +683,7 @@ void tst_QGraphicsView::textRiver() #ifdef CALLGRIND_DEBUG CALLGRIND_START_INSTRUMENTATION #endif -#if defined(Q_OS_SYMBIAN) for (int i = 0; i < 50; ++i) { -#else - for (int i = 0; i < 100; ++i) { -#endif scene.advance(); while (view.count < (i+1)) qApp->processEvents(); @@ -787,11 +767,7 @@ void tst_QGraphicsView::moveItemCache() QFile file(":/random.data"); QVERIFY(file.open(QIODevice::ReadOnly)); QDataStream str(&file); -#if defined(Q_OS_SYMBIAN) for (int i = 0; i < 5; ++i) { -#else - for (int i = 0; i < 50; ++i) { -#endif AnimatedPixmapCacheItem *item = 0; if (direction == 0) item = new AnimatedPixmapCacheItem((i % 4) + 1, 0); if (direction == 1) item = new AnimatedPixmapCacheItem(0, (i % 4) + 1); @@ -813,11 +789,7 @@ void tst_QGraphicsView::moveItemCache() #ifdef CALLGRIND_DEBUG CALLGRIND_START_INSTRUMENTATION #endif -#if defined(Q_OS_SYMBIAN) for (int i = 0; i < 50; ++i) { -#else - for (int i = 0; i < 100; ++i) { -#endif scene.advance(); while (view.count < (i+1)) qApp->processEvents(); @@ -918,11 +890,7 @@ void tst_QGraphicsView::paintItemCache() #ifdef CALLGRIND_DEBUG CALLGRIND_START_INSTRUMENTATION #endif -#if defined(Q_OS_SYMBIAN) for (int i = 0; i < 5; ++i) { -#else - for (int i = 0; i < 50; ++i) { -#endif scene.advance(); while (view.count < (i+1)) qApp->processEvents(); -- cgit v0.12 From b37def83cb97dec7167f99a53dfada1b48dee59c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Nilsen?= Date: Thu, 18 Feb 2010 16:13:14 +0100 Subject: Stabilize QGraphicsView benchmarks. --- .../qgraphicsview/tst_qgraphicsview.cpp | 259 +++++++++++---------- 1 file changed, 134 insertions(+), 125 deletions(-) diff --git a/tests/benchmarks/gui/graphicsview/qgraphicsview/tst_qgraphicsview.cpp b/tests/benchmarks/gui/graphicsview/qgraphicsview/tst_qgraphicsview.cpp index 235afef..3c0ae71 100644 --- a/tests/benchmarks/gui/graphicsview/qgraphicsview/tst_qgraphicsview.cpp +++ b/tests/benchmarks/gui/graphicsview/qgraphicsview/tst_qgraphicsview.cpp @@ -45,11 +45,7 @@ #include #include #include -#ifdef Q_WS_X11 -QT_BEGIN_NAMESPACE -extern void qt_x11_wait_for_window_manager(QWidget *); -QT_END_NAMESPACE -#endif + #include "chiptester/chiptester.h" //#define CALLGRIND_DEBUG #ifdef CALLGRIND_DEBUG @@ -58,34 +54,65 @@ QT_END_NAMESPACE //TESTED_FILES= -class QEventWaiter : public QEventLoop +static inline void processEvents() { + QPixmapCache::clear(); + QApplication::flush(); + QApplication::processEvents(); + QApplication::processEvents(); +} + +class TestView : public QGraphicsView +{ + Q_OBJECT public: - QEventWaiter(QObject *receiver, QEvent::Type type) - : waiting(false), t(type) - { - receiver->installEventFilter(this); - } + TestView() : QGraphicsView(), waiting(false), timerId(-1) + {} - void wait() + void waitForPaintEvent(int timeout = 4000) { + if (waiting) + return; waiting = true; - exec(); + timerId = startTimer(timeout); + eventLoop.exec(); + killTimer(timerId); + timerId = -1; + waiting = false; } - bool eventFilter(QObject *receiver, QEvent *event) + void tryResize(int width, int height) { - Q_UNUSED(receiver); - if (waiting && event->type() == t) { - waiting = false; - exit(); + QDesktopWidget *desktop = QApplication::desktop(); + if (desktop->width() < width) + width = desktop->width(); + if (desktop->height() < height) + height = desktop->height(); + if (size() != QSize(width, height)) { + resize(width, height); + QTest::qWait(250); + processEvents(); } - return false; + } + +protected: + void paintEvent(QPaintEvent *event) + { + QGraphicsView::paintEvent(event); + if (waiting) + eventLoop.exit(); + } + + void timerEvent(QTimerEvent *event) + { + if (event->timerId() == timerId) + eventLoop.exit(); } private: + QEventLoop eventLoop; bool waiting; - QEvent::Type t; + int timerId; }; class tst_QGraphicsView : public QObject @@ -97,6 +124,7 @@ public: virtual ~tst_QGraphicsView(); public slots: + void initTestCase(); void init(); void cleanup(); @@ -126,6 +154,9 @@ private slots: void moveItemCache(); void paintItemCache_data(); void paintItemCache(); + +private: + TestView mView; }; tst_QGraphicsView::tst_QGraphicsView() @@ -136,8 +167,25 @@ tst_QGraphicsView::~tst_QGraphicsView() { } +void tst_QGraphicsView::initTestCase() +{ + mView.setFrameStyle(0); + mView.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + mView.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + mView.tryResize(100, 100); + mView.show(); + QTest::qWaitForWindowShown(&mView); + QTest::qWait(300); + processEvents(); +} + void tst_QGraphicsView::init() { + mView.setRenderHints(QPainter::RenderHints(0)); + mView.viewport()->setMouseTracking(false); + mView.setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate); + for (int i = 0; i < 3; ++i) + processEvents(); } void tst_QGraphicsView::cleanup() @@ -156,17 +204,14 @@ void tst_QGraphicsView::paintSingleItem() QGraphicsScene scene(0, 0, 100, 100); scene.addRect(0, 0, 10, 10); - QGraphicsView view(&scene); - view.show(); - view.resize(100, 100); -#ifdef Q_WS_X11 - qt_x11_wait_for_window_manager(&view); -#endif + mView.setScene(&scene); + mView.tryResize(100, 100); + processEvents(); QImage image(100, 100, QImage::Format_ARGB32_Premultiplied); QPainter painter(&image); QBENCHMARK { - view.viewport()->render(&painter); + mView.viewport()->render(&painter); } } @@ -184,17 +229,14 @@ void tst_QGraphicsView::paintDeepStackingItems() lastRect = rect; } - QGraphicsView view(&scene); - view.show(); - view.resize(100, 100); -#ifdef Q_WS_X11 - qt_x11_wait_for_window_manager(&view); -#endif + mView.setScene(&scene); + mView.tryResize(100, 100); + processEvents(); QImage image(100, 100, QImage::Format_ARGB32_Premultiplied); QPainter painter(&image); QBENCHMARK { - view.viewport()->render(&painter); + mView.viewport()->render(&painter); } } @@ -211,17 +253,14 @@ void tst_QGraphicsView::paintDeepStackingItems_clipped() lastRect = rect; } - QGraphicsView view(&scene); - view.show(); - view.resize(100, 100); -#ifdef Q_WS_X11 - qt_x11_wait_for_window_manager(&view); -#endif + mView.setScene(&scene); + mView.tryResize(100, 100); + processEvents(); QImage image(100, 100, QImage::Format_ARGB32_Premultiplied); QPainter painter(&image); QBENCHMARK { - view.viewport()->render(&painter); + mView.viewport()->render(&painter); } } @@ -230,18 +269,14 @@ void tst_QGraphicsView::moveSingleItem() QGraphicsScene scene(0, 0, 100, 100); QGraphicsRectItem *item = scene.addRect(0, 0, 10, 10); - QGraphicsView view(&scene); - view.show(); - view.resize(100, 100); -#ifdef Q_WS_X11 - qt_x11_wait_for_window_manager(&view); -#endif + mView.setScene(&scene); + mView.tryResize(100, 100); + processEvents(); - QEventWaiter waiter(view.viewport(), QEvent::Paint); int n = 1; QBENCHMARK { item->setPos(25 * n, 25 * n); - waiter.wait(); + mView.waitForPaintEvent(); n = n ? 0 : 1; } } @@ -267,6 +302,8 @@ void tst_QGraphicsView::mapPointToScene() QGraphicsView view; view.setTransform(transform); + processEvents(); + QBENCHMARK { view.mapToScene(point); } @@ -293,6 +330,8 @@ void tst_QGraphicsView::mapPointFromScene() QGraphicsView view; view.setTransform(transform); + processEvents(); + QBENCHMARK { view.mapFromScene(point); } @@ -319,6 +358,8 @@ void tst_QGraphicsView::mapRectToScene() QGraphicsView view; view.setTransform(transform); + processEvents(); + QBENCHMARK { view.mapToScene(rect); } @@ -345,6 +386,8 @@ void tst_QGraphicsView::mapRectFromScene() QGraphicsView view; view.setTransform(transform); + processEvents(); + QBENCHMARK { view.mapFromScene(rect); } @@ -376,13 +419,14 @@ void tst_QGraphicsView::chipTester() QFETCH(int, operation); ChipTester tester; - tester.show(); -#ifdef Q_WS_X11 - qt_x11_wait_for_window_manager(&tester); -#endif tester.setAntialias(antialias); tester.setOpenGL(opengl); tester.setOperation(ChipTester::Operation(operation)); + tester.show(); + QTest::qWaitForWindowShown(&tester); + QTest::qWait(250); + processEvents(); + QBENCHMARK { tester.runBenchmark(); } @@ -432,20 +476,20 @@ void tst_QGraphicsView::deepNesting() } scene.setItemIndexMethod(bsp ? QGraphicsScene::BspTreeIndex : QGraphicsScene::NoIndex); scene.setSortCacheEnabled(sortCache); + scene.setSceneRect(scene.sceneRect()); - QGraphicsView view(&scene); - view.setRenderHint(QPainter::Antialiasing); - view.show(); -#ifdef Q_WS_X11 - qt_x11_wait_for_window_manager(&view); -#endif - QTest::qWait(250); + mView.setRenderHint(QPainter::Antialiasing); + mView.setScene(&scene); + mView.tryResize(600, 600); + (void)scene.itemAt(0, 0); + processEvents(); QBENCHMARK { #ifdef CALLGRIND_DEBUG CALLGRIND_START_INSTRUMENTATION #endif - view.viewport()->repaint(); + mView.viewport()->update(); + mView.waitForPaintEvent(); #ifdef CALLGRIND_DEBUG CALLGRIND_STOP_INSTRUMENTATION #endif @@ -499,23 +543,6 @@ private: bool scale; }; -class CountPaintEventView : public QGraphicsView -{ -public: - CountPaintEventView(QGraphicsScene *scene = 0) - : QGraphicsView(scene), count(0) - { } - - int count; - -protected: - void paintEvent(QPaintEvent *event) - { - ++count; - QGraphicsView::paintEvent(event); - }; -}; - void tst_QGraphicsView::imageRiver_data() { QTest::addColumn("direction"); @@ -537,13 +564,6 @@ void tst_QGraphicsView::imageRiver() QGraphicsScene scene(0, 0, 300, 300); - CountPaintEventView view(&scene); - view.resize(300, 300); - view.setFrameStyle(0); - view.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - view.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - view.show(); - QPixmap pix(":/images/designer.png"); QVERIFY(!pix.isNull()); @@ -559,12 +579,15 @@ void tst_QGraphicsView::imageRiver() item->setPixmap(pix); int rnd1, rnd2; str >> rnd1 >> rnd2; - item->setPos(-pix.width() + rnd1 % (view.width() + pix.width()), - -pix.height() + rnd2 % (view.height() + pix.height())); + item->setPos(-pix.width() + rnd1 % (300 + pix.width()), + -pix.height() + rnd2 % (300 + pix.height())); scene.addItem(item); } + scene.setSceneRect(0, 0, 300, 300); - view.count = 0; + mView.setScene(&scene); + mView.tryResize(300, 300); + processEvents(); QBENCHMARK { #ifdef CALLGRIND_DEBUG @@ -572,8 +595,7 @@ void tst_QGraphicsView::imageRiver() #endif for (int i = 0; i < 50; ++i) { scene.advance(); - while (view.count < (i+1)) - qApp->processEvents(); + mView.waitForPaintEvent(); } #ifdef CALLGRIND_DEBUG CALLGRIND_STOP_INSTRUMENTATION @@ -651,13 +673,6 @@ void tst_QGraphicsView::textRiver() QGraphicsScene scene(0, 0, 300, 300); - CountPaintEventView view(&scene); - view.resize(300, 300); - view.setFrameStyle(0); - view.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - view.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - view.show(); - QPixmap pix(":/images/designer.png"); QVERIFY(!pix.isNull()); @@ -672,12 +687,17 @@ void tst_QGraphicsView::textRiver() if (direction == 2) item = new AnimatedTextItem((i % 4) + 1, (i % 4) + 1, rotation, scale); int rnd1, rnd2; str >> rnd1 >> rnd2; - item->setPos(-pix.width() + rnd1 % (view.width() + pix.width()), - -pix.height() + rnd2 % (view.height() + pix.height())); + item->setPos(-pix.width() + rnd1 % (300 + pix.width()), + -pix.height() + rnd2 % (300 + pix.height())); + item->setAcceptDrops(false); + item->setAcceptHoverEvents(false); scene.addItem(item); } + scene.setSceneRect(0, 0, 300, 300); - view.count = 0; + mView.setScene(&scene); + mView.tryResize(300, 300); + processEvents(); QBENCHMARK { #ifdef CALLGRIND_DEBUG @@ -685,8 +705,7 @@ void tst_QGraphicsView::textRiver() #endif for (int i = 0; i < 50; ++i) { scene.advance(); - while (view.count < (i+1)) - qApp->processEvents(); + mView.waitForPaintEvent(); } #ifdef CALLGRIND_DEBUG CALLGRIND_STOP_INSTRUMENTATION @@ -753,13 +772,6 @@ void tst_QGraphicsView::moveItemCache() QGraphicsScene scene(0, 0, 300, 300); - CountPaintEventView view(&scene); - view.resize(600, 600); - view.setFrameStyle(0); - view.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - view.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - view.show(); - QPixmap pix(":/images/wine.jpeg"); QVERIFY(!pix.isNull()); @@ -778,21 +790,23 @@ void tst_QGraphicsView::moveItemCache() item->setTransform(QTransform().rotate(45)); int rnd1, rnd2; str >> rnd1 >> rnd2; - item->setPos(-pix.width() + rnd1 % (view.width() + pix.width()), - -pix.height() + rnd2 % (view.height() + pix.height())); + item->setPos(-pix.width() + rnd1 % (400 + pix.width()), + -pix.height() + rnd2 % (400 + pix.height())); scene.addItem(item); } + scene.setSceneRect(0, 0, 400, 400); - view.count = 0; + mView.setScene(&scene); + mView.tryResize(400, 400); + processEvents(); QBENCHMARK { #ifdef CALLGRIND_DEBUG CALLGRIND_START_INSTRUMENTATION #endif - for (int i = 0; i < 50; ++i) { + for (int i = 0; i < 5; ++i) { scene.advance(); - while (view.count < (i+1)) - qApp->processEvents(); + mView.waitForPaintEvent(); } #ifdef CALLGRIND_DEBUG CALLGRIND_STOP_INSTRUMENTATION @@ -853,13 +867,6 @@ void tst_QGraphicsView::paintItemCache() QGraphicsScene scene(0, 0, 300, 300); - CountPaintEventView view(&scene); - view.resize(600, 600); - view.setFrameStyle(0); - view.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - view.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - view.show(); - QPixmap pix(":/images/wine.jpeg"); QVERIFY(!pix.isNull()); @@ -883,8 +890,11 @@ void tst_QGraphicsView::paintItemCache() item->setTransform(QTransform().rotate(45)); item->setPos(0, 0); scene.addItem(item); + scene.setSceneRect(-100, -100, 600, 600); - view.count = 0; + mView.tryResize(600, 600); + mView.setScene(&scene); + processEvents(); QBENCHMARK { #ifdef CALLGRIND_DEBUG @@ -892,8 +902,7 @@ void tst_QGraphicsView::paintItemCache() #endif for (int i = 0; i < 5; ++i) { scene.advance(); - while (view.count < (i+1)) - qApp->processEvents(); + mView.waitForPaintEvent(); } #ifdef CALLGRIND_DEBUG CALLGRIND_STOP_INSTRUMENTATION -- cgit v0.12 From 059be19781a22d2e41f22072152589857d0fabf9 Mon Sep 17 00:00:00 2001 From: Thierry Bastian Date: Thu, 18 Feb 2010 16:21:42 +0100 Subject: Fixed a regression in dockwidgets that would jump when toplevel resized This was reproducible when the main window doesn't contain a central widget. Task-number: QTBUG-8107 Reviewed-by: ogoffart --- src/gui/widgets/qdockarealayout.cpp | 2 +- src/gui/widgets/qmainwindowlayout.cpp | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/gui/widgets/qdockarealayout.cpp b/src/gui/widgets/qdockarealayout.cpp index d754800..0c39f42 100644 --- a/src/gui/widgets/qdockarealayout.cpp +++ b/src/gui/widgets/qdockarealayout.cpp @@ -2635,7 +2635,7 @@ void QDockAreaLayout::getGrid(QVector *_ver_struct_list, QSize bottom_max = docks[QInternal::BottomDock].maximumSize(); bottom_hint = bottom_hint.boundedTo(bottom_max).expandedTo(bottom_min); - fallbackToSizeHints = !have_central; + fallbackToSizeHints = false; if (_ver_struct_list != 0) { QVector &ver_struct_list = *_ver_struct_list; diff --git a/src/gui/widgets/qmainwindowlayout.cpp b/src/gui/widgets/qmainwindowlayout.cpp index fc75c92..593e391 100644 --- a/src/gui/widgets/qmainwindowlayout.cpp +++ b/src/gui/widgets/qmainwindowlayout.cpp @@ -1772,6 +1772,7 @@ void QMainWindowLayout::setCentralWidget(QWidget *widget) if (savedState.isValid()) { #ifndef QT_NO_DOCKWIDGET savedState.dockAreaLayout.centralWidgetItem = layoutState.dockAreaLayout.centralWidgetItem; + savedState.dockAreaLayout.fallbackToSizeHints = true; #else savedState.centralWidgetItem = layoutState.centralWidgetItem; #endif -- cgit v0.12 From 90c3e1d2110c47ad36e05c04c874d6d932dd772f Mon Sep 17 00:00:00 2001 From: Markus Goetz Date: Thu, 18 Feb 2010 14:41:20 +0100 Subject: QNAM HTTP: Clean code a bit .. and some changes that will help us track down bugs Reviewed-by: Peter Hartmann --- src/network/access/qhttpnetworkconnection.cpp | 10 ++-- .../access/qhttpnetworkconnectionchannel.cpp | 64 ++++++++++++++-------- 2 files changed, 45 insertions(+), 29 deletions(-) diff --git a/src/network/access/qhttpnetworkconnection.cpp b/src/network/access/qhttpnetworkconnection.cpp index 327d2db..62aa2d7 100644 --- a/src/network/access/qhttpnetworkconnection.cpp +++ b/src/network/access/qhttpnetworkconnection.cpp @@ -689,14 +689,12 @@ void QHttpNetworkConnectionPrivate::_q_startNextRequest() if (channels[i].resendCurrent) { channels[i].resendCurrent = false; channels[i].state = QHttpNetworkConnectionChannel::IdleState; - if (channels[i].reply) { - // if this is not possible, error will be emitted and connection terminated - if (!channels[i].resetUploadData()) - continue; + // if this is not possible, error will be emitted and connection terminated + if (!channels[i].resetUploadData()) + continue; - channels[i].sendRequest(); - } + channels[i].sendRequest(); } } diff --git a/src/network/access/qhttpnetworkconnectionchannel.cpp b/src/network/access/qhttpnetworkconnectionchannel.cpp index 89fd032..dbee72a 100644 --- a/src/network/access/qhttpnetworkconnectionchannel.cpp +++ b/src/network/access/qhttpnetworkconnectionchannel.cpp @@ -124,6 +124,13 @@ void QHttpNetworkConnectionChannel::close() bool QHttpNetworkConnectionChannel::sendRequest() { + if (!reply) { + // heh, how should that happen! + qWarning() << "QHttpNetworkConnectionChannel::sendRequest() called without QHttpNetworkReply"; + state = QHttpNetworkConnectionChannel::IdleState; + return false; + } + switch (state) { case QHttpNetworkConnectionChannel::IdleState: { // write the header if (!ensureConnection()) { @@ -134,14 +141,13 @@ bool QHttpNetworkConnectionChannel::sendRequest() } written = 0; // excluding the header bytesTotal = 0; - if (reply) { - reply->d_func()->clear(); - reply->d_func()->connection = connection; - reply->d_func()->connectionChannel = this; - reply->d_func()->autoDecompress = request.d->autoDecompress; - reply->d_func()->pipeliningUsed = false; - } - state = QHttpNetworkConnectionChannel::WritingState; + + reply->d_func()->clear(); + reply->d_func()->connection = connection; + reply->d_func()->connectionChannel = this; + reply->d_func()->autoDecompress = request.d->autoDecompress; + reply->d_func()->pipeliningUsed = false; + pendingEncrypt = false; // if the url contains authentication parameters, use the new ones // both channels will use the new authentication parameters @@ -175,13 +181,15 @@ bool QHttpNetworkConnectionChannel::sendRequest() QObject::connect(uploadByteDevice, SIGNAL(readyRead()),this, SLOT(_q_uploadDataReadyRead())); bytesTotal = request.contentLength(); + + state = QHttpNetworkConnectionChannel::WritingState; // start writing data + sendRequest(); //recurse } else { - state = QHttpNetworkConnectionChannel::WaitingState; - sendRequest(); - break; + state = QHttpNetworkConnectionChannel::WaitingState; // now wait for response + sendRequest(); //recurse } - // write the initial chunk together with the headers - // fall through + + break; } case QHttpNetworkConnectionChannel::WritingState: { @@ -191,7 +199,7 @@ bool QHttpNetworkConnectionChannel::sendRequest() if (uploadByteDevice) emit reply->dataSendProgress(written, bytesTotal); state = QHttpNetworkConnectionChannel::WaitingState; // now wait for response - sendRequest(); + sendRequest(); // recurse break; } @@ -279,16 +287,25 @@ void QHttpNetworkConnectionChannel::_q_receiveReply() { Q_ASSERT(socket); + if (!reply) { + // heh, how should that happen! + qWarning() << "QHttpNetworkConnectionChannel::_q_receiveReply() called without QHttpNetworkReply," + << socket->bytesAvailable() << "bytes on socket."; + close(); + return; + } + qint64 bytes = 0; QAbstractSocket::SocketState socketState = socket->state(); // connection might be closed to signal the end of data if (socketState == QAbstractSocket::UnconnectedState) { if (socket->bytesAvailable() <= 0) { - if (reply && reply->d_func()->state == QHttpNetworkReplyPrivate::ReadingDataState) { + if (reply->d_func()->state == QHttpNetworkReplyPrivate::ReadingDataState) { // finish this reply. this case happens when the server did not send a content length reply->d_func()->state = QHttpNetworkReplyPrivate::AllDoneState; allDone(); + return; } else { handleUnexpectedEOF(); return; @@ -300,12 +317,13 @@ void QHttpNetworkConnectionChannel::_q_receiveReply() // read loop for the response while (socket->bytesAvailable()) { - QHttpNetworkReplyPrivate::ReplyState state = reply ? reply->d_func()->state : QHttpNetworkReplyPrivate::AllDoneState; + QHttpNetworkReplyPrivate::ReplyState state = reply->d_func()->state; switch (state) { case QHttpNetworkReplyPrivate::NothingDoneState: { // only eat whitespace on the first call eatWhitespace(); state = reply->d_func()->state = QHttpNetworkReplyPrivate::ReadingStatusState; + // fallthrough } case QHttpNetworkReplyPrivate::ReadingStatusState: { qint64 statusBytes = reply->d_func()->readStatus(socket); @@ -413,8 +431,10 @@ void QHttpNetworkConnectionChannel::_q_receiveReply() #endif } } + // still in ReadingDataState? This function will be called again by the socket's readyRead if (replyPrivate->state == QHttpNetworkReplyPrivate::ReadingDataState) break; + // everything done, fall through } case QHttpNetworkReplyPrivate::AllDoneState: @@ -752,13 +772,11 @@ void QHttpNetworkConnectionChannel::pipelineInto(HttpMessagePair &pair) QHttpNetworkRequest &request = pair.first; QHttpNetworkReply *reply = pair.second; - if (reply) { - reply->d_func()->clear(); - reply->d_func()->connection = connection; - reply->d_func()->connectionChannel = this; - reply->d_func()->autoDecompress = request.d->autoDecompress; - reply->d_func()->pipeliningUsed = true; - } + reply->d_func()->clear(); + reply->d_func()->connection = connection; + reply->d_func()->connectionChannel = this; + reply->d_func()->autoDecompress = request.d->autoDecompress; + reply->d_func()->pipeliningUsed = true; #ifndef QT_NO_NETWORKPROXY QByteArray header = QHttpNetworkRequestPrivate::header(request, -- cgit v0.12 From 9d8614d8dcd1ae8389842aa4c48d8c77ae69bf27 Mon Sep 17 00:00:00 2001 From: Markus Goetz Date: Thu, 18 Feb 2010 15:11:10 +0100 Subject: tst_qnetworkreply: Add another testcase Reviewed-by: Peter Hartmann --- tests/auto/qnetworkreply/tst_qnetworkreply.cpp | 66 ++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/tests/auto/qnetworkreply/tst_qnetworkreply.cpp b/tests/auto/qnetworkreply/tst_qnetworkreply.cpp index 5fecc86..049bbb8 100644 --- a/tests/auto/qnetworkreply/tst_qnetworkreply.cpp +++ b/tests/auto/qnetworkreply/tst_qnetworkreply.cpp @@ -257,6 +257,8 @@ private Q_SLOTS: void httpConnectionCount(); + void httpRecursiveCreation(); + #ifndef QT_NO_OPENSSL void ioPostToHttpsUploadProgress(); void ignoreSslErrorsList_data(); @@ -3788,6 +3790,70 @@ void tst_QNetworkReply::httpConnectionCount() #endif } +class HttpRecursiveCreationHelper : public QObject { + Q_OBJECT +public: + + HttpRecursiveCreationHelper(): + QObject(0), + requestsStartedCount_finished(0), + requestsStartedCount_readyRead(0), + requestsFinishedCount(0) + { + } + QNetworkAccessManager manager; + int requestsStartedCount_finished; + int requestsStartedCount_readyRead; + int requestsFinishedCount; +public slots: + void finishedSlot() { + requestsFinishedCount++; + + QNetworkReply *reply = qobject_cast(sender()); + QVERIFY(!reply->error()); + QVERIFY(reply->bytesAvailable() == 27906); + + if (requestsFinishedCount == 60) { + QTestEventLoop::instance().exitLoop(); + return; + } + + if (requestsStartedCount_finished < 30) { + startOne(); + requestsStartedCount_finished++; + } + + reply->deleteLater(); + } + void readyReadSlot() { + QNetworkReply *reply = qobject_cast(sender()); + QVERIFY(!reply->error()); + + if (requestsStartedCount_readyRead < 30 && reply->bytesAvailable() > 27906/2) { + startOne(); + requestsStartedCount_readyRead++; + } + } + void startOne() { + QUrl url = "http://" + QtNetworkSettings::serverName() + "/gif/fluke.gif"; + QNetworkRequest request(url); + QNetworkReply *reply = manager.get(request); + reply->setParent(this); + connect(reply, SIGNAL(finished()), this, SLOT(finishedSlot())); + connect(reply, SIGNAL(readyRead()), this, SLOT(readyReadSlot())); + } +}; + +void tst_QNetworkReply::httpRecursiveCreation() +{ + // this test checks if creation of new requests to the same host properly works + // from readyRead() and finished() signals + HttpRecursiveCreationHelper helper; + helper.startOne(); + QTestEventLoop::instance().enterLoop(30); + QVERIFY(!QTestEventLoop::instance().timeout()); +} + #ifndef QT_NO_OPENSSL void tst_QNetworkReply::ignoreSslErrorsList_data() { -- cgit v0.12 From 3a1ad930266b7b10c04ee0481e6fa6b0b6bed739 Mon Sep 17 00:00:00 2001 From: Tom Cooksey Date: Thu, 18 Feb 2010 17:08:29 +0100 Subject: Always use display() in QEglContext, so initialization can occur Reviewed-By: Trustme --- src/gui/egl/qegl.cpp | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/gui/egl/qegl.cpp b/src/gui/egl/qegl.cpp index 4d447cb..0ed95ea 100644 --- a/src/gui/egl/qegl.cpp +++ b/src/gui/egl/qegl.cpp @@ -101,7 +101,7 @@ bool QEglContext::chooseConfig // If we want the best pixel format, then return the first // matching configuration. if (match == QEgl::BestPixelFormat) { - eglChooseConfig(dpy, props.properties(), &cfg, 1, &matching); + eglChooseConfig(display(), props.properties(), &cfg, 1, &matching); if (matching < 1) continue; return true; @@ -111,13 +111,13 @@ bool QEglContext::chooseConfig // first that matches the pixel format we wanted. EGLint size = matching; EGLConfig *configs = new EGLConfig [size]; - eglChooseConfig(dpy, props.properties(), configs, size, &matching); + eglChooseConfig(display(), props.properties(), configs, size, &matching); for (EGLint index = 0; index < size; ++index) { EGLint red, green, blue, alpha; - eglGetConfigAttrib(dpy, configs[index], EGL_RED_SIZE, &red); - eglGetConfigAttrib(dpy, configs[index], EGL_GREEN_SIZE, &green); - eglGetConfigAttrib(dpy, configs[index], EGL_BLUE_SIZE, &blue); - eglGetConfigAttrib(dpy, configs[index], EGL_ALPHA_SIZE, &alpha); + eglGetConfigAttrib(display(), configs[index], EGL_RED_SIZE, &red); + eglGetConfigAttrib(display(), configs[index], EGL_GREEN_SIZE, &green); + eglGetConfigAttrib(display(), configs[index], EGL_BLUE_SIZE, &blue); + eglGetConfigAttrib(display(), configs[index], EGL_ALPHA_SIZE, &alpha); if (red == props.value(EGL_RED_SIZE) && green == props.value(EGL_GREEN_SIZE) && blue == props.value(EGL_BLUE_SIZE) && @@ -181,7 +181,7 @@ bool QEglContext::createContext(QEglContext *shareContext, const QEglProperties } } if (ctx == EGL_NO_CONTEXT) { - ctx = eglCreateContext(dpy, cfg, 0, contextProps.properties()); + ctx = eglCreateContext(display(), cfg, 0, contextProps.properties()); if (ctx == EGL_NO_CONTEXT) { qWarning() << "QEglContext::createContext(): Unable to create EGL context:" << errorString(eglGetError()); return false; @@ -197,7 +197,7 @@ void QEglContext::destroySurface(EGLSurface surface) if (surface != EGL_NO_SURFACE) { if (surface == currentSurface) doneCurrent(); - eglDestroySurface(dpy, surface); + eglDestroySurface(display(), surface); } } @@ -205,8 +205,7 @@ void QEglContext::destroySurface(EGLSurface surface) void QEglContext::destroyContext() { if (ctx != EGL_NO_CONTEXT && ownsContext) - eglDestroyContext(dpy, ctx); - dpy = EGL_NO_DISPLAY; + eglDestroyContext(display(), ctx); ctx = EGL_NO_CONTEXT; cfg = 0; } @@ -343,7 +342,7 @@ QEglProperties QEglContext::configProperties(EGLConfig cfg) const QEglProperties props; for (int name = 0x3020; name <= 0x304F; ++name) { EGLint value; - if (name != EGL_NONE && eglGetConfigAttrib(dpy, cfg, name, &value)) + if (name != EGL_NONE && eglGetConfigAttrib(display(), cfg, name, &value)) props.setValue(name, value); } eglGetError(); // Clear the error state. @@ -417,7 +416,7 @@ void QEglContext::dumpAllConfigs() if (!eglGetConfigs(display(), 0, 0, &count) || count < 1) return; EGLConfig *configs = new EGLConfig [count]; - eglGetConfigs(dpy, configs, count, &count); + eglGetConfigs(display(), configs, count, &count); for (EGLint index = 0; index < count; ++index) { props = configProperties(configs[index]); qWarning() << props.toString(); -- cgit v0.12 From f641369ceb7b7e2f95b9d0656b34c0517c5b95f7 Mon Sep 17 00:00:00 2001 From: Gareth Stockwell Date: Wed, 10 Feb 2010 13:20:09 +0000 Subject: Factored readRegistryKey implementation out of qmake This function is now implemented with its own header and source files, rather than being embedded within the MSVC qmake generator. The motivation for this is to allow code to be shared between qmake and configure, both of which query the registry when built for Windows. Reviewed-by: Miikka Heikkinen --- qmake/Makefile.unix | 9 +- qmake/Makefile.win32 | 7 ++ qmake/Makefile.win32-g++ | 5 + qmake/Makefile.win32-g++-sh | 5 + qmake/generators/win32/msvc_vcproj.cpp | 97 +------------------- qmake/qmake.pri | 7 +- qmake/qmake.pro | 4 + tools/shared/windows/registry.cpp | 161 +++++++++++++++++++++++++++++++++ tools/shared/windows/registry.h | 64 +++++++++++++ 9 files changed, 259 insertions(+), 100 deletions(-) create mode 100644 tools/shared/windows/registry.cpp create mode 100644 tools/shared/windows/registry.h diff --git a/qmake/Makefile.unix b/qmake/Makefile.unix index fcf43c8..e343803 100644 --- a/qmake/Makefile.unix +++ b/qmake/Makefile.unix @@ -10,7 +10,8 @@ OBJS=project.o property.o main.o makefile.o unixmake2.o unixmake.o \ mingw_make.o option.o winmakefile.o projectgenerator.o \ meta.o makefiledeps.o metamakefile.o xmloutput.o pbuilder_pbx.o \ borland_bmake.o msvc_dsp.o msvc_vcproj.o msvc_nmake.o msvc_objectmodel.o \ - symmake.o initprojectdeploy_symbian.o symmake_abld.o symmake_sbsv2.o + symmake.o initprojectdeploy_symbian.o symmake_abld.o symmake_sbsv2.o \ + registry.o #qt code QOBJS=qtextcodec.o qutfcodec.o qstring.o qtextstream.o qiodevice.o qmalloc.o qglobal.o \ @@ -20,6 +21,7 @@ QOBJS=qtextcodec.o qutfcodec.o qstring.o qtextstream.o qiodevice.o qmalloc.o qgl qfileinfo.o qdatetime.o qstringlist.o qabstractfileengine.o qtemporaryfile.o \ qmap.o qmetatype.o qsettings.o qlibraryinfo.o qvariant.o qvsnprintf.o \ qlocale.o qlinkedlist.o qurl.o qnumeric.o qcryptographichash.o qxmlstream.o qxmlutils.o \ + registry.o \ $(QTOBJS) @@ -32,6 +34,7 @@ DEPEND_SRC=project.cpp property.cpp meta.cpp main.cpp generators/makefile.cpp ge generators/makefiledeps.cpp option.cpp generators/win32/mingw_make.cpp generators/makefile.cpp \ generators/win32/msvc_objectmodel.cpp generators/win32/msvc_nmake.cpp generators/win32/borland_bmake.cpp \ generators/symbian/symmake.cpp generators/symbian/initprojectdeploy_symbian.cpp \ + $(SOURCE_PATH)/tools/shared/windows/registry.cpp \ generators/symbian/symmake_abld.cpp generators/symbian/symmake_sbsv2.cpp \ $(SOURCE_PATH)/src/corelib/codecs/qtextcodec.cpp $(SOURCE_PATH)/src/corelib/codecs/qutfcodec.cpp \ $(SOURCE_PATH)/src/corelib/tools/qstring.cpp $(SOURCE_PATH)/src/corelib/io/qfile.cpp \ @@ -62,6 +65,7 @@ DEPEND_SRC=project.cpp property.cpp meta.cpp main.cpp generators/makefile.cpp ge CPPFLAGS = -I. -Igenerators -Igenerators/unix -Igenerators/win32 -Igenerators/mac -Igenerators/symbian \ -I$(BUILD_PATH)/include -I$(BUILD_PATH)/include/QtCore \ -I$(BUILD_PATH)/src/corelib/global -I$(BUILD_PATH)/src/corelib/xml \ + -I$(BUILD_PATH)/tools/shared \ -DQT_NO_PCRE \ -DQT_BUILD_QMAKE -DQT_BOOTSTRAPPED \ -DQT_NO_TEXTCODEC -DQT_NO_UNICODETABLES -DQT_NO_COMPONENT -DQT_NO_STL \ @@ -281,6 +285,9 @@ symmake_sbsv2.o: generators/symbian/symmake_sbsv2.cpp initprojectdeploy_symbian.o: generators/symbian/initprojectdeploy_symbian.cpp $(CXX) -c -o $@ $(CXXFLAGS) generators/symbian/initprojectdeploy_symbian.cpp +registry.o: $(SOURCE_PATH)/tools/shared/windows/registry.cpp + $(CXX) -c -o $@ $(CXXFLAGS) $(SOURCE_PATH)/tools/shared/windows/registry.cpp + projectgenerator.o: generators/projectgenerator.cpp $(CXX) -c -o $@ $(CXXFLAGS) generators/projectgenerator.cpp diff --git a/qmake/Makefile.win32 b/qmake/Makefile.win32 index e6bbcd5..3cd180c 100644 --- a/qmake/Makefile.win32 +++ b/qmake/Makefile.win32 @@ -34,6 +34,7 @@ CFLAGS = -c -Fo$@ \ -I$(BUILD_PATH)\src\corelib\global \ -I$(BUILD_PATH)\src\corelib\xml \ -I$(SOURCE_PATH)\mkspecs\$(QMAKESPEC) \ + -I$(SOURCE_PATH)\tools\shared \ -DQT_NO_TEXTCODEC -DQT_NO_UNICODETABLES -DQT_LITE_COMPONENT -DQT_NODLL -DQT_NO_STL \ -DQT_NO_COMPRESS -DUNICODE -DHAVE_QCONFIG_CPP -DQT_BUILD_QMAKE -DQT_NO_THREAD \ -DQT_NO_QOBJECT -DQT_NO_GEOM_VARIANT -DQT_NO_DATASTREAM -DQT_NO_PCRE -DQT_BOOTSTRAPPED \ @@ -59,6 +60,7 @@ CFLAGS = -c -o$@ \ -I$(SOURCE_PATH)\include -I$(SOURCE_PATH)\include\QtCore \ -I$(BUILD_PATH)\src\corelib\global \ -I$(SOURCE_PATH)\mkspecs\$(QMAKESPEC) \ + -I$(SOURCE_PATH)\tools\shared \ -DQT_NO_TEXTCODEC -DQT_NO_UNICODETABLES -DQT_LITE_COMPONENT -DQT_NODLL -DQT_NO_STL \ -DQT_NO_COMPRESS -DUNICODE -DHAVE_QCONFIG_CPP -DQT_BUILD_QMAKE -DQT_NO_THREAD \ -DQT_NO_QOBJECT -DQT_NO_GEOM_VARIANT @@ -75,6 +77,7 @@ OBJS = project.obj main.obj makefile.obj unixmake.obj unixmake2.obj mingw makefiledeps.obj metamakefile.obj xmloutput.obj pbuilder_pbx.obj \ borland_bmake.obj msvc_nmake.obj msvc_dsp.obj msvc_vcproj.obj \ msvc_objectmodel.obj symmake.obj initprojectdeploy_symbian.obj \ + registry.obj \ symmake_abld.obj symmake_sbsv2.obj !IFDEF QMAKE_OPENSOURCE_EDITION @@ -198,6 +201,7 @@ clean:: -del symmake_abld.obj -del symmake_sbsv2.obj -del initprojectdeploy_symbian.obj + -del registry.obj -del pbuilder_pbx.obj -del qxmlstream.obj -del qxmlutils.obj @@ -397,6 +401,9 @@ symmake_sbsv2.obj: $(SOURCE_PATH)/qmake/generators/symbian/symmake_sbsv2.cpp initprojectdeploy_symbian.obj: $(SOURCE_PATH)/qmake/generators/symbian/initprojectdeploy_symbian.cpp $(CXX) $(CXXFLAGS) generators/symbian/initprojectdeploy_symbian.cpp +registry.obj: $(SOURCE_PATH)/tools/shared/windows/registry.cpp + $(CXX) $(CXXFLAGS) $(SOURCE_PATH)/tools/shared/windows/registry.cpp + md5.obj: $(SOURCE_PATH)\src\3rdparty\md5\md5.cpp $(CXX) $(CXXFLAGS) $(SOURCE_PATH)\src\3rdparty\md5\md5.cpp diff --git a/qmake/Makefile.win32-g++ b/qmake/Makefile.win32-g++ index ade379b..ebc7fe2 100644 --- a/qmake/Makefile.win32-g++ +++ b/qmake/Makefile.win32-g++ @@ -21,6 +21,7 @@ CFLAGS = -c -o$@ -O \ -I$(BUILD_PATH)/src/corelib/global \ -I$(BUILD_PATH)/src/corelib/xml \ -I$(SOURCE_PATH)/mkspecs/win32-g++ \ + -I$(SOURCE_PATH)/tools/shared \ -DQT_NO_TEXTCODEC -DQT_NO_UNICODETABLES -DQT_LITE_COMPONENT -DQT_NO_PCRE \ -DQT_NODLL -DQT_NO_STL -DQT_NO_COMPRESS -DUNICODE -DHAVE_QCONFIG_CPP \ -DQT_BUILD_QMAKE -DQT_NO_THREAD -DQT_NO_QOBJECT -DQT_NO_GEOM_VARIANT -DQT_NO_DATASTREAM \ @@ -38,6 +39,7 @@ OBJS = project.o main.o makefile.o unixmake.o unixmake2.o mingw_make.o \ makefiledeps.o metamakefile.o xmloutput.o pbuilder_pbx.o \ borland_bmake.o msvc_nmake.o msvc_dsp.o msvc_vcproj.o \ msvc_objectmodel.o symmake.o initprojectdeploy_symbian.o \ + registry.o \ symmake_abld.o symmake_sbsv2.o ifdef QMAKE_OPENSOURCE_EDITION @@ -278,6 +280,9 @@ symmake_sbsv2.o: $(SOURCE_PATH)/qmake/generators/symbian/symmake_sbsv2.cpp initprojectdeploy_symbian.o: $(SOURCE_PATH)/qmake/generators/symbian/initprojectdeploy_symbian.cpp $(CXX) $(CXXFLAGS) generators/symbian/initprojectdeploy_symbian.cpp +registry.o: $(SOURCE_PATH)/tools/shared/windows/registry.cpp + $(CXX) $(CXXFLAGS) $(SOURCE_PATH)/tools/shared/windows/registry.cpp + project.o: $(SOURCE_PATH)/qmake/project.cpp $(SOURCE_PATH)/qmake/project.h $(SOURCE_PATH)/qmake/option.h $(CXX) $(CXXFLAGS) project.cpp diff --git a/qmake/Makefile.win32-g++-sh b/qmake/Makefile.win32-g++-sh index 8d2723c..1d55da2 100644 --- a/qmake/Makefile.win32-g++-sh +++ b/qmake/Makefile.win32-g++-sh @@ -21,6 +21,7 @@ CFLAGS = -c -o$@ -O \ -I$(BUILD_PATH)/src/corelib/global \ -I$(BUILD_PATH)/src/corelib/xml \ -I$(SOURCE_PATH)/mkspecs/win32-g++ \ + -I$(SOURCE_PATH)/tools/shared \ -DQT_NO_TEXTCODEC -DQT_NO_UNICODETABLES -DQT_LITE_COMPONENT -DQT_NO_PCRE \ -DQT_NODLL -DQT_NO_STL -DQT_NO_COMPRESS -DUNICODE -DHAVE_QCONFIG_CPP \ -DQT_BUILD_QMAKE -DQT_NO_THREAD -DQT_NO_QOBJECT -DQT_NO_GEOM_VARIANT -DQT_NO_DATASTREAM \ @@ -38,6 +39,7 @@ OBJS = project.o main.o makefile.o unixmake.o unixmake2.o mingw_make.o \ makefiledeps.o metamakefile.o xmloutput.o pbuilder_pbx.o \ borland_bmake.o msvc_nmake.o msvc_dsp.o msvc_vcproj.o \ msvc_objectmodel.o symmake.o initprojectdeploy_symbian.o \ + registry.o \ symmake_abld.o symmake_sbsv2.o ifdef QMAKE_OPENSOURCE_EDITION @@ -277,6 +279,9 @@ symmake_sbsv2.o: $(SOURCE_PATH)/qmake/generators/symbian/symmake_sbsv2.cpp initprojectdeploy_symbian.o: $(SOURCE_PATH)/qmake/generators/symbian/initprojectdeploy_symbian.cpp $(CXX) $(CXXFLAGS) generators/symbian/initprojectdeploy_symbian.cpp +registry.o: $(SOURCE_PATH)/tools/shared/windows/registry.cpp + $(CXX) $(CXXFLAGS) $(SOURCE_PATH)/tools/shared/windows/registry.cpp + project.o: $(SOURCE_PATH)/qmake/project.cpp $(SOURCE_PATH)/qmake/project.h $(SOURCE_PATH)/qmake/option.h $(CXX) $(CXXFLAGS) project.cpp diff --git a/qmake/generators/win32/msvc_vcproj.cpp b/qmake/generators/win32/msvc_vcproj.cpp index 47986f5..58f95e9 100644 --- a/qmake/generators/win32/msvc_vcproj.cpp +++ b/qmake/generators/win32/msvc_vcproj.cpp @@ -67,6 +67,7 @@ QT_END_NAMESPACE #ifdef Q_OS_WIN32 #include +#include QT_BEGIN_NAMESPACE @@ -93,102 +94,6 @@ struct { {NETUnknown, "", ""}, }; -static QString keyPath(const QString &rKey) -{ - int idx = rKey.lastIndexOf(QLatin1Char('\\')); - if (idx == -1) - return QString(); - return rKey.left(idx + 1); -} - -static QString keyName(const QString &rKey) -{ - int idx = rKey.lastIndexOf(QLatin1Char('\\')); - if (idx == -1) - return rKey; - - QString res(rKey.mid(idx + 1)); - if (res == "Default" || res == ".") - res = ""; - return res; -} - -static QString readRegistryKey(HKEY parentHandle, const QString &rSubkey) -{ - - QString rSubkeyName = keyName(rSubkey); - QString rSubkeyPath = keyPath(rSubkey); - - HKEY handle = 0; - LONG res = RegOpenKeyEx(parentHandle, (wchar_t*)rSubkeyPath.utf16(), 0, KEY_READ, &handle); - - if (res != ERROR_SUCCESS) - return QString(); - - // get the size and type of the value - DWORD dataType; - DWORD dataSize; - res = RegQueryValueEx(handle, (wchar_t*)rSubkeyName.utf16(), 0, &dataType, 0, &dataSize); - if (res != ERROR_SUCCESS) { - RegCloseKey(handle); - return QString(); - } - - // get the value - QByteArray data(dataSize, 0); - res = RegQueryValueEx(handle, (wchar_t*)rSubkeyName.utf16(), 0, 0, - reinterpret_cast(data.data()), &dataSize); - if (res != ERROR_SUCCESS) { - RegCloseKey(handle); - return QString(); - } - - QString result; - switch (dataType) { - case REG_EXPAND_SZ: - case REG_SZ: { - result = QString::fromWCharArray(((const wchar_t *)data.constData())); - break; - } - - case REG_MULTI_SZ: { - QStringList l; - int i = 0; - for (;;) { - QString s = QString::fromWCharArray((const wchar_t *)data.constData() + i); - i += s.length() + 1; - - if (s.isEmpty()) - break; - l.append(s); - } - result = l.join(", "); - break; - } - - case REG_NONE: - case REG_BINARY: { - result = QString::fromWCharArray((const wchar_t *)data.constData(), data.size() / 2); - break; - } - - case REG_DWORD_BIG_ENDIAN: - case REG_DWORD: { - Q_ASSERT(data.size() == sizeof(int)); - int i; - memcpy((char*)&i, data.constData(), sizeof(int)); - result = QString::number(i); - break; - } - - default: - qWarning("QSettings: unknown data %d type in windows registry", dataType); - break; - } - - RegCloseKey(handle); - return result; -} QT_END_NAMESPACE #endif diff --git a/qmake/qmake.pri b/qmake/qmake.pri index efe4f36..a2ffe15 100644 --- a/qmake/qmake.pri +++ b/qmake/qmake.pri @@ -17,7 +17,8 @@ SOURCES += project.cpp property.cpp main.cpp generators/makefile.cpp \ generators/symbian/symmake.cpp \ generators/symbian/symmake_abld.cpp \ generators/symbian/symmake_sbsv2.cpp \ - generators/symbian/initprojectdeploy_symbian.cpp + generators/symbian/initprojectdeploy_symbian.cpp \ + windows/registry.cpp HEADERS += project.h property.h generators/makefile.h \ generators/unix/unixmake.h meta.h option.h cachekeys.h \ @@ -29,8 +30,8 @@ HEADERS += project.h property.h generators/makefile.h \ generators/symbian/symmake.h \ generators/symbian/symmake_abld.h \ generators/symbian/symmake_sbsv2.h \ - generators/symbian/epocroot.h \ - generators/symbian/initprojectdeploy_symbian.h + generators/symbian/initprojectdeploy_symbian.h \ + windows/registry.h contains(QT_EDITION, OpenSource) { DEFINES += QMAKE_OPENSOURCE_EDITION diff --git a/qmake/qmake.pro b/qmake/qmake.pro index 00dcbce..f3f9d53 100644 --- a/qmake/qmake.pro +++ b/qmake/qmake.pro @@ -27,5 +27,9 @@ INCPATH += generators \ $$QT_SOURCE_TREE/include \ $$QT_SOURCE_TREE/include/QtCore \ $$QT_SOURCE_TREE/qmake + +VPATH += $$QT_SOURCE_TREE/tools/shared +INCPATH += $$QT_SOURCE_TREE/tools/shared + include(qmake.pri) diff --git a/tools/shared/windows/registry.cpp b/tools/shared/windows/registry.cpp new file mode 100644 index 0000000..d342d78 --- /dev/null +++ b/tools/shared/windows/registry.cpp @@ -0,0 +1,161 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the qmake application 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 "registry.h" + +/*! + Returns the path part of a registry key. + e.g. + For a key + "Software\\Microsoft\\VisualStudio\\8.0\\Setup\\VC\\ProductDir" + it returns + "Software\\Microsoft\\VisualStudio\\8.0\\Setup\\VC\\" +*/ +static QString keyPath(const QString &rKey) +{ + int idx = rKey.lastIndexOf(QLatin1Char('\\')); + if (idx == -1) + return QString(); + return rKey.left(idx + 1); +} + +/*! + Returns the name part of a registry key. + e.g. + For a key + "Software\\Microsoft\\VisualStudio\\8.0\\Setup\\VC\\ProductDir" + it returns + "ProductDir" +*/ +static QString keyName(const QString &rKey) +{ + int idx = rKey.lastIndexOf(QLatin1Char('\\')); + if (idx == -1) + return rKey; + + QString res(rKey.mid(idx + 1)); + if (res == "Default" || res == ".") + res = ""; + return res; +} + +QString readRegistryKey(HKEY parentHandle, const QString &rSubkey) +{ + QString result; + +#ifdef Q_OS_WIN32 + QString rSubkeyName = keyName(rSubkey); + QString rSubkeyPath = keyPath(rSubkey); + + HKEY handle = 0; + LONG res = RegOpenKeyEx(parentHandle, (wchar_t*)rSubkeyPath.utf16(), 0, KEY_READ, &handle); + + if (res != ERROR_SUCCESS) + return QString(); + + // get the size and type of the value + DWORD dataType; + DWORD dataSize; + res = RegQueryValueEx(handle, (wchar_t*)rSubkeyName.utf16(), 0, &dataType, 0, &dataSize); + if (res != ERROR_SUCCESS) { + RegCloseKey(handle); + return QString(); + } + + // get the value + QByteArray data(dataSize, 0); + res = RegQueryValueEx(handle, (wchar_t*)rSubkeyName.utf16(), 0, 0, + reinterpret_cast(data.data()), &dataSize); + if (res != ERROR_SUCCESS) { + RegCloseKey(handle); + return QString(); + } + + switch (dataType) { + case REG_EXPAND_SZ: + case REG_SZ: { + result = QString::fromWCharArray(((const wchar_t *)data.constData())); + break; + } + + case REG_MULTI_SZ: { + QStringList l; + int i = 0; + for (;;) { + QString s = QString::fromWCharArray((const wchar_t *)data.constData() + i); + i += s.length() + 1; + + if (s.isEmpty()) + break; + l.append(s); + } + result = l.join(", "); + break; + } + + case REG_NONE: + case REG_BINARY: { + result = QString::fromWCharArray((const wchar_t *)data.constData(), data.size() / 2); + break; + } + + case REG_DWORD_BIG_ENDIAN: + case REG_DWORD: { + Q_ASSERT(data.size() == sizeof(int)); + int i; + memcpy((char*)&i, data.constData(), sizeof(int)); + result = QString::number(i); + break; + } + + default: + qWarning("QSettings: unknown data %d type in windows registry", dataType); + break; + } + + RegCloseKey(handle); +#endif + + return result; +} + + diff --git a/tools/shared/windows/registry.h b/tools/shared/windows/registry.h new file mode 100644 index 0000000..3896527 --- /dev/null +++ b/tools/shared/windows/registry.h @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the qmake application 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$ +** +****************************************************************************/ + +#ifndef WINDOWS_REGISTRY_H +#define WINDOWS_REGISTRY_H + +#include + +#ifdef Q_OS_WIN32 + #include +#else + typedef void* HKEY; +#endif + +#include + +/** + * Read a value from the Windows registry. + * + * If the key is not found, or the registry cannot be accessed (for example + * if this code is compiled for a platform other than Windows), a null + * string is returned. + */ +QString readRegistryKey(HKEY parentHandle, const QString &rSubkey); + +#endif // WINDOWS_REGISTRY_H -- cgit v0.12 From 13cb80be958c40077245cbc4b36448a661e30c64 Mon Sep 17 00:00:00 2001 From: Gareth Stockwell Date: Wed, 10 Feb 2010 14:57:51 +0000 Subject: Factored epocRoot implementation out of qmake This function is now implemented in its own source file, rather than being embedded within the Symbian qmake generator. The motivation for this is to allow code to be shared between qmake and configure - the latter needs to determine the epoc root path in order to perform feature detection on Symbian SDKs. Reviewed-by: Miikka Heikkinen --- qmake/Makefile.unix | 9 +- qmake/Makefile.win32 | 5 + qmake/Makefile.win32-g++ | 4 + qmake/Makefile.win32-g++-sh | 4 + qmake/generators/symbian/epocroot.h | 51 ----- .../symbian/initprojectdeploy_symbian.cpp | 96 +-------- .../generators/symbian/initprojectdeploy_symbian.h | 2 - qmake/generators/symbian/symmake.cpp | 3 + qmake/generators/symbian/symmake_abld.cpp | 3 + qmake/generators/symbian/symmake_sbsv2.cpp | 3 + qmake/project.cpp | 5 +- qmake/qmake.pri | 6 +- tools/shared/symbian/epocroot.cpp | 230 +++++++++++++++++++++ tools/shared/symbian/epocroot.h | 67 ++++++ 14 files changed, 337 insertions(+), 151 deletions(-) delete mode 100644 qmake/generators/symbian/epocroot.h create mode 100644 tools/shared/symbian/epocroot.cpp create mode 100644 tools/shared/symbian/epocroot.h diff --git a/qmake/Makefile.unix b/qmake/Makefile.unix index e343803..5469134 100644 --- a/qmake/Makefile.unix +++ b/qmake/Makefile.unix @@ -11,7 +11,8 @@ OBJS=project.o property.o main.o makefile.o unixmake2.o unixmake.o \ meta.o makefiledeps.o metamakefile.o xmloutput.o pbuilder_pbx.o \ borland_bmake.o msvc_dsp.o msvc_vcproj.o msvc_nmake.o msvc_objectmodel.o \ symmake.o initprojectdeploy_symbian.o symmake_abld.o symmake_sbsv2.o \ - registry.o + registry.o \ + epocroot.o #qt code QOBJS=qtextcodec.o qutfcodec.o qstring.o qtextstream.o qiodevice.o qmalloc.o qglobal.o \ @@ -22,6 +23,7 @@ QOBJS=qtextcodec.o qutfcodec.o qstring.o qtextstream.o qiodevice.o qmalloc.o qgl qmap.o qmetatype.o qsettings.o qlibraryinfo.o qvariant.o qvsnprintf.o \ qlocale.o qlinkedlist.o qurl.o qnumeric.o qcryptographichash.o qxmlstream.o qxmlutils.o \ registry.o \ + epocroot.o \ $(QTOBJS) @@ -35,6 +37,7 @@ DEPEND_SRC=project.cpp property.cpp meta.cpp main.cpp generators/makefile.cpp ge generators/win32/msvc_objectmodel.cpp generators/win32/msvc_nmake.cpp generators/win32/borland_bmake.cpp \ generators/symbian/symmake.cpp generators/symbian/initprojectdeploy_symbian.cpp \ $(SOURCE_PATH)/tools/shared/windows/registry.cpp \ + $(SOURCE_PATH)/tools/shared/symbian/epocroot.cpp \ generators/symbian/symmake_abld.cpp generators/symbian/symmake_sbsv2.cpp \ $(SOURCE_PATH)/src/corelib/codecs/qtextcodec.cpp $(SOURCE_PATH)/src/corelib/codecs/qutfcodec.cpp \ $(SOURCE_PATH)/src/corelib/tools/qstring.cpp $(SOURCE_PATH)/src/corelib/io/qfile.cpp \ @@ -288,6 +291,9 @@ initprojectdeploy_symbian.o: generators/symbian/initprojectdeploy_symbian.cpp registry.o: $(SOURCE_PATH)/tools/shared/windows/registry.cpp $(CXX) -c -o $@ $(CXXFLAGS) $(SOURCE_PATH)/tools/shared/windows/registry.cpp +epocroot.o: $(SOURCE_PATH)/tools/shared/symbian/epocroot.cpp + $(CXX) -c -o $@ $(CXXFLAGS) $(SOURCE_PATH)/tools/shared/symbian/epocroot.cpp + projectgenerator.o: generators/projectgenerator.cpp $(CXX) -c -o $@ $(CXXFLAGS) generators/projectgenerator.cpp @@ -296,6 +302,7 @@ qxmlstream.o: $(SOURCE_PATH)/src/corelib/xml/qxmlstream.cpp qxmlutils.o: $(SOURCE_PATH)/src/corelib/xml/qxmlutils.cpp $(CXX) -c -o $@ $(CXXFLAGS) $(SOURCE_PATH)/src/corelib/xml/qxmlutils.cpp + #default rules .cpp.o: $(CXX) -c -o $@ $(CXXFLAGS) $< diff --git a/qmake/Makefile.win32 b/qmake/Makefile.win32 index 3cd180c..48d84b7 100644 --- a/qmake/Makefile.win32 +++ b/qmake/Makefile.win32 @@ -78,6 +78,7 @@ OBJS = project.obj main.obj makefile.obj unixmake.obj unixmake2.obj mingw borland_bmake.obj msvc_nmake.obj msvc_dsp.obj msvc_vcproj.obj \ msvc_objectmodel.obj symmake.obj initprojectdeploy_symbian.obj \ registry.obj \ + epocroot.obj \ symmake_abld.obj symmake_sbsv2.obj !IFDEF QMAKE_OPENSOURCE_EDITION @@ -202,6 +203,7 @@ clean:: -del symmake_sbsv2.obj -del initprojectdeploy_symbian.obj -del registry.obj + -del epocroot.obj -del pbuilder_pbx.obj -del qxmlstream.obj -del qxmlutils.obj @@ -404,6 +406,9 @@ initprojectdeploy_symbian.obj: $(SOURCE_PATH)/qmake/generators/symbian/initproje registry.obj: $(SOURCE_PATH)/tools/shared/windows/registry.cpp $(CXX) $(CXXFLAGS) $(SOURCE_PATH)/tools/shared/windows/registry.cpp +epocroot.obj: $(SOURCE_PATH)/tools/shared/symbian/epocroot.cpp + $(CXX) $(CXXFLAGS) $(SOURCE_PATH)/tools/shared/symbian/epocroot.cpp + md5.obj: $(SOURCE_PATH)\src\3rdparty\md5\md5.cpp $(CXX) $(CXXFLAGS) $(SOURCE_PATH)\src\3rdparty\md5\md5.cpp diff --git a/qmake/Makefile.win32-g++ b/qmake/Makefile.win32-g++ index ebc7fe2..169de3c 100644 --- a/qmake/Makefile.win32-g++ +++ b/qmake/Makefile.win32-g++ @@ -40,6 +40,7 @@ OBJS = project.o main.o makefile.o unixmake.o unixmake2.o mingw_make.o \ borland_bmake.o msvc_nmake.o msvc_dsp.o msvc_vcproj.o \ msvc_objectmodel.o symmake.o initprojectdeploy_symbian.o \ registry.o \ + epocroot.o \ symmake_abld.o symmake_sbsv2.o ifdef QMAKE_OPENSOURCE_EDITION @@ -283,6 +284,9 @@ initprojectdeploy_symbian.o: $(SOURCE_PATH)/qmake/generators/symbian/initproject registry.o: $(SOURCE_PATH)/tools/shared/windows/registry.cpp $(CXX) $(CXXFLAGS) $(SOURCE_PATH)/tools/shared/windows/registry.cpp +epocroot.o: $(SOURCE_PATH)/tools/shared/symbian/epocroot.cpp + $(CXX) $(CXXFLAGS) $(SOURCE_PATH)/tools/shared/symbian/epocroot.cpp + project.o: $(SOURCE_PATH)/qmake/project.cpp $(SOURCE_PATH)/qmake/project.h $(SOURCE_PATH)/qmake/option.h $(CXX) $(CXXFLAGS) project.cpp diff --git a/qmake/Makefile.win32-g++-sh b/qmake/Makefile.win32-g++-sh index 1d55da2..98237e7 100644 --- a/qmake/Makefile.win32-g++-sh +++ b/qmake/Makefile.win32-g++-sh @@ -40,6 +40,7 @@ OBJS = project.o main.o makefile.o unixmake.o unixmake2.o mingw_make.o \ borland_bmake.o msvc_nmake.o msvc_dsp.o msvc_vcproj.o \ msvc_objectmodel.o symmake.o initprojectdeploy_symbian.o \ registry.o \ + epocroot.o \ symmake_abld.o symmake_sbsv2.o ifdef QMAKE_OPENSOURCE_EDITION @@ -282,6 +283,9 @@ initprojectdeploy_symbian.o: $(SOURCE_PATH)/qmake/generators/symbian/initproject registry.o: $(SOURCE_PATH)/tools/shared/windows/registry.cpp $(CXX) $(CXXFLAGS) $(SOURCE_PATH)/tools/shared/windows/registry.cpp +epocroot.o: $(SOURCE_PATH)/tools/shared/symbian/epocroot.cpp + $(CXX) $(CXXFLAGS) $(SOURCE_PATH)/tools/shared/symbian/epocroot.cpp + project.o: $(SOURCE_PATH)/qmake/project.cpp $(SOURCE_PATH)/qmake/project.h $(SOURCE_PATH)/qmake/option.h $(CXX) $(CXXFLAGS) project.cpp diff --git a/qmake/generators/symbian/epocroot.h b/qmake/generators/symbian/epocroot.h deleted file mode 100644 index be26438..0000000 --- a/qmake/generators/symbian/epocroot.h +++ /dev/null @@ -1,51 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the qmake application 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$ -** -****************************************************************************/ - -#ifndef EPOCROOT_H -#define EPOCROOT_H - -#include - -// Implementation of epocRoot method is in initprojectdeploy_symbian.cpp -// Defined in separate header for inclusion clarity -extern QString epocRoot(); - -#endif // EPOCROOT_H diff --git a/qmake/generators/symbian/initprojectdeploy_symbian.cpp b/qmake/generators/symbian/initprojectdeploy_symbian.cpp index 5fbff58..2a22305 100644 --- a/qmake/generators/symbian/initprojectdeploy_symbian.cpp +++ b/qmake/generators/symbian/initprojectdeploy_symbian.cpp @@ -46,105 +46,15 @@ #include #include +// Included from tools/shared +#include + #define SYSBIN_DIR "\\sys\\bin" #define SUFFIX_DLL "dll" #define SUFFIX_EXE "exe" #define SUFFIX_QTPLUGIN "qtplugin" -static void fixEpocRootStr(QString& path) -{ - path.replace("\\", "/"); - - if (path.size() > 1 && path[1] == QChar(':')) { - path = path.mid(2); - } - - if (!path.size() || path[path.size()-1] != QChar('/')) { - path += QChar('/'); - } -} - -#define SYMBIAN_SDKS_KEY "HKEY_LOCAL_MACHINE\\Software\\Symbian\\EPOC SDKs" - -static QString epocRootStr; - -QString epocRoot() -{ - if (!epocRootStr.isEmpty()) { - return epocRootStr; - } - - // First, check the env variable - epocRootStr = qgetenv("EPOCROOT"); - - if (epocRootStr.isEmpty()) { - // No EPOCROOT set, check the default device - // First check EPOCDEVICE env variable - QString defaultDevice = qgetenv("EPOCDEVICE"); - - // Check the windows registry via QSettings for devices.xml path - QSettings settings(SYMBIAN_SDKS_KEY, QSettings::NativeFormat); - QString devicesXmlPath = settings.value("CommonPath").toString(); - - if (!devicesXmlPath.isEmpty()) { - // Parse xml for correct device - devicesXmlPath += "/devices.xml"; - QFile devicesFile(devicesXmlPath); - if (devicesFile.open(QIODevice::ReadOnly)) { - QXmlStreamReader xml(&devicesFile); - while (!xml.atEnd()) { - xml.readNext(); - if (xml.isStartElement() && xml.name() == "devices") { - if (xml.attributes().value("version") == "1.0") { - // Look for correct device - while (!(xml.isEndElement() && xml.name() == "devices") && !xml.atEnd()) { - xml.readNext(); - if (xml.isStartElement() && xml.name() == "device") { - if ((defaultDevice.isEmpty() && xml.attributes().value("default") == "yes") || - (!defaultDevice.isEmpty() && (xml.attributes().value("id").toString() + QString(":") + xml.attributes().value("name").toString()) == defaultDevice)) { - // Found the correct device - while (!(xml.isEndElement() && xml.name() == "device") && !xml.atEnd()) { - xml.readNext(); - if (xml.isStartElement() && xml.name() == "epocroot") { - epocRootStr = xml.readElementText(); - fixEpocRootStr(epocRootStr); - return epocRootStr; - } - } - xml.raiseError("No epocroot element found"); - } - } - } - } else { - xml.raiseError("Invalid 'devices' element version"); - } - } - } - if (xml.hasError()) { - fprintf(stderr, "ERROR: \"%s\" when parsing devices.xml\n", qPrintable(xml.errorString())); - } - } else { - fprintf(stderr, "Could not open devices.xml (%s)\n", qPrintable(devicesXmlPath)); - } - } else { - fprintf(stderr, "Could not retrieve " SYMBIAN_SDKS_KEY " setting\n"); - } - - fprintf(stderr, "Failed to determine epoc root.\n"); - if (!defaultDevice.isEmpty()) - fprintf(stderr, "The device indicated by EPOCDEVICE environment variable (%s) could not be found.\n", qPrintable(defaultDevice)); - fprintf(stderr, "Either set EPOCROOT or EPOCDEVICE environment variable to a valid value, or provide a default Symbian device.\n"); - - // No valid device found; set epocroot to "/" - epocRootStr = QLatin1String("/"); - } - - fixEpocRootStr(epocRootStr); - return epocRootStr; -} - - static bool isPlugin(const QFileInfo& info, const QString& devicePath) { // Libraries are plugins if deployment path is something else than diff --git a/qmake/generators/symbian/initprojectdeploy_symbian.h b/qmake/generators/symbian/initprojectdeploy_symbian.h index e23e6a9..b409225 100644 --- a/qmake/generators/symbian/initprojectdeploy_symbian.h +++ b/qmake/generators/symbian/initprojectdeploy_symbian.h @@ -50,8 +50,6 @@ #include #include -#include "epocroot.h" - #define PLUGIN_STUB_DIR "qmakepluginstubs" struct CopyItem diff --git a/qmake/generators/symbian/symmake.cpp b/qmake/generators/symbian/symmake.cpp index 2055f81..a712434 100644 --- a/qmake/generators/symbian/symmake.cpp +++ b/qmake/generators/symbian/symmake.cpp @@ -49,6 +49,9 @@ #include #include +// Included from tools/shared +#include + #define RESOURCE_DIRECTORY_MMP "/resource/apps" #define RESOURCE_DIRECTORY_RESOURCE "\\\\resource\\\\apps\\\\" #define REGISTRATION_RESOURCE_DIRECTORY_HW "/private/10003a3f/import/apps" diff --git a/qmake/generators/symbian/symmake_abld.cpp b/qmake/generators/symbian/symmake_abld.cpp index 033bcbe..6c62412 100644 --- a/qmake/generators/symbian/symmake_abld.cpp +++ b/qmake/generators/symbian/symmake_abld.cpp @@ -48,6 +48,9 @@ #include #include +// Included from tools/shared +#include + #define DO_NOTHING_TARGET "do_nothing" #define CREATE_TEMPS_TARGET "create_temps" #define EXTENSION_CLEAN "extension_clean" diff --git a/qmake/generators/symbian/symmake_sbsv2.cpp b/qmake/generators/symbian/symmake_sbsv2.cpp index e081b19..8accfce 100644 --- a/qmake/generators/symbian/symmake_sbsv2.cpp +++ b/qmake/generators/symbian/symmake_sbsv2.cpp @@ -48,6 +48,9 @@ #include #include +// Included from tools/shared +#include + SymbianSbsv2MakefileGenerator::SymbianSbsv2MakefileGenerator() : SymbianMakefileGenerator() { } SymbianSbsv2MakefileGenerator::~SymbianSbsv2MakefileGenerator() { } diff --git a/qmake/project.cpp b/qmake/project.cpp index 4ce8ba4..e4ef7dd 100644 --- a/qmake/project.cpp +++ b/qmake/project.cpp @@ -44,8 +44,6 @@ #include "option.h" #include "cachekeys.h" -#include "epocroot.h" - #include #include #include @@ -64,6 +62,9 @@ #include #include +// Included from tools/shared +#include + #ifdef Q_OS_WIN32 #define QT_POPEN _popen #define QT_PCLOSE _pclose diff --git a/qmake/qmake.pri b/qmake/qmake.pri index a2ffe15..05debe6 100644 --- a/qmake/qmake.pri +++ b/qmake/qmake.pri @@ -18,7 +18,8 @@ SOURCES += project.cpp property.cpp main.cpp generators/makefile.cpp \ generators/symbian/symmake_abld.cpp \ generators/symbian/symmake_sbsv2.cpp \ generators/symbian/initprojectdeploy_symbian.cpp \ - windows/registry.cpp + windows/registry.cpp \ + symbian/epocroot.cpp HEADERS += project.h property.h generators/makefile.h \ generators/unix/unixmake.h meta.h option.h cachekeys.h \ @@ -31,7 +32,8 @@ HEADERS += project.h property.h generators/makefile.h \ generators/symbian/symmake_abld.h \ generators/symbian/symmake_sbsv2.h \ generators/symbian/initprojectdeploy_symbian.h \ - windows/registry.h + windows/registry.h \ + symbian/epocroot.h contains(QT_EDITION, OpenSource) { DEFINES += QMAKE_OPENSOURCE_EDITION diff --git a/tools/shared/symbian/epocroot.cpp b/tools/shared/symbian/epocroot.cpp new file mode 100644 index 0000000..071477d --- /dev/null +++ b/tools/shared/symbian/epocroot.cpp @@ -0,0 +1,230 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the qmake application 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 + +#include "epocroot.h" +#include "../windows/registry.h" + +// Registry key under which the location of the Symbian devices.xml file is +// stored. +// Note that, on 64-bit machines, this key is located under the 32-bit +// compatibility key: +// HKEY_LOCAL_MACHINE\Software\Wow6432Node +#define SYMBIAN_SDKS_REG_SUBKEY "Software\\Symbian\\EPOC SDKs\\CommonPath" + +#ifdef Q_OS_WIN32 +# define SYMBIAN_SDKS_REG_HANDLE HKEY_LOCAL_MACHINE +#else +# define SYMBIAN_SDKS_REG_HANDLE 0 +#endif + +// Value which is populated and returned by the epocRoot() function. +// Stored as a static value in order to avoid unnecessary re-evaluation. +static QString epocRootValue; + +#ifdef QT_BUILD_QMAKE +std::ostream &operator<<(std::ostream &s, const QString &val) { + s << val.toLocal8Bit().data(); + return s; +} +#else +// Operator implemented in configureapp.cpp +std::ostream &operator<<(std::ostream &s, const QString &val); +#endif + +QString getDevicesXmlPath() + { + // Note that the following call will return a null string on platforms other + // than Windows. If support is required on other platforms for devices.xml, + // an alternative mechanism for retrieving the location of this file will + // be required. + return readRegistryKey(SYMBIAN_SDKS_REG_HANDLE, SYMBIAN_SDKS_REG_SUBKEY); + } + +/** + * Checks whether epocRootValue points to an existent directory. + * If not, epocRootValue is set to an empty string and an error message is printed. + */ +void checkEpocRootExists(const QString &source) +{ + if (!epocRootValue.isEmpty()) { + QDir dir(epocRootValue); + if (!dir.exists()) { + std::cerr << "Warning: " << source << " is set to an invalid path: " << epocRootValue << std::endl; + epocRootValue = QString(); + } + } +} + +/** + * Translate path from Windows to Qt format. + */ +static void fixEpocRoot(QString &path) +{ + path.replace("\\", "/"); + + if (path.size() > 1 && path[1] == QChar(':')) { + path = path.mid(2); + } + + if (!path.size() || path[path.size()-1] != QChar('/')) { + path += QChar('/'); + } +} + +/** + * Determine the epoc root for the currently active SDK. + */ +QString epocRoot() +{ + if (epocRootValue.isEmpty()) { + // 1. If environment variable EPOCROOT is set and points to an existent + // directory, this is returned. + epocRootValue = qgetenv("EPOCROOT"); + checkEpocRootExists("EPOCROOT"); + + if (epocRootValue.isEmpty()) { + // 2. The location of devices.xml is specified by a registry key. If this + // file exists, it is parsed. + QString devicesXmlPath = getDevicesXmlPath(); + if (devicesXmlPath.isEmpty()) { + std::cerr << "Error: Symbian SDK registry key not found" << std::endl; + } else { + devicesXmlPath += "/devices.xml"; + QFile devicesFile(devicesXmlPath); + if (devicesFile.open(QIODevice::ReadOnly)) { + + // 3. If the EPOCDEVICE environment variable is set and a corresponding + // entry is found in devices.xml, and its epocroot value points to an + // existent directory, it is returned. + // 4. If a device element marked as default is found in devices.xml and its + // epocroot value points to an existent directory, this is returned. + + const QString epocDeviceValue = qgetenv("EPOCDEVICE"); + bool epocDeviceFound = false; + + QXmlStreamReader xml(&devicesFile); + while (!xml.atEnd()) { + xml.readNext(); + if (xml.isStartElement() && xml.name() == "devices") { + if (xml.attributes().value("version") == "1.0") { + while (!(xml.isEndElement() && xml.name() == "devices") && !xml.atEnd()) { + xml.readNext(); + if (xml.isStartElement() && xml.name() == "device") { + const bool isDefault = xml.attributes().value("default") == "yes"; + const QString id = xml.attributes().value("id").toString(); + const QString name = xml.attributes().value("name").toString(); + const bool epocDeviceMatch = (id + ":" + name) == epocDeviceValue; + epocDeviceFound |= epocDeviceMatch; + + if((epocDeviceValue.isEmpty() && isDefault) || epocDeviceMatch) { + // Found a matching device + while (!(xml.isEndElement() && xml.name() == "device") && !xml.atEnd()) { + xml.readNext(); + if (xml.isStartElement() && xml.name() == "epocroot") { + epocRootValue = xml.readElementText(); + const QString deviceSource = epocDeviceValue.isEmpty() + ? "default device" + : "EPOCDEVICE (" + epocDeviceValue + ")"; + checkEpocRootExists(deviceSource); + } + } + + if (epocRootValue.isEmpty()) + xml.raiseError("No epocroot element found"); + } + } + } + } else { + xml.raiseError("Invalid 'devices' element version"); + } + } + } + if (xml.hasError()) { + std::cerr << "Error: \"" << xml.errorString() << "\" when parsing devices.xml" << std::endl; + } else { + if (epocRootValue.isEmpty()) { + if (!epocDeviceValue.isEmpty()) { + if (epocDeviceFound) { + std::cerr << "Error: missing or invalid epocroot attribute " + << "in device '" << epocDeviceValue << "'"; + } else { + std::cerr << "Error: no device matching EPOCDEVICE (" + << epocDeviceValue << ")"; + } + } else { + if (epocDeviceFound) { + std::cerr << "Error: missing or invalid epocroot attribute " + << "in default device"; + } else { + std::cerr << "Error: no default device"; + } + } + std::cerr << " found in devices.xml file." << std::endl; + } + } + } else { + std::cerr << "Error: could not open file " << devicesXmlPath << std::endl; + } + } + } + + if (epocRootValue.isEmpty()) { + // 5. An empty string is returned. + std::cerr << "Error: failed to find epoc root" << std::endl + << "Either" << std::endl + << " 1. Set EPOCROOT environment variable to a valid value" << std::endl + << " or 2. Ensure that the HKEY_LOCAL_MACHINE\\" SYMBIAN_SDKS_REG_SUBKEY + " registry key is set, and then" << std::endl + << " a. Set EPOCDEVICE environment variable to a valid device" << std::endl + << " or b. Specify a default device in the devices.xml file." << std::endl; + } else { + fixEpocRoot(epocRootValue); + } + } + + return epocRootValue; +} + diff --git a/tools/shared/symbian/epocroot.h b/tools/shared/symbian/epocroot.h new file mode 100644 index 0000000..9846485 --- /dev/null +++ b/tools/shared/symbian/epocroot.h @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the qmake application 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$ +** +****************************************************************************/ + +#ifndef SYMBIAN_EPOCROOT_H +#define SYMBIAN_EPOCROOT_H + +#include + +/** + * Determine the epoc root for the currently active SDK. + * + * The algorithm used is as follows: + * 1. If environment variable EPOCROOT is set and points to an existent + * directory, this is returned. + * 2. The location of devices.xml is specified by a registry key. If this + * file exists, it is parsed. + * 3. If the EPOCDEVICE environment variable is set and a corresponding + * entry is found in devices.xml, and its epocroot value points to an + * existent directory, it is returned. + * 4. If a device element marked as default is found in devices.xml and its + * epocroot value points to an existent directory, this is returned. + * 5. An empty string is returned. + * + * Any return value other than the empty string therefore is guaranteed to + * point to an existent directory. + */ +QString epocRoot(); + +#endif // EPOCROOT_H -- cgit v0.12 From ea34fbde76a0407dc4a9bb9f4a3140c4764ca6ba Mon Sep 17 00:00:00 2001 From: Gareth Stockwell Date: Wed, 10 Feb 2010 15:16:20 +0000 Subject: Removed duplicated implementation of readRegistryKeys from configure Configure now shares - at the source level - a single implementation of this function with qmake. Reviewed-by: Miikka Heikkinen --- tools/configure/configure.pro | 7 ++- tools/configure/environment.cpp | 121 +--------------------------------------- tools/configure/environment.h | 3 - 3 files changed, 6 insertions(+), 125 deletions(-) diff --git a/tools/configure/configure.pro b/tools/configure/configure.pro index 243183c..ca2ba84 100644 --- a/tools/configure/configure.pro +++ b/tools/configure/configure.pro @@ -27,6 +27,7 @@ INCPATH += $$QT_SOURCE_TREE/src/corelib/arch/generic \ $$QT_SOURCE_TREE/src/corelib/global \ $$QT_BUILD_TREE/include \ $$QT_BUILD_TREE/include/QtCore \ + $$QT_BUILD_TREE/tools/shared HEADERS = configureapp.h environment.h tools.h\ $$QT_SOURCE_TREE/src/corelib/tools/qbytearray.h \ @@ -58,7 +59,8 @@ HEADERS = configureapp.h environment.h tools.h\ $$QT_SOURCE_TREE/src/corelib/tools/qstring.h \ $$QT_SOURCE_TREE/src/corelib/tools/qstringlist.h \ $$QT_SOURCE_TREE/src/corelib/tools/qstringmatcher.h \ - $$QT_SOURCE_TREE/src/corelib/tools/qunicodetables_p.h + $$QT_SOURCE_TREE/src/corelib/tools/qunicodetables_p.h \ + $$QT_SOURCE_TREE/tools/shared/windows/registry.h SOURCES = main.cpp configureapp.cpp environment.cpp tools.cpp \ @@ -102,7 +104,8 @@ SOURCES = main.cpp configureapp.cpp environment.cpp tools.cpp \ $$QT_SOURCE_TREE/src/corelib/tools/qpoint.cpp \ $$QT_SOURCE_TREE/src/corelib/tools/qrect.cpp \ $$QT_SOURCE_TREE/src/corelib/kernel/qmetatype.cpp \ - $$QT_SOURCE_TREE/src/corelib/global/qmalloc.cpp + $$QT_SOURCE_TREE/src/corelib/global/qmalloc.cpp \ + $$QT_SOURCE_TREE/tools/shared/windows/registry.cpp win32:SOURCES += $$QT_SOURCE_TREE/src/corelib/io/qfsfileengine_win.cpp diff --git a/tools/configure/environment.cpp b/tools/configure/environment.cpp index af6f9e5..da86f5d 100644 --- a/tools/configure/environment.cpp +++ b/tools/configure/environment.cpp @@ -60,6 +60,7 @@ using namespace std; #include #endif +#include // from tools/shared QT_BEGIN_NAMESPACE @@ -97,126 +98,6 @@ CompilerInfo *Environment::compilerInfo(Compiler compiler) } /*! - Returns the path part of a registry key. - Ei. - For a key - "Software\\Microsoft\\VisualStudio\\8.0\\Setup\\VC\\ProductDir" - it returns - "Software\\Microsoft\\VisualStudio\\8.0\\Setup\\VC\\" -*/ -QString Environment::keyPath(const QString &rKey) -{ - int idx = rKey.lastIndexOf(QLatin1Char('\\')); - if (idx == -1) - return QString(); - return rKey.left(idx + 1); -} - -/*! - Returns the name part of a registry key. - Ei. - For a key - "Software\\Microsoft\\VisualStudio\\8.0\\Setup\\VC\\ProductDir" - it returns - "ProductDir" -*/ -QString Environment::keyName(const QString &rKey) -{ - int idx = rKey.lastIndexOf(QLatin1Char('\\')); - if (idx == -1) - return rKey; - - QString res(rKey.mid(idx + 1)); - if (res == "Default" || res == ".") - res = ""; - return res; -} - -/*! - Returns a registry keys value in string form. - If the registry key does not exist, or cannot be accessed, a - QString() is returned. -*/ -QString Environment::readRegistryKey(HKEY parentHandle, const QString &rSubkey) -{ -#ifndef Q_OS_WIN32 - return QString(); -#else - QString rSubkeyName = keyName(rSubkey); - QString rSubkeyPath = keyPath(rSubkey); - - HKEY handle = 0; - LONG res = RegOpenKeyEx(parentHandle, (wchar_t*)rSubkeyPath.utf16(), 0, KEY_READ, &handle); - if (res != ERROR_SUCCESS) - return QString(); - - // get the size and type of the value - DWORD dataType; - DWORD dataSize; - res = RegQueryValueEx(handle, (wchar_t*)rSubkeyName.utf16(), 0, &dataType, 0, &dataSize); - if (res != ERROR_SUCCESS) { - RegCloseKey(handle); - return QString(); - } - - // get the value - QByteArray data(dataSize, 0); - res = RegQueryValueEx(handle, (wchar_t*)rSubkeyName.utf16(), 0, 0, - reinterpret_cast(data.data()), &dataSize); - if (res != ERROR_SUCCESS) { - RegCloseKey(handle); - return QString(); - } - - QString result; - switch (dataType) { - case REG_EXPAND_SZ: - case REG_SZ: { - result = QString::fromWCharArray(((const wchar_t *)data.constData())); - break; - } - - case REG_MULTI_SZ: { - QStringList l; - int i = 0; - for (;;) { - QString s = QString::fromWCharArray((const wchar_t *)data.constData() + i); - i += s.length() + 1; - - if (s.isEmpty()) - break; - l.append(s); - } - result = l.join(", "); - break; - } - - case REG_NONE: - case REG_BINARY: { - result = QString::fromWCharArray((const wchar_t *)data.constData(), data.size() / 2); - break; - } - - case REG_DWORD_BIG_ENDIAN: - case REG_DWORD: { - Q_ASSERT(data.size() == sizeof(int)); - int i; - memcpy((char*)&i, data.constData(), sizeof(int)); - result = QString::number(i); - break; - } - - default: - qWarning("QSettings: unknown data %d type in windows registry", dataType); - break; - } - - RegCloseKey(handle); - return result; -#endif -} - -/*! Returns the qmakespec for the compiler detected on the system. */ QString Environment::detectQMakeSpec() diff --git a/tools/configure/environment.h b/tools/configure/environment.h index 2d0eafd..549dcfa 100644 --- a/tools/configure/environment.h +++ b/tools/configure/environment.h @@ -75,9 +75,6 @@ private: static Compiler detectedCompiler; static CompilerInfo *compilerInfo(Compiler compiler); - static QString keyPath(const QString &rKey); - static QString keyName(const QString &rKey); - static QString readRegistryKey(HKEY parentHandle, const QString &rSubkey); }; -- cgit v0.12 From 35f7b0803ea9f43981370aff0da4f4d06c248396 Mon Sep 17 00:00:00 2001 From: Gareth Stockwell Date: Wed, 10 Feb 2010 20:30:24 +0000 Subject: Added implementation of epocRoot() function to configure Exposing epocRoot() to the configure application allows it to determine the location of the currently active Symbian SDK, so that support for optional SDK features can be checked. Reviewed-by: Miikka Heikkinen --- src/corelib/xml/qxmlstream_p.h | 2 +- tools/configure/configure.pro | 10 ++++++++-- tools/configure/environment.cpp | 7 +++++++ tools/configure/environment.h | 2 ++ 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/corelib/xml/qxmlstream_p.h b/src/corelib/xml/qxmlstream_p.h index 6b911d2..ac421cf 100644 --- a/src/corelib/xml/qxmlstream_p.h +++ b/src/corelib/xml/qxmlstream_p.h @@ -54,7 +54,7 @@ #ifndef QXMLSTREAM_P_H #define QXMLSTREAM_P_H -#if defined(Q_OS_VXWORKS) && defined(ERROR) +#if defined(ERROR) # undef ERROR #endif diff --git a/tools/configure/configure.pro b/tools/configure/configure.pro index ca2ba84..91de7c2 100644 --- a/tools/configure/configure.pro +++ b/tools/configure/configure.pro @@ -3,8 +3,8 @@ DESTDIR = ../.. CONFIG += console flat CONFIG -= moc qt -DEFINES = UNICODE QT_NODLL QT_NO_CODECS QT_NO_TEXTCODEC QT_NO_UNICODETABLES QT_LITE_COMPONENT QT_NO_STL QT_NO_COMPRESS QT_BUILD_QMAKE QT_NO_THREAD QT_NO_QOBJECT _CRT_SECURE_NO_DEPRECATE - +DEFINES = UNICODE QT_NODLL QT_NO_CODECS QT_NO_TEXTCODEC QT_NO_UNICODETABLES QT_LITE_COMPONENT QT_NO_STL QT_NO_COMPRESS QT_NO_THREAD QT_NO_QOBJECT _CRT_SECURE_NO_DEPRECATE +DEFINES += QT_BOOTSTRAPPED win32 : LIBS += -lole32 -ladvapi32 win32-msvc.net | win32-msvc2* : QMAKE_CXXFLAGS += /EHsc @@ -60,6 +60,9 @@ HEADERS = configureapp.h environment.h tools.h\ $$QT_SOURCE_TREE/src/corelib/tools/qstringlist.h \ $$QT_SOURCE_TREE/src/corelib/tools/qstringmatcher.h \ $$QT_SOURCE_TREE/src/corelib/tools/qunicodetables_p.h \ + $$QT_SOURCE_TREE/src/corelib/xml/qxmlstream.h \ + $$QT_SOURCE_TREE/src/corelib/xml/qxmlutils_p.h \ + $$QT_SOURCE_TREE/tools/shared/symbian/epocroot.h \ $$QT_SOURCE_TREE/tools/shared/windows/registry.h @@ -105,6 +108,9 @@ SOURCES = main.cpp configureapp.cpp environment.cpp tools.cpp \ $$QT_SOURCE_TREE/src/corelib/tools/qrect.cpp \ $$QT_SOURCE_TREE/src/corelib/kernel/qmetatype.cpp \ $$QT_SOURCE_TREE/src/corelib/global/qmalloc.cpp \ + $$QT_SOURCE_TREE/src/corelib/xml/qxmlstream.cpp \ + $$QT_SOURCE_TREE/src/corelib/xml/qxmlutils.cpp \ + $$QT_SOURCE_TREE/tools/shared/symbian/epocroot.cpp \ $$QT_SOURCE_TREE/tools/shared/windows/registry.cpp win32:SOURCES += $$QT_SOURCE_TREE/src/corelib/io/qfsfileengine_win.cpp diff --git a/tools/configure/environment.cpp b/tools/configure/environment.cpp index da86f5d..e93f9a0 100644 --- a/tools/configure/environment.cpp +++ b/tools/configure/environment.cpp @@ -60,6 +60,7 @@ using namespace std; #include #endif +#include // from tools/shared #include // from tools/shared QT_BEGIN_NAMESPACE @@ -460,4 +461,10 @@ bool Environment::rmdir(const QString &name) return result; } +QString Environment::symbianEpocRoot() +{ + // Call function defined in tools/shared/symbian/epocroot.h + return ::epocRoot(); +} + QT_END_NAMESPACE diff --git a/tools/configure/environment.h b/tools/configure/environment.h index 549dcfa..b1cbe3a 100644 --- a/tools/configure/environment.h +++ b/tools/configure/environment.h @@ -71,6 +71,8 @@ public: static bool cpdir(const QString &srcDir, const QString &destDir); static bool rmdir(const QString &name); + static QString symbianEpocRoot(); + private: static Compiler detectedCompiler; -- cgit v0.12 From b76e3e5f4e9cad5c2e7331031e5a44868616105e Mon Sep 17 00:00:00 2001 From: Gareth Stockwell Date: Wed, 10 Feb 2010 20:44:10 +0000 Subject: Modified configure to detect SDK support for Symbian audio backend This version of configure.exe was compiled with MSVC 9.0. Reviewed-by: Miikka Heikkinen --- configure.exe | Bin 1179136 -> 1008128 bytes tools/configure/configureapp.cpp | 50 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/configure.exe b/configure.exe index 09f4ef2..9974236 100755 Binary files a/configure.exe and b/configure.exe differ diff --git a/tools/configure/configureapp.cpp b/tools/configure/configureapp.cpp index 9e0cb70..d521276 100644 --- a/tools/configure/configureapp.cpp +++ b/tools/configure/configureapp.cpp @@ -247,7 +247,7 @@ Configure::Configure( int& argc, char** argv ) dictionary[ "PHONON" ] = "auto"; dictionary[ "PHONON_BACKEND" ] = "yes"; dictionary[ "MULTIMEDIA" ] = "yes"; - dictionary[ "AUDIO_BACKEND" ] = "yes"; + dictionary[ "AUDIO_BACKEND" ] = "auto"; dictionary[ "DIRECTSHOW" ] = "no"; dictionary[ "WEBKIT" ] = "auto"; dictionary[ "DECLARATIVE" ] = "auto"; @@ -2065,6 +2065,52 @@ bool Configure::checkAvailability(const QString &part) available = (dictionary.value("QMAKESPEC") == "win32-msvc2005") || (dictionary.value("QMAKESPEC") == "win32-msvc2008") || (dictionary.value("QMAKESPEC") == "win32-g++"); } else if (part == "DECLARATIVE") { available = QFile::exists(sourcePath + "/src/declarative/qml/qmlcomponent.h"); + } else if (part == "AUDIO_BACKEND") { + available = true; + if (dictionary.contains("XQMAKESPEC") && dictionary["XQMAKESPEC"].startsWith("symbian")) { + QString epocRoot = Environment::symbianEpocRoot(); + const QDir epocRootDir(epocRoot); + if (epocRootDir.exists()) { + QStringList paths; + paths << "epoc32/release/armv5/lib/mmfdevsound.dso" + << "epoc32/release/armv5/lib/mmfdevsound.lib" + << "epoc32/release/winscw/udeb/mmfdevsound.dll" + << "epoc32/release/winscw/udeb/mmfdevsound.lib" + << "epoc32/include/mmf/server/sounddevice.h"; + + QStringList::iterator i = paths.begin(); + while (i != paths.end()) { + const QString &path = epocRoot + *i; + if (QFile::exists(path)) + i = paths.erase(i); + else + ++i; + } + + available = (paths.size() == 0); + if (!available) { + if (epocRoot.isNull() || epocRoot == "") + epocRoot = ""; + cout << endl + << "The QtMultimedia audio backend will not be built because required" << endl + << "support for CMMFDevSound was not found in the SDK." << endl + << "The SDK which was examined was located at the following path:" << endl + << " " << epocRoot << endl + << "The following required files were missing from the SDK:" << endl; + QString path; + foreach (path, paths) + cout << " " << path << endl; + cout << endl; + } + } else { + cout << endl + << "The SDK root was determined to be '" << epocRoot << "'." << endl + << "This directory was not found, so the SDK could not be checked for" << endl + << "CMMFDevSound support. The QtMultimedia audio backend will therefore" << endl + << "not be built." << endl << endl; + available = false; + } + } } return available; @@ -2153,6 +2199,8 @@ void Configure::autoDetection() dictionary["WEBKIT"] = checkAvailability("WEBKIT") ? "yes" : "no"; if (dictionary["DECLARATIVE"] == "auto") dictionary["DECLARATIVE"] = checkAvailability("DECLARATIVE") ? "yes" : "no"; + if (dictionary["AUDIO_BACKEND"] == "auto") + dictionary["AUDIO_BACKEND"] = checkAvailability("AUDIO_BACKEND") ? "yes" : "no"; // Qt/WinCE remote test application if (dictionary["CETEST"] == "auto") -- cgit v0.12 From 28610950d2efb0b543ede40512f6172c37c78698 Mon Sep 17 00:00:00 2001 From: Gareth Stockwell Date: Thu, 18 Feb 2010 14:10:03 +0000 Subject: Symbian backend for QtMultimedia audio Task-number: QT-567 --- src/plugins/audio/audio.pro | 8 +- src/plugins/audio/symbian/main.cpp | 121 ++++ src/plugins/audio/symbian/symbian.pro | 31 + src/plugins/audio/symbian/symbianaudio.h | 76 +++ .../audio/symbian/symbianaudiodeviceinfo.cpp | 191 ++++++ src/plugins/audio/symbian/symbianaudiodeviceinfo.h | 94 +++ src/plugins/audio/symbian/symbianaudioinput.cpp | 595 ++++++++++++++++++ src/plugins/audio/symbian/symbianaudioinput.h | 177 ++++++ src/plugins/audio/symbian/symbianaudiooutput.cpp | 697 +++++++++++++++++++++ src/plugins/audio/symbian/symbianaudiooutput.h | 199 ++++++ src/plugins/audio/symbian/symbianaudioutils.cpp | 395 ++++++++++++ src/plugins/audio/symbian/symbianaudioutils.h | 125 ++++ src/s60installs/qt.iby | 6 + src/s60installs/s60installs.pro | 6 + 14 files changed, 2720 insertions(+), 1 deletion(-) create mode 100644 src/plugins/audio/symbian/main.cpp create mode 100644 src/plugins/audio/symbian/symbian.pro create mode 100644 src/plugins/audio/symbian/symbianaudio.h create mode 100644 src/plugins/audio/symbian/symbianaudiodeviceinfo.cpp create mode 100644 src/plugins/audio/symbian/symbianaudiodeviceinfo.h create mode 100644 src/plugins/audio/symbian/symbianaudioinput.cpp create mode 100644 src/plugins/audio/symbian/symbianaudioinput.h create mode 100644 src/plugins/audio/symbian/symbianaudiooutput.cpp create mode 100644 src/plugins/audio/symbian/symbianaudiooutput.h create mode 100644 src/plugins/audio/symbian/symbianaudioutils.cpp create mode 100644 src/plugins/audio/symbian/symbianaudioutils.h diff --git a/src/plugins/audio/audio.pro b/src/plugins/audio/audio.pro index e93b369..5f75a8d 100644 --- a/src/plugins/audio/audio.pro +++ b/src/plugins/audio/audio.pro @@ -1,3 +1,9 @@ TEMPLATE = subdirs +SUBDIRS = + +contains(QT_CONFIG, audio-backend) { + symbian { + SUBDIRS += symbian + } +} -#SUBDIRS += ossaudio diff --git a/src/plugins/audio/symbian/main.cpp b/src/plugins/audio/symbian/main.cpp new file mode 100644 index 0000000..377944b --- /dev/null +++ b/src/plugins/audio/symbian/main.cpp @@ -0,0 +1,121 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the plugins 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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include + +#include +#include +#include +#include + +#include "symbianaudiodeviceinfo.h" +#include "symbianaudioinput.h" +#include "symbianaudiooutput.h" + +QT_BEGIN_NAMESPACE + +class SymbianAudioPlugin : public QAudioEnginePlugin +{ +public: + SymbianAudioPlugin(QObject *parent = 0); + ~SymbianAudioPlugin(); + + QStringList keys() const; + + QList availableDevices(QAudio::Mode) const; + QAbstractAudioInput* createInput(const QByteArray& device, + const QAudioFormat& format = QAudioFormat()); + QAbstractAudioOutput* createOutput(const QByteArray& device, + const QAudioFormat& format = QAudioFormat()); + QAbstractAudioDeviceInfo* createDeviceInfo(const QByteArray& device, + QAudio::Mode mode); +}; + +SymbianAudioPlugin::SymbianAudioPlugin(QObject *parent) + : QAudioEnginePlugin(parent) +{ + +} + +SymbianAudioPlugin::~SymbianAudioPlugin() +{ + +} + +QStringList SymbianAudioPlugin::keys() const +{ + QStringList keys(QLatin1String("default")); + keys << QLatin1String("default"); + return keys; +} + +QList SymbianAudioPlugin::availableDevices(QAudio::Mode mode) const +{ + Q_UNUSED(mode) + QList devices; + devices.append("default"); + return devices; +} + +QAbstractAudioInput* SymbianAudioPlugin::createInput( + const QByteArray &device, const QAudioFormat &format) +{ + return new SymbianAudioInput(device, format); +} + +QAbstractAudioOutput* SymbianAudioPlugin::createOutput( + const QByteArray &device, const QAudioFormat &format) +{ + return new SymbianAudioOutput(device, format); +} + +QAbstractAudioDeviceInfo* SymbianAudioPlugin::createDeviceInfo( + const QByteArray& device, QAudio::Mode mode) +{ + return new SymbianAudioDeviceInfo(device, mode); +} + +Q_EXPORT_STATIC_PLUGIN(SymbianAudioPlugin) +Q_EXPORT_PLUGIN2(qaudio, SymbianAudioPlugin) + +QT_END_NAMESPACE + diff --git a/src/plugins/audio/symbian/symbian.pro b/src/plugins/audio/symbian/symbian.pro new file mode 100644 index 0000000..7355daa --- /dev/null +++ b/src/plugins/audio/symbian/symbian.pro @@ -0,0 +1,31 @@ +QT += multimedia +TARGET = qaudio + +# Paths to DevSound headers +INCLUDEPATH += /epoc32/include/mmf/common +INCLUDEPATH += /epoc32/include/mmf/server + +HEADERS += \ + symbianaudio.h \ + symbianaudiodeviceinfo.h \ + symbianaudioinput.h \ + symbianaudiooutput.h \ + symbianaudioutils.h + +SOURCES += \ + main.cpp \ + symbianaudiodeviceinfo.cpp \ + symbianaudioinput.cpp \ + symbianaudiooutput.cpp \ + symbianaudioutils.cpp + +LIBS += -lmmfdevsound + +QTDIR_build:DESTDIR = $$QT_BUILD_TREE/plugins/audio +target.path = $$[QT_INSTALL_PLUGINS]/audio +INSTALLS += target + +include(../../qpluginbase.pri) + +TARGET.UID3 = 0x2001E630 + diff --git a/src/plugins/audio/symbian/symbianaudio.h b/src/plugins/audio/symbian/symbianaudio.h new file mode 100644 index 0000000..527aa55 --- /dev/null +++ b/src/plugins/audio/symbian/symbianaudio.h @@ -0,0 +1,76 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the plugins 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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef SYMBIANAUDIO_H +#define SYMBIANAUDIO_H + +#include + +QT_BEGIN_NAMESPACE + +namespace SymbianAudio { + +/** + * Default values used by audio input and output classes, when underlying + * DevSound instance has not yet been created. + */ + +const int DefaultBufferSize = 4096; // bytes +const int DefaultNotifyInterval = 1000; // ms + +/** + * Enumeration used to track state of internal DevSound instances. + * Values are translated to the corresponding QAudio::State values by + * SymbianAudio::Utils::stateNativeToQt. + */ +enum State { + ClosedState + , InitializingState + , ActiveState + , IdleState + , SuspendedState +}; + +} // namespace SymbianAudio + +QT_END_NAMESPACE + +#endif diff --git a/src/plugins/audio/symbian/symbianaudiodeviceinfo.cpp b/src/plugins/audio/symbian/symbianaudiodeviceinfo.cpp new file mode 100644 index 0000000..b8d59de --- /dev/null +++ b/src/plugins/audio/symbian/symbianaudiodeviceinfo.cpp @@ -0,0 +1,191 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the plugins 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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "symbianaudiodeviceinfo.h" +#include "symbianaudioutils.h" + +QT_BEGIN_NAMESPACE + +SymbianAudioDeviceInfo::SymbianAudioDeviceInfo(QByteArray device, + QAudio::Mode mode) + : m_deviceName(device) + , m_mode(mode) + , m_updated(false) +{ + QT_TRAP_THROWING(m_devsound.reset(CMMFDevSound::NewL())); +} + +SymbianAudioDeviceInfo::~SymbianAudioDeviceInfo() +{ + +} + +QAudioFormat SymbianAudioDeviceInfo::preferredFormat() const +{ + QAudioFormat format; + switch (m_mode) { + case QAudio::AudioOutput: + format.setFrequency(44100); + format.setChannels(2); + format.setSampleSize(16); + format.setByteOrder(QAudioFormat::LittleEndian); + format.setSampleType(QAudioFormat::SignedInt); + format.setCodec(QLatin1String("audio/pcm")); + break; + + case QAudio::AudioInput: + format.setFrequency(8000); + format.setChannels(1); + format.setSampleSize(16); + format.setByteOrder(QAudioFormat::LittleEndian); + format.setSampleType(QAudioFormat::SignedInt); + format.setCodec(QLatin1String("audio/pcm")); + break; + + default: + Q_ASSERT_X(false, Q_FUNC_INFO, "Invalid mode"); + } + + if (!isFormatSupported(format)) { + if (m_frequencies.size()) + format.setFrequency(m_frequencies[0]); + if (m_channels.size()) + format.setChannels(m_channels[0]); + if (m_sampleSizes.size()) + format.setSampleSize(m_sampleSizes[0]); + if (m_byteOrders.size()) + format.setByteOrder(m_byteOrders[0]); + if (m_sampleTypes.size()) + format.setSampleType(m_sampleTypes[0]); + } + + return format; +} + +bool SymbianAudioDeviceInfo::isFormatSupported( + const QAudioFormat &format) const +{ + getSupportedFormats(); + const bool supported = + m_codecs.contains(format.codec()) + && m_frequencies.contains(format.frequency()) + && m_channels.contains(format.channels()) + && m_sampleSizes.contains(format.sampleSize()) + && m_byteOrders.contains(format.byteOrder()) + && m_sampleTypes.contains(format.sampleType()); + + return supported; +} + +QAudioFormat SymbianAudioDeviceInfo::nearestFormat(const QAudioFormat &format) const +{ + if (isFormatSupported(format)) + return format; + else + return preferredFormat(); +} + +QString SymbianAudioDeviceInfo::deviceName() const +{ + return m_deviceName; +} + +QStringList SymbianAudioDeviceInfo::codecList() +{ + getSupportedFormats(); + return m_codecs; +} + +QList SymbianAudioDeviceInfo::frequencyList() +{ + getSupportedFormats(); + return m_frequencies; +} + +QList SymbianAudioDeviceInfo::channelsList() +{ + getSupportedFormats(); + return m_channels; +} + +QList SymbianAudioDeviceInfo::sampleSizeList() +{ + getSupportedFormats(); + return m_sampleSizes; +} + +QList SymbianAudioDeviceInfo::byteOrderList() +{ + getSupportedFormats(); + return m_byteOrders; +} + +QList SymbianAudioDeviceInfo::sampleTypeList() +{ + getSupportedFormats(); + return m_sampleTypes; +} + +QList SymbianAudioDeviceInfo::deviceList(QAudio::Mode mode) +{ + Q_UNUSED(mode) + QList devices; + devices.append("default"); + return devices; +} + +void SymbianAudioDeviceInfo::getSupportedFormats() const +{ + if (!m_updated) { + QScopedPointer caps( + new SymbianAudio::DevSoundCapabilities(*m_devsound, m_mode)); + + SymbianAudio::Utils::capabilitiesNativeToQt(*caps, + m_frequencies, m_channels, m_sampleSizes, + m_byteOrders, m_sampleTypes); + + m_codecs.append(QLatin1String("audio/pcm")); + + m_updated = true; + } +} + +QT_END_NAMESPACE diff --git a/src/plugins/audio/symbian/symbianaudiodeviceinfo.h b/src/plugins/audio/symbian/symbianaudiodeviceinfo.h new file mode 100644 index 0000000..1df6afb --- /dev/null +++ b/src/plugins/audio/symbian/symbianaudiodeviceinfo.h @@ -0,0 +1,94 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the plugins 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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef SYMBIANAUDIODEVICEINFO_H +#define SYMBIANAUDIODEVICEINFO_H + +#include +#include + +QT_BEGIN_NAMESPACE + +class SymbianAudioDeviceInfo + : public QAbstractAudioDeviceInfo +{ + Q_OBJECT + +public: + SymbianAudioDeviceInfo(QByteArray device, QAudio::Mode mode); + ~SymbianAudioDeviceInfo(); + + // QAbstractAudioDeviceInfo + QAudioFormat preferredFormat() const; + bool isFormatSupported(const QAudioFormat &format) const; + QAudioFormat nearestFormat(const QAudioFormat &format) const; + QString deviceName() const; + QStringList codecList(); + QList frequencyList(); + QList channelsList(); + QList sampleSizeList(); + QList byteOrderList(); + QList sampleTypeList(); + QList deviceList(QAudio::Mode); + +private: + void getSupportedFormats() const; + +private: + QScopedPointer m_devsound; + + QString m_deviceName; + QAudio::Mode m_mode; + + // Mutable to allow lazy initialization when called from const-qualified + // public functions (isFormatSupported, nearestFormat) + mutable bool m_updated; + mutable QStringList m_codecs; + mutable QList m_frequencies; + mutable QList m_channels; + mutable QList m_sampleSizes; + mutable QList m_byteOrders; + mutable QList m_sampleTypes; +}; + +QT_END_NAMESPACE + +#endif diff --git a/src/plugins/audio/symbian/symbianaudioinput.cpp b/src/plugins/audio/symbian/symbianaudioinput.cpp new file mode 100644 index 0000000..c1a6299 --- /dev/null +++ b/src/plugins/audio/symbian/symbianaudioinput.cpp @@ -0,0 +1,595 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the plugins 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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "symbianaudioinput.h" +#include "symbianaudioutils.h" + +QT_BEGIN_NAMESPACE + +//----------------------------------------------------------------------------- +// Constants +//----------------------------------------------------------------------------- + +const int PushInterval = 50; // ms + + +//----------------------------------------------------------------------------- +// Private class +//----------------------------------------------------------------------------- + +SymbianAudioInputPrivate::SymbianAudioInputPrivate( + SymbianAudioInput *audioDevice) + : m_audioDevice(audioDevice) +{ + +} + +SymbianAudioInputPrivate::~SymbianAudioInputPrivate() +{ + +} + +qint64 SymbianAudioInputPrivate::readData(char *data, qint64 len) +{ + qint64 totalRead = 0; + + if (m_audioDevice->state() == QAudio::ActiveState || + m_audioDevice->state() == QAudio::IdleState) { + + while (totalRead < len) { + const qint64 read = m_audioDevice->read(data + totalRead, + len - totalRead); + if (read > 0) + totalRead += read; + else + break; + } + } + + return totalRead; +} + +qint64 SymbianAudioInputPrivate::writeData(const char *data, qint64 len) +{ + Q_UNUSED(data) + Q_UNUSED(len) + return 0; +} + +void SymbianAudioInputPrivate::dataReady() +{ + emit readyRead(); +} + + +//----------------------------------------------------------------------------- +// Public functions +//----------------------------------------------------------------------------- + +SymbianAudioInput::SymbianAudioInput(const QByteArray &device, + const QAudioFormat &format) + : m_device(device) + , m_format(format) + , m_clientBufferSize(SymbianAudio::DefaultBufferSize) + , m_notifyInterval(SymbianAudio::DefaultNotifyInterval) + , m_notifyTimer(new QTimer(this)) + , m_error(QAudio::NoError) + , m_internalState(SymbianAudio::ClosedState) + , m_externalState(QAudio::StoppedState) + , m_pullMode(false) + , m_sink(0) + , m_pullTimer(new QTimer(this)) + , m_devSoundBuffer(0) + , m_devSoundBufferSize(0) + , m_totalBytesReady(0) + , m_devSoundBufferPos(0) + , m_totalSamplesRecorded(0) +{ + connect(m_notifyTimer.data(), SIGNAL(timeout()), this, SIGNAL(notify())); + + SymbianAudio::Utils::formatQtToNative(m_format, m_nativeFourCC, + m_nativeFormat); + + m_pullTimer->setInterval(PushInterval); + connect(m_pullTimer.data(), SIGNAL(timeout()), this, SLOT(pullData())); +} + +SymbianAudioInput::~SymbianAudioInput() +{ + close(); +} + +QIODevice* SymbianAudioInput::start(QIODevice *device) +{ + stop(); + + open(); + if (SymbianAudio::ClosedState != m_internalState) { + if (device) { + m_pullMode = true; + m_sink = device; + } else { + m_sink = new SymbianAudioInputPrivate(this); + m_sink->open(QIODevice::ReadOnly | QIODevice::Unbuffered); + } + + m_elapsed.restart(); + } + + return m_sink; +} + +void SymbianAudioInput::stop() +{ + close(); +} + +void SymbianAudioInput::reset() +{ + m_totalSamplesRecorded += getSamplesRecorded(); + m_devSound->Stop(); + startRecording(); +} + +void SymbianAudioInput::suspend() +{ + if (SymbianAudio::ActiveState == m_internalState + || SymbianAudio::IdleState == m_internalState) { + m_notifyTimer->stop(); + m_pullTimer->stop(); + m_devSound->Pause(); + const qint64 samplesRecorded = getSamplesRecorded(); + m_totalSamplesRecorded += samplesRecorded; + + if (m_devSoundBuffer) { + m_devSoundBufferQ.append(m_devSoundBuffer); + m_devSoundBuffer = 0; + } + + setState(SymbianAudio::SuspendedState); + } +} + +void SymbianAudioInput::resume() +{ + if (SymbianAudio::SuspendedState == m_internalState) + startDataTransfer(); +} + +int SymbianAudioInput::bytesReady() const +{ + Q_ASSERT(m_devSoundBufferPos <= m_totalBytesReady); + return m_totalBytesReady - m_devSoundBufferPos; +} + +int SymbianAudioInput::periodSize() const +{ + return bufferSize(); +} + +void SymbianAudioInput::setBufferSize(int value) +{ + // Note that DevSound does not allow its client to specify the buffer size. + // This functionality is available via custom interfaces, but since these + // cannot be guaranteed to work across all DevSound implementations, we + // do not use them here. + // In order to comply with the expected bevahiour of QAudioInput, we store + // the value and return it from bufferSize(), but the underlying DevSound + // buffer size remains unchanged. + if (value > 0) + m_clientBufferSize = value; +} + +int SymbianAudioInput::bufferSize() const +{ + return m_devSoundBufferSize ? m_devSoundBufferSize : m_clientBufferSize; +} + +void SymbianAudioInput::setNotifyInterval(int ms) +{ + if (ms > 0) { + const int oldNotifyInterval = m_notifyInterval; + m_notifyInterval = ms; + if (m_notifyTimer->isActive() && ms != oldNotifyInterval) + m_notifyTimer->start(m_notifyInterval); + } +} + +int SymbianAudioInput::notifyInterval() const +{ + return m_notifyInterval; +} + +qint64 SymbianAudioInput::processedUSecs() const +{ + int samplesPlayed = 0; + if (m_devSound && SymbianAudio::SuspendedState != m_internalState) + samplesPlayed = getSamplesRecorded(); + + // Protect against division by zero + Q_ASSERT_X(m_format.frequency() > 0, Q_FUNC_INFO, "Invalid frequency"); + + const qint64 result = qint64(1000000) * + (samplesPlayed + m_totalSamplesRecorded) + / m_format.frequency(); + + return result; +} + +qint64 SymbianAudioInput::elapsedUSecs() const +{ + const qint64 result = (QAudio::StoppedState == state()) ? + 0 : m_elapsed.elapsed() * 1000; + return result; +} + +QAudio::Error SymbianAudioInput::error() const +{ + return m_error; +} + +QAudio::State SymbianAudioInput::state() const +{ + return m_externalState; +} + +QAudioFormat SymbianAudioInput::format() const +{ + return m_format; +} + +//----------------------------------------------------------------------------- +// MDevSoundObserver implementation +//----------------------------------------------------------------------------- + +void SymbianAudioInput::InitializeComplete(TInt aError) +{ + Q_ASSERT_X(SymbianAudio::InitializingState == m_internalState, + Q_FUNC_INFO, "Invalid state"); + + if (KErrNone == aError) + startRecording(); +} + +void SymbianAudioInput::ToneFinished(TInt aError) +{ + Q_UNUSED(aError) + // This class doesn't use DevSound's tone playback functions, so should + // never receive this callback. + Q_ASSERT_X(false, Q_FUNC_INFO, "Unexpected callback"); +} + +void SymbianAudioInput::BufferToBeFilled(CMMFBuffer *aBuffer) +{ + Q_UNUSED(aBuffer) + // This class doesn't use DevSound in play mode, so should never receive + // this callback. + Q_ASSERT_X(false, Q_FUNC_INFO, "Unexpected callback"); +} + +void SymbianAudioInput::PlayError(TInt aError) +{ + Q_UNUSED(aError) + // This class doesn't use DevSound in play mode, so should never receive + // this callback. + Q_ASSERT_X(false, Q_FUNC_INFO, "Unexpected callback"); +} + +void SymbianAudioInput::BufferToBeEmptied(CMMFBuffer *aBuffer) +{ + // Following receipt of this callback, DevSound should not provide another + // buffer until we have returned the current one. + Q_ASSERT_X(!m_devSoundBuffer, Q_FUNC_INFO, "Buffer already held"); + + CMMFDataBuffer *const buffer = static_cast(aBuffer); + + if (!m_devSoundBufferSize) + m_devSoundBufferSize = buffer->Data().MaxLength(); + + m_totalBytesReady += buffer->Data().Length(); + + if (SymbianAudio::SuspendedState == m_internalState) { + m_devSoundBufferQ.append(buffer); + } else { + // Will be returned to DevSound by bufferEmptied(). + m_devSoundBuffer = buffer; + m_devSoundBufferPos = 0; + + if (bytesReady() && !m_pullMode) + pushData(); + } +} + +void SymbianAudioInput::RecordError(TInt aError) +{ + Q_UNUSED(aError) + setError(QAudio::IOError); +} + +void SymbianAudioInput::ConvertError(TInt aError) +{ + Q_UNUSED(aError) + // This class doesn't use DevSound's format conversion functions, so + // should never receive this callback. + Q_ASSERT_X(false, Q_FUNC_INFO, "Unexpected callback"); +} + +void SymbianAudioInput::DeviceMessage(TUid aMessageType, const TDesC8 &aMsg) +{ + Q_UNUSED(aMessageType) + Q_UNUSED(aMsg) + // Ignore this callback. +} + +//----------------------------------------------------------------------------- +// Private functions +//----------------------------------------------------------------------------- + +void SymbianAudioInput::open() +{ + Q_ASSERT_X(SymbianAudio::ClosedState == m_internalState, + Q_FUNC_INFO, "DevSound already opened"); + + QT_TRAP_THROWING( m_devSound.reset(CMMFDevSound::NewL()) ) + + QScopedPointer caps( + new SymbianAudio::DevSoundCapabilities(*m_devSound, QAudio::AudioInput)); + + int err = SymbianAudio::Utils::isFormatSupported(m_format, *caps) ? + KErrNone : KErrNotSupported; + + if (KErrNone == err) { + setState(SymbianAudio::InitializingState); + TRAP(err, m_devSound->InitializeL(*this, m_nativeFourCC, + EMMFStateRecording)); + } + + if (KErrNone != err) { + setError(QAudio::OpenError); + m_devSound.reset(); + } +} + +void SymbianAudioInput::startRecording() +{ + const int samplesRecorded = m_devSound->SamplesRecorded(); + Q_ASSERT(samplesRecorded == 0); + + TRAPD(err, startDevSoundL()); + if (KErrNone == err) { + startDataTransfer(); + } else { + setError(QAudio::OpenError); + close(); + } +} + +void SymbianAudioInput::startDevSoundL() +{ + TMMFCapabilities nativeFormat = m_devSound->Config(); + m_nativeFormat.iBufferSize = nativeFormat.iBufferSize; + m_devSound->SetConfigL(m_nativeFormat); + m_devSound->RecordInitL(); +} + +void SymbianAudioInput::startDataTransfer() +{ + m_notifyTimer->start(m_notifyInterval); + + if (m_pullMode) + m_pullTimer->start(); + + if (bytesReady()) { + setState(SymbianAudio::ActiveState); + if (!m_pullMode) + pushData(); + } else { + if (SymbianAudio::SuspendedState == m_internalState) + setState(SymbianAudio::ActiveState); + else + setState(SymbianAudio::IdleState); + } +} + +CMMFDataBuffer* SymbianAudioInput::currentBuffer() const +{ + CMMFDataBuffer *result = m_devSoundBuffer; + if (!result && !m_devSoundBufferQ.empty()) + result = m_devSoundBufferQ.front(); + return result; +} + +void SymbianAudioInput::pushData() +{ + Q_ASSERT_X(bytesReady(), Q_FUNC_INFO, "No data available"); + Q_ASSERT_X(!m_pullMode, Q_FUNC_INFO, "pushData called when in pull mode"); + qobject_cast(m_sink)->dataReady(); +} + +qint64 SymbianAudioInput::read(char *data, qint64 len) +{ + // SymbianAudioInputPrivate is ready to read data + + Q_ASSERT_X(!m_pullMode, Q_FUNC_INFO, + "read called when in pull mode"); + + qint64 bytesRead = 0; + + CMMFDataBuffer *buffer = 0; + while ((buffer = currentBuffer()) && (bytesRead < len)) { + if (SymbianAudio::IdleState == m_internalState) + setState(SymbianAudio::ActiveState); + + TDesC8 &inputBuffer = buffer->Data(); + + const qint64 inputBytes = bytesReady(); + const qint64 outputBytes = len - bytesRead; + const qint64 copyBytes = outputBytes < inputBytes ? + outputBytes : inputBytes; + + memcpy(data, inputBuffer.Ptr() + m_devSoundBufferPos, copyBytes); + + m_devSoundBufferPos += copyBytes; + data += copyBytes; + bytesRead += copyBytes; + + if (!bytesReady()) + bufferEmptied(); + } + + return bytesRead; +} + +void SymbianAudioInput::pullData() +{ + Q_ASSERT_X(m_pullMode, Q_FUNC_INFO, + "pullData called when in push mode"); + + CMMFDataBuffer *buffer = 0; + while (buffer = currentBuffer()) { + if (SymbianAudio::IdleState == m_internalState) + setState(SymbianAudio::ActiveState); + + TDesC8 &inputBuffer = buffer->Data(); + + const qint64 inputBytes = bytesReady(); + const qint64 bytesPushed = m_sink->write( + (char*)inputBuffer.Ptr() + m_devSoundBufferPos, inputBytes); + + m_devSoundBufferPos += bytesPushed; + + if (!bytesReady()) + bufferEmptied(); + + if (!bytesPushed) + break; + } +} + +void SymbianAudioInput::bufferEmptied() +{ + m_devSoundBufferPos = 0; + + if (m_devSoundBuffer) { + m_totalBytesReady -= m_devSoundBuffer->Data().Length(); + m_devSoundBuffer = 0; + m_devSound->RecordData(); + } else { + Q_ASSERT(!m_devSoundBufferQ.empty()); + m_totalBytesReady -= m_devSoundBufferQ.front()->Data().Length(); + m_devSoundBufferQ.erase(m_devSoundBufferQ.begin()); + + // If the queue has been emptied, resume transfer from the hardware + if (m_devSoundBufferQ.empty()) + m_devSound->RecordInitL(); + } + + Q_ASSERT(m_totalBytesReady >= 0); +} + +void SymbianAudioInput::close() +{ + m_notifyTimer->stop(); + m_pullTimer->stop(); + + m_error = QAudio::NoError; + + if (m_devSound) + m_devSound->Stop(); + m_devSound.reset(); + m_devSoundBuffer = 0; + m_devSoundBufferSize = 0; + m_totalBytesReady = 0; + + if (!m_pullMode) // m_sink is owned + delete m_sink; + m_pullMode = false; + m_sink = 0; + + m_devSoundBufferQ.clear(); + m_devSoundBufferPos = 0; + m_totalSamplesRecorded = 0; + + setState(SymbianAudio::ClosedState); +} + +qint64 SymbianAudioInput::getSamplesRecorded() const +{ + qint64 result = 0; + if (m_devSound) + result = qint64(m_devSound->SamplesRecorded()); + return result; +} + +void SymbianAudioInput::setError(QAudio::Error error) +{ + m_error = error; + + // Although no state transition actually occurs here, a stateChanged event + // must be emitted to inform the client that the call to start() was + // unsuccessful. + if (QAudio::OpenError == error) + emit stateChanged(QAudio::StoppedState); + + // Close the DevSound instance. This causes a transition to StoppedState. + // This must be done asynchronously in case the current function was called + // from a DevSound event handler, in which case deleting the DevSound + // instance may cause an exception. + QMetaObject::invokeMethod(this, "close", Qt::QueuedConnection); +} + +void SymbianAudioInput::setState(SymbianAudio::State newInternalState) +{ + const QAudio::State oldExternalState = m_externalState; + m_internalState = newInternalState; + m_externalState = SymbianAudio::Utils::stateNativeToQt( + m_internalState, initializingState()); + + if (m_externalState != oldExternalState) + emit stateChanged(m_externalState); +} + +QAudio::State SymbianAudioInput::initializingState() const +{ + return QAudio::IdleState; +} + +QT_END_NAMESPACE diff --git a/src/plugins/audio/symbian/symbianaudioinput.h b/src/plugins/audio/symbian/symbianaudioinput.h new file mode 100644 index 0000000..0497d7a --- /dev/null +++ b/src/plugins/audio/symbian/symbianaudioinput.h @@ -0,0 +1,177 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the plugins 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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef SYMBIANAUDIOINPUT_H +#define SYMBIANAUDIOINPUT_H + +#include +#include +#include +#include +#include "symbianaudio.h" + +QT_BEGIN_NAMESPACE + +class SymbianAudioInput; + +class SymbianAudioInputPrivate : public QIODevice +{ + friend class SymbianAudioInput; + Q_OBJECT +public: + SymbianAudioInputPrivate(SymbianAudioInput *audio); + ~SymbianAudioInputPrivate(); + + qint64 readData(char *data, qint64 len); + qint64 writeData(const char *data, qint64 len); + + void dataReady(); + +private: + SymbianAudioInput *const m_audioDevice; +}; + +class SymbianAudioInput + : public QAbstractAudioInput + , public MDevSoundObserver +{ + friend class SymbianAudioInputPrivate; + Q_OBJECT +public: + SymbianAudioInput(const QByteArray &device, + const QAudioFormat &audioFormat); + ~SymbianAudioInput(); + + // QAbstractAudioInput + QIODevice* start(QIODevice *device = 0); + void stop(); + void reset(); + void suspend(); + void resume(); + int bytesReady() const; + int periodSize() const; + void setBufferSize(int value); + int bufferSize() const; + void setNotifyInterval(int milliSeconds); + int notifyInterval() const; + qint64 processedUSecs() const; + qint64 elapsedUSecs() const; + QAudio::Error error() const; + QAudio::State state() const; + QAudioFormat format() const; + + // MDevSoundObserver + void InitializeComplete(TInt aError); + void ToneFinished(TInt aError); + void BufferToBeFilled(CMMFBuffer *aBuffer); + void PlayError(TInt aError); + void BufferToBeEmptied(CMMFBuffer *aBuffer); + void RecordError(TInt aError); + void ConvertError(TInt aError); + void DeviceMessage(TUid aMessageType, const TDesC8 &aMsg); + +private slots: + void pullData(); + +private: + void open(); + void startRecording(); + void startDevSoundL(); + void startDataTransfer(); + CMMFDataBuffer* currentBuffer() const; + void pushData(); + qint64 read(char *data, qint64 len); + void bufferEmptied(); + Q_INVOKABLE void close(); + + qint64 getSamplesRecorded() const; + + void setError(QAudio::Error error); + void setState(SymbianAudio::State state); + + QAudio::State initializingState() const; + +private: + const QByteArray m_device; + const QAudioFormat m_format; + + int m_clientBufferSize; + int m_notifyInterval; + QScopedPointer m_notifyTimer; + QTime m_elapsed; + QAudio::Error m_error; + + SymbianAudio::State m_internalState; + QAudio::State m_externalState; + + bool m_pullMode; + QIODevice *m_sink; + + QScopedPointer m_pullTimer; + + QScopedPointer m_devSound; + TUint32 m_nativeFourCC; + TMMFCapabilities m_nativeFormat; + + // Latest buffer provided by DevSound, to be empied of data. + CMMFDataBuffer *m_devSoundBuffer; + + int m_devSoundBufferSize; + + // Total amount of data in buffers provided by DevSound + int m_totalBytesReady; + + // Queue of buffers returned after call to CMMFDevSound::Pause(). + QList m_devSoundBufferQ; + + // Current read position within m_devSoundBuffer + qint64 m_devSoundBufferPos; + + // Samples recorded up to the last call to suspend(). It is necessary + // to cache this because suspend() is implemented using + // CMMFDevSound::Stop(), which resets DevSound's SamplesRecorded() counter. + quint32 m_totalSamplesRecorded; + +}; + +QT_END_NAMESPACE + +#endif diff --git a/src/plugins/audio/symbian/symbianaudiooutput.cpp b/src/plugins/audio/symbian/symbianaudiooutput.cpp new file mode 100644 index 0000000..7e05211 --- /dev/null +++ b/src/plugins/audio/symbian/symbianaudiooutput.cpp @@ -0,0 +1,697 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the plugins 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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "symbianaudiooutput.h" +#include "symbianaudioutils.h" + +QT_BEGIN_NAMESPACE + +//----------------------------------------------------------------------------- +// Constants +//----------------------------------------------------------------------------- + +const int UnderflowTimerInterval = 50; // ms + + +//----------------------------------------------------------------------------- +// Private class +//----------------------------------------------------------------------------- + +SymbianAudioOutputPrivate::SymbianAudioOutputPrivate( + SymbianAudioOutput *audioDevice) + : m_audioDevice(audioDevice) +{ + +} + +SymbianAudioOutputPrivate::~SymbianAudioOutputPrivate() +{ + +} + +qint64 SymbianAudioOutputPrivate::readData(char *data, qint64 len) +{ + Q_UNUSED(data) + Q_UNUSED(len) + return 0; +} + +qint64 SymbianAudioOutputPrivate::writeData(const char *data, qint64 len) +{ + qint64 totalWritten = 0; + + if (m_audioDevice->state() == QAudio::ActiveState || + m_audioDevice->state() == QAudio::IdleState) { + + while (totalWritten < len) { + const qint64 written = m_audioDevice->pushData(data + totalWritten, + len - totalWritten); + if (written > 0) + totalWritten += written; + else + break; + } + } + + return totalWritten; +} + + +//----------------------------------------------------------------------------- +// Public functions +//----------------------------------------------------------------------------- + +SymbianAudioOutput::SymbianAudioOutput(const QByteArray &device, + const QAudioFormat &format) + : m_device(device) + , m_format(format) + , m_clientBufferSize(SymbianAudio::DefaultBufferSize) + , m_notifyInterval(SymbianAudio::DefaultNotifyInterval) + , m_notifyTimer(new QTimer(this)) + , m_error(QAudio::NoError) + , m_internalState(SymbianAudio::ClosedState) + , m_externalState(QAudio::StoppedState) + , m_pullMode(false) + , m_source(0) + , m_devSoundBuffer(0) + , m_devSoundBufferSize(0) + , m_bytesWritten(0) + , m_pushDataReady(false) + , m_bytesPadding(0) + , m_underflow(false) + , m_lastBuffer(false) + , m_underflowTimer(new QTimer(this)) + , m_samplesPlayed(0) + , m_totalSamplesPlayed(0) +{ + connect(m_notifyTimer.data(), SIGNAL(timeout()), this, SIGNAL(notify())); + + SymbianAudio::Utils::formatQtToNative(m_format, m_nativeFourCC, + m_nativeFormat); + + m_underflowTimer->setInterval(UnderflowTimerInterval); + connect(m_underflowTimer.data(), SIGNAL(timeout()), this, + SLOT(underflowTimerExpired())); +} + +SymbianAudioOutput::~SymbianAudioOutput() +{ + close(); +} + +QIODevice* SymbianAudioOutput::start(QIODevice *device) +{ + stop(); + + // We have to set these before the call to open() because of the + // logic in initializingState() + if (device) { + m_pullMode = true; + m_source = device; + } + + open(); + + if (SymbianAudio::ClosedState != m_internalState) { + if (device) { + connect(m_source, SIGNAL(readyRead()), this, SLOT(dataReady())); + } else { + m_source = new SymbianAudioOutputPrivate(this); + m_source->open(QIODevice::WriteOnly | QIODevice::Unbuffered); + } + + m_elapsed.restart(); + } + + return m_source; +} + +void SymbianAudioOutput::stop() +{ + close(); +} + +void SymbianAudioOutput::reset() +{ + m_totalSamplesPlayed += getSamplesPlayed(); + m_devSound->Stop(); + m_bytesPadding = 0; + startPlayback(); +} + +void SymbianAudioOutput::suspend() +{ + if (SymbianAudio::ActiveState == m_internalState + || SymbianAudio::IdleState == m_internalState) { + m_notifyTimer->stop(); + m_underflowTimer->stop(); + + const qint64 samplesWritten = SymbianAudio::Utils::bytesToSamples( + m_format, m_bytesWritten); + m_bytesWritten = 0; + + const qint64 samplesPlayed = getSamplesPlayed(); + + // CMMFDevSound::Pause() is not guaranteed to work correctly in all + // implementations, for play-mode DevSound sessions. We therefore + // have to implement suspend() by calling CMMFDevSound::Stop(). + // Because this causes buffered data to be dropped, we replace the + // lost data with silence following a call to resume(), in order to + // ensure that processedUSecs() returns the correct value. + m_devSound->Stop(); + m_totalSamplesPlayed += samplesPlayed; + + // Calculate the amount of data dropped + const qint64 paddingSamples = samplesWritten - samplesPlayed; + m_bytesPadding = SymbianAudio::Utils::samplesToBytes(m_format, + paddingSamples); + + setState(SymbianAudio::SuspendedState); + } +} + +void SymbianAudioOutput::resume() +{ + if (SymbianAudio::SuspendedState == m_internalState) + startPlayback(); +} + +int SymbianAudioOutput::bytesFree() const +{ + int result = 0; + if (m_devSoundBuffer) { + const TDes8 &outputBuffer = m_devSoundBuffer->Data(); + result = outputBuffer.MaxLength() - outputBuffer.Length(); + } + return result; +} + +int SymbianAudioOutput::periodSize() const +{ + return bufferSize(); +} + +void SymbianAudioOutput::setBufferSize(int value) +{ + // Note that DevSound does not allow its client to specify the buffer size. + // This functionality is available via custom interfaces, but since these + // cannot be guaranteed to work across all DevSound implementations, we + // do not use them here. + // In order to comply with the expected bevahiour of QAudioOutput, we store + // the value and return it from bufferSize(), but the underlying DevSound + // buffer size remains unchanged. + if (value > 0) + m_clientBufferSize = value; +} + +int SymbianAudioOutput::bufferSize() const +{ + return m_devSoundBufferSize ? m_devSoundBufferSize : m_clientBufferSize; +} + +void SymbianAudioOutput::setNotifyInterval(int ms) +{ + if (ms > 0) { + const int oldNotifyInterval = m_notifyInterval; + m_notifyInterval = ms; + if (m_notifyTimer->isActive() && ms != oldNotifyInterval) + m_notifyTimer->start(m_notifyInterval); + } +} + +int SymbianAudioOutput::notifyInterval() const +{ + return m_notifyInterval; +} + +qint64 SymbianAudioOutput::processedUSecs() const +{ + int samplesPlayed = 0; + if (m_devSound && SymbianAudio::SuspendedState != m_internalState) + samplesPlayed = getSamplesPlayed(); + + // Protect against division by zero + Q_ASSERT_X(m_format.frequency() > 0, Q_FUNC_INFO, "Invalid frequency"); + + const qint64 result = qint64(1000000) * + (samplesPlayed + m_totalSamplesPlayed) + / m_format.frequency(); + + return result; +} + +qint64 SymbianAudioOutput::elapsedUSecs() const +{ + const qint64 result = (QAudio::StoppedState == state()) ? + 0 : m_elapsed.elapsed() * 1000; + return result; +} + +QAudio::Error SymbianAudioOutput::error() const +{ + return m_error; +} + +QAudio::State SymbianAudioOutput::state() const +{ + return m_externalState; +} + +QAudioFormat SymbianAudioOutput::format() const +{ + return m_format; +} + +//----------------------------------------------------------------------------- +// MDevSoundObserver implementation +//----------------------------------------------------------------------------- + +void SymbianAudioOutput::InitializeComplete(TInt aError) +{ + Q_ASSERT_X(SymbianAudio::InitializingState == m_internalState, + Q_FUNC_INFO, "Invalid state"); + + if (KErrNone == aError) + startPlayback(); +} + +void SymbianAudioOutput::ToneFinished(TInt aError) +{ + Q_UNUSED(aError) + // This class doesn't use DevSound's tone playback functions, so should + // never receive this callback. + Q_ASSERT_X(false, Q_FUNC_INFO, "Unexpected callback"); +} + +void SymbianAudioOutput::BufferToBeFilled(CMMFBuffer *aBuffer) +{ + // Following receipt of this callback, DevSound should not provide another + // buffer until we have returned the current one. + Q_ASSERT_X(!m_devSoundBuffer, Q_FUNC_INFO, "Buffer already held"); + + // Will be returned to DevSound by bufferFilled(). + m_devSoundBuffer = static_cast(aBuffer); + + if (!m_devSoundBufferSize) + m_devSoundBufferSize = m_devSoundBuffer->Data().MaxLength(); + + writePaddingData(); + + if (m_pullMode && isDataReady() && !m_bytesPadding) + pullData(); +} + +void SymbianAudioOutput::PlayError(TInt aError) +{ + switch (aError) { + case KErrUnderflow: + m_underflow = true; + if (m_pullMode && !m_lastBuffer) + setError(QAudio::UnderrunError); + else + setState(SymbianAudio::IdleState); + break; + default: + setError(QAudio::IOError); + break; + } +} + +void SymbianAudioOutput::BufferToBeEmptied(CMMFBuffer *aBuffer) +{ + Q_UNUSED(aBuffer) + // This class doesn't use DevSound in record mode, so should never receive + // this callback. + Q_ASSERT_X(false, Q_FUNC_INFO, "Unexpected callback"); +} + +void SymbianAudioOutput::RecordError(TInt aError) +{ + Q_UNUSED(aError) + // This class doesn't use DevSound in record mode, so should never receive + // this callback. + Q_ASSERT_X(false, Q_FUNC_INFO, "Unexpected callback"); +} + +void SymbianAudioOutput::ConvertError(TInt aError) +{ + Q_UNUSED(aError) + // This class doesn't use DevSound's format conversion functions, so + // should never receive this callback. + Q_ASSERT_X(false, Q_FUNC_INFO, "Unexpected callback"); +} + +void SymbianAudioOutput::DeviceMessage(TUid aMessageType, const TDesC8 &aMsg) +{ + Q_UNUSED(aMessageType) + Q_UNUSED(aMsg) + // Ignore this callback. +} + +//----------------------------------------------------------------------------- +// Private functions +//----------------------------------------------------------------------------- + +void SymbianAudioOutput::dataReady() +{ + // Client-provided QIODevice has data ready to read. + + Q_ASSERT_X(m_source->bytesAvailable(), Q_FUNC_INFO, + "readyRead signal received, but no data available"); + + if (!m_bytesPadding) + pullData(); +} + +void SymbianAudioOutput::underflowTimerExpired() +{ + const TInt samplesPlayed = getSamplesPlayed(); + if (m_samplesPlayed && (samplesPlayed == m_samplesPlayed)) { + setError(QAudio::UnderrunError); + } else { + m_samplesPlayed = samplesPlayed; + m_underflowTimer->start(); + } +} + +void SymbianAudioOutput::open() +{ + Q_ASSERT_X(SymbianAudio::ClosedState == m_internalState, + Q_FUNC_INFO, "DevSound already opened"); + + QT_TRAP_THROWING( m_devSound.reset(CMMFDevSound::NewL()) ) + + QScopedPointer caps( + new SymbianAudio::DevSoundCapabilities(*m_devSound, + QAudio::AudioOutput)); + + int err = SymbianAudio::Utils::isFormatSupported(m_format, *caps) ? + KErrNone : KErrNotSupported; + + if (KErrNone == err) { + setState(SymbianAudio::InitializingState); + TRAP(err, m_devSound->InitializeL(*this, m_nativeFourCC, + EMMFStatePlaying)); + } + + if (KErrNone != err) { + setError(QAudio::OpenError); + m_devSound.reset(); + } +} + +void SymbianAudioOutput::startPlayback() +{ + TRAPD(err, startDevSoundL()); + if (KErrNone == err) { + if (isDataReady()) + setState(SymbianAudio::ActiveState); + else + setState(SymbianAudio::IdleState); + + m_notifyTimer->start(m_notifyInterval); + m_underflow = false; + + Q_ASSERT(m_devSound->SamplesPlayed() == 0); + + writePaddingData(); + + if (m_pullMode && m_source->bytesAvailable() && !m_bytesPadding) + dataReady(); + } else { + setError(QAudio::OpenError); + close(); + } +} + +void SymbianAudioOutput::startDevSoundL() +{ + TMMFCapabilities nativeFormat = m_devSound->Config(); + m_nativeFormat.iBufferSize = nativeFormat.iBufferSize; + m_devSound->SetConfigL(m_nativeFormat); + m_devSound->PlayInitL(); +} + +void SymbianAudioOutput::writePaddingData() +{ + // See comments in suspend() + + while (m_devSoundBuffer && m_bytesPadding) { + if (SymbianAudio::IdleState == m_internalState) + setState(SymbianAudio::ActiveState); + + TDes8 &outputBuffer = m_devSoundBuffer->Data(); + const qint64 outputBytes = bytesFree(); + const qint64 paddingBytes = outputBytes < m_bytesPadding ? + outputBytes : m_bytesPadding; + unsigned char *ptr = const_cast(outputBuffer.Ptr()); + Mem::FillZ(ptr, paddingBytes); + outputBuffer.SetLength(outputBuffer.Length() + paddingBytes); + m_bytesPadding -= paddingBytes; + + if (m_pullMode && m_source->atEnd()) + lastBufferFilled(); + if (paddingBytes == outputBytes) + bufferFilled(); + } +} + +qint64 SymbianAudioOutput::pushData(const char *data, qint64 len) +{ + // Data has been written to SymbianAudioOutputPrivate + + Q_ASSERT_X(!m_pullMode, Q_FUNC_INFO, + "pushData called when in pull mode"); + + const unsigned char *const inputPtr = + reinterpret_cast(data); + qint64 bytesWritten = 0; + + if (SymbianAudio::IdleState == m_internalState) + setState(SymbianAudio::ActiveState); + + while (m_devSoundBuffer && (bytesWritten < len)) { + // writePaddingData() is called from BufferToBeFilled(), so we should + // never have any padding data left at this point. + Q_ASSERT_X(0 == m_bytesPadding, Q_FUNC_INFO, + "Padding bytes remaining in pushData"); + + TDes8 &outputBuffer = m_devSoundBuffer->Data(); + + const qint64 outputBytes = bytesFree(); + const qint64 inputBytes = len - bytesWritten; + const qint64 copyBytes = outputBytes < inputBytes ? + outputBytes : inputBytes; + + outputBuffer.Append(inputPtr + bytesWritten, copyBytes); + bytesWritten += copyBytes; + + bufferFilled(); + } + + m_pushDataReady = (bytesWritten < len); + + // If DevSound is still initializing (m_internalState == InitializingState), + // we cannot transition m_internalState to ActiveState, but we must emit + // an (external) state change from IdleState to ActiveState. The following + // call triggers this signal. + setState(m_internalState); + + return bytesWritten; +} + +void SymbianAudioOutput::pullData() +{ + Q_ASSERT_X(m_pullMode, Q_FUNC_INFO, + "pullData called when in push mode"); + + if (m_bytesPadding) + m_bytesPadding = 1; + + // writePaddingData() is called by BufferToBeFilled() before pullData(), + // so we should never have any padding data left at this point. + Q_ASSERT_X(0 == m_bytesPadding, Q_FUNC_INFO, + "Padding bytes remaining in pullData"); + + qint64 inputBytes = m_source->bytesAvailable(); + while (m_devSoundBuffer && inputBytes) { + if (SymbianAudio::IdleState == m_internalState) + setState(SymbianAudio::ActiveState); + + TDes8 &outputBuffer = m_devSoundBuffer->Data(); + + const qint64 outputBytes = bytesFree(); + const qint64 copyBytes = outputBytes < inputBytes ? + outputBytes : inputBytes; + + char *outputPtr = (char*)(outputBuffer.Ptr() + outputBuffer.Length()); + const qint64 bytesCopied = m_source->read(outputPtr, copyBytes); + Q_ASSERT(bytesCopied == copyBytes); + outputBuffer.SetLength(outputBuffer.Length() + bytesCopied); + inputBytes -= bytesCopied; + + if (m_source->atEnd()) + lastBufferFilled(); + else if (copyBytes == outputBytes) + bufferFilled(); + } +} + +void SymbianAudioOutput::bufferFilled() +{ + Q_ASSERT_X(m_devSoundBuffer, Q_FUNC_INFO, "No buffer to return"); + + const TDes8 &outputBuffer = m_devSoundBuffer->Data(); + m_bytesWritten += outputBuffer.Length(); + + m_devSoundBuffer = 0; + + m_samplesPlayed = getSamplesPlayed(); + m_underflowTimer->start(); + + if (QAudio::UnderrunError == m_error) + m_error = QAudio::NoError; + + m_devSound->PlayData(); +} + +void SymbianAudioOutput::lastBufferFilled() +{ + Q_ASSERT_X(m_devSoundBuffer, Q_FUNC_INFO, "No buffer to fill"); + Q_ASSERT_X(!m_lastBuffer, Q_FUNC_INFO, "Last buffer already sent"); + m_lastBuffer = true; + m_devSoundBuffer->SetLastBuffer(ETrue); + bufferFilled(); +} + +void SymbianAudioOutput::close() +{ + m_notifyTimer->stop(); + m_underflowTimer->stop(); + + m_error = QAudio::NoError; + + if (m_devSound) + m_devSound->Stop(); + m_devSound.reset(); + m_devSoundBuffer = 0; + m_devSoundBufferSize = 0; + + if (!m_pullMode) // m_source is owned + delete m_source; + m_pullMode = false; + m_source = 0; + + m_bytesWritten = 0; + m_pushDataReady = false; + m_bytesPadding = 0; + m_underflow = false; + m_lastBuffer = false; + m_samplesPlayed = 0; + m_totalSamplesPlayed = 0; + + setState(SymbianAudio::ClosedState); +} + +qint64 SymbianAudioOutput::getSamplesPlayed() const +{ + qint64 result = 0; + if (m_devSound) { + const qint64 samplesWritten = SymbianAudio::Utils::bytesToSamples( + m_format, m_bytesWritten); + + if (m_underflow) { + result = samplesWritten; + } else { + // This is necessary because some DevSound implementations report + // that they have played more data than has actually been provided to them + // by the client. + const qint64 devSoundSamplesPlayed(m_devSound->SamplesPlayed()); + result = qMin(devSoundSamplesPlayed, samplesWritten); + } + } + return result; +} + +void SymbianAudioOutput::setError(QAudio::Error error) +{ + m_error = error; + + // Although no state transition actually occurs here, a stateChanged event + // must be emitted to inform the client that the call to start() was + // unsuccessful. + if (QAudio::OpenError == error) + emit stateChanged(QAudio::StoppedState); + + if (QAudio::UnderrunError == error) + setState(SymbianAudio::IdleState); + else + // Close the DevSound instance. This causes a transition to + // StoppedState. This must be done asynchronously in case the + // current function was called from a DevSound event handler, in which + // case deleting the DevSound instance may cause an exception. + QMetaObject::invokeMethod(this, "close", Qt::QueuedConnection); +} + +void SymbianAudioOutput::setState(SymbianAudio::State newInternalState) +{ + const QAudio::State oldExternalState = m_externalState; + m_internalState = newInternalState; + m_externalState = SymbianAudio::Utils::stateNativeToQt( + m_internalState, initializingState()); + + if (m_externalState != oldExternalState) + emit stateChanged(m_externalState); +} + +bool SymbianAudioOutput::isDataReady() const +{ + return (m_source && m_source->bytesAvailable()) + || m_bytesPadding + || m_pushDataReady; +} + +QAudio::State SymbianAudioOutput::initializingState() const +{ + return isDataReady() ? QAudio::ActiveState : QAudio::IdleState; +} + +QT_END_NAMESPACE diff --git a/src/plugins/audio/symbian/symbianaudiooutput.h b/src/plugins/audio/symbian/symbianaudiooutput.h new file mode 100644 index 0000000..4db97c3 --- /dev/null +++ b/src/plugins/audio/symbian/symbianaudiooutput.h @@ -0,0 +1,199 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the plugins 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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef SYMBIANAUDIOOUTPUT_H +#define SYMBIANAUDIOOUTPUT_H + +#include +#include +#include +#include +#include "symbianaudio.h" + +QT_BEGIN_NAMESPACE + +class SymbianAudioOutput; + +class SymbianAudioOutputPrivate : public QIODevice +{ + friend class SymbianAudioOutput; + Q_OBJECT +public: + SymbianAudioOutputPrivate(SymbianAudioOutput *audio); + ~SymbianAudioOutputPrivate(); + + qint64 readData(char *data, qint64 len); + qint64 writeData(const char *data, qint64 len); + +private: + SymbianAudioOutput *const m_audioDevice; +}; + +class SymbianAudioOutput + : public QAbstractAudioOutput + , public MDevSoundObserver +{ + friend class SymbianAudioOutputPrivate; + Q_OBJECT +public: + SymbianAudioOutput(const QByteArray &device, + const QAudioFormat &audioFormat); + ~SymbianAudioOutput(); + + // QAbstractAudioOutput + QIODevice* start(QIODevice *device = 0); + void stop(); + void reset(); + void suspend(); + void resume(); + int bytesFree() const; + int periodSize() const; + void setBufferSize(int value); + int bufferSize() const; + void setNotifyInterval(int milliSeconds); + int notifyInterval() const; + qint64 processedUSecs() const; + qint64 elapsedUSecs() const; + QAudio::Error error() const; + QAudio::State state() const; + QAudioFormat format() const; + + // MDevSoundObserver + void InitializeComplete(TInt aError); + void ToneFinished(TInt aError); + void BufferToBeFilled(CMMFBuffer *aBuffer); + void PlayError(TInt aError); + void BufferToBeEmptied(CMMFBuffer *aBuffer); + void RecordError(TInt aError); + void ConvertError(TInt aError); + void DeviceMessage(TUid aMessageType, const TDesC8 &aMsg); + +private slots: + void dataReady(); + void underflowTimerExpired(); + +private: + void open(); + void startPlayback(); + void startDevSoundL(); + void writePaddingData(); + qint64 pushData(const char *data, qint64 len); + void pullData(); + void bufferFilled(); + void lastBufferFilled(); + Q_INVOKABLE void close(); + + qint64 getSamplesPlayed() const; + + void setError(QAudio::Error error); + void setState(SymbianAudio::State state); + + bool isDataReady() const; + QAudio::State initializingState() const; + +private: + const QByteArray m_device; + const QAudioFormat m_format; + + int m_clientBufferSize; + int m_notifyInterval; + QScopedPointer m_notifyTimer; + QTime m_elapsed; + QAudio::Error m_error; + + SymbianAudio::State m_internalState; + QAudio::State m_externalState; + + bool m_pullMode; + QIODevice *m_source; + + QScopedPointer m_devSound; + TUint32 m_nativeFourCC; + TMMFCapabilities m_nativeFormat; + + // Buffer provided by DevSound, to be filled with data. + CMMFDataBuffer *m_devSoundBuffer; + + int m_devSoundBufferSize; + + // Number of bytes transferred from QIODevice to QAudioOutput. It is + // necessary to count this because data is dropped when suspend() is + // called. The difference between the position reported by DevSound and + // this value allows us to calculate m_bytesPadding; + quint32 m_bytesWritten; + + // True if client has provided data while the audio subsystem was not + // ready to consume it. + bool m_pushDataReady; + + // Number of zero bytes which will be written when client calls resume(). + quint32 m_bytesPadding; + + // True if PlayError(KErrUnderflow) has been called. + bool m_underflow; + + // True if a buffer marked with the "last buffer" flag has been provided + // to DevSound. + bool m_lastBuffer; + + // Some DevSound implementations ignore all underflow errors raised by the + // audio driver, unless the last buffer flag has been set by the client. + // In push-mode playback, this flag will never be set, so the underflow + // error will never be reported. In order to work around this, a timer + // is used, which gets reset every time the client provides more data. If + // the timer expires, an underflow error is raised by this object. + QScopedPointer m_underflowTimer; + + // Result of previous call to CMMFDevSound::SamplesPlayed(). This value is + // used to determine whether, when m_underflowTimer expires, an + // underflow error has actually occurred. + quint32 m_samplesPlayed; + + // Samples played up to the last call to suspend(). It is necessary + // to cache this because suspend() is implemented using + // CMMFDevSound::Stop(), which resets DevSound's SamplesPlayed() counter. + quint32 m_totalSamplesPlayed; + +}; + +QT_END_NAMESPACE + +#endif diff --git a/src/plugins/audio/symbian/symbianaudioutils.cpp b/src/plugins/audio/symbian/symbianaudioutils.cpp new file mode 100644 index 0000000..13ea03d --- /dev/null +++ b/src/plugins/audio/symbian/symbianaudioutils.cpp @@ -0,0 +1,395 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the plugins 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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "symbianaudioutils.h" +#include + +QT_BEGIN_NAMESPACE + +namespace SymbianAudio { + +DevSoundCapabilities::DevSoundCapabilities(CMMFDevSound &devsound, + QAudio::Mode mode) +{ + QT_TRAP_THROWING(constructL(devsound, mode)); +} + +DevSoundCapabilities::~DevSoundCapabilities() +{ + m_fourCC.Close(); +} + +void DevSoundCapabilities::constructL(CMMFDevSound &devsound, + QAudio::Mode mode) +{ + m_caps = devsound.Capabilities(); + + TMMFPrioritySettings settings; + + switch (mode) { + case QAudio::AudioOutput: + settings.iState = EMMFStatePlaying; + devsound.GetSupportedInputDataTypesL(m_fourCC, settings); + break; + + case QAudio::AudioInput: + settings.iState = EMMFStateRecording; + devsound.GetSupportedInputDataTypesL(m_fourCC, settings); + break; + + default: + Q_ASSERT_X(false, Q_FUNC_INFO, "Invalid mode"); + } +} + +namespace Utils { + +//----------------------------------------------------------------------------- +// Static data +//----------------------------------------------------------------------------- + +// Sample rate / frequency + +typedef TMMFSampleRate SampleRateNative; +typedef int SampleRateQt; + +const int SampleRateCount = 12; + +const SampleRateNative SampleRateListNative[SampleRateCount] = { + EMMFSampleRate8000Hz + , EMMFSampleRate11025Hz + , EMMFSampleRate12000Hz + , EMMFSampleRate16000Hz + , EMMFSampleRate22050Hz + , EMMFSampleRate24000Hz + , EMMFSampleRate32000Hz + , EMMFSampleRate44100Hz + , EMMFSampleRate48000Hz + , EMMFSampleRate64000Hz + , EMMFSampleRate88200Hz + , EMMFSampleRate96000Hz +}; + +const SampleRateQt SampleRateListQt[SampleRateCount] = { + 8000 + , 11025 + , 12000 + , 16000 + , 22050 + , 24000 + , 32000 + , 44100 + , 48000 + , 64000 + , 88200 + , 96000 +}; + +// Channels + +typedef TMMFMonoStereo ChannelsNative; +typedef int ChannelsQt; + +const int ChannelsCount = 2; + +const ChannelsNative ChannelsListNative[ChannelsCount] = { + EMMFMono + , EMMFStereo +}; + +const ChannelsQt ChannelsListQt[ChannelsCount] = { + 1 + , 2 +}; + +// Encoding + +const int EncodingCount = 6; + +const TUint32 EncodingFourCC[EncodingCount] = { + KMMFFourCCCodePCM8 // 0 + , KMMFFourCCCodePCMU8 // 1 + , KMMFFourCCCodePCM16 // 2 + , KMMFFourCCCodePCMU16 // 3 + , KMMFFourCCCodePCM16B // 4 + , KMMFFourCCCodePCMU16B // 5 +}; + +// The characterised DevSound API specification states that the iEncoding +// field in TMMFCapabilities is ignored, and that the FourCC should be used +// to specify the PCM encoding. +// See "SGL.GT0287.102 Multimedia DevSound Baseline Compatibility.doc" in the +// mm_info/mm_docs repository. +const TMMFSoundEncoding EncodingNative[EncodingCount] = { + EMMFSoundEncoding16BitPCM // 0 + , EMMFSoundEncoding16BitPCM // 1 + , EMMFSoundEncoding16BitPCM // 2 + , EMMFSoundEncoding16BitPCM // 3 + , EMMFSoundEncoding16BitPCM // 4 + , EMMFSoundEncoding16BitPCM // 5 +}; + + +const int EncodingSampleSize[EncodingCount] = { + 8 // 0 + , 8 // 1 + , 16 // 2 + , 16 // 3 + , 16 // 4 + , 16 // 5 +}; + +const QAudioFormat::Endian EncodingByteOrder[EncodingCount] = { + QAudioFormat::LittleEndian // 0 + , QAudioFormat::LittleEndian // 1 + , QAudioFormat::LittleEndian // 2 + , QAudioFormat::LittleEndian // 3 + , QAudioFormat::BigEndian // 4 + , QAudioFormat::BigEndian // 5 +}; + +const QAudioFormat::SampleType EncodingSampleType[EncodingCount] = { + QAudioFormat::SignedInt // 0 + , QAudioFormat::UnSignedInt // 1 + , QAudioFormat::SignedInt // 2 + , QAudioFormat::UnSignedInt // 3 + , QAudioFormat::SignedInt // 4 + , QAudioFormat::UnSignedInt // 5 +}; + + +//----------------------------------------------------------------------------- +// Private functions +//----------------------------------------------------------------------------- + +// Helper functions for implementing parameter conversions + +template +bool findValue(const Input *inputArray, int length, Input input, int &index) { + bool result = false; + for (int i=0; !result && i +bool convertValue(const Input *inputArray, const Output *outputArray, + int length, Input input, Output &output) { + int index; + const bool result = findValue(inputArray, length, input, index); + if (result) + output = outputArray[index]; + return result; +} + +/** + * Macro which is used to generate the implementation of the conversion + * functions. The implementation is just a wrapper around the templated + * convertValue function, e.g. + * + * CONVERSION_FUNCTION_IMPL(SampleRate, Qt, Native) + * + * expands to + * + * bool SampleRateQtToNative(int input, TMMFSampleRate &output) { + * return convertValue + * (SampleRateListQt, SampleRateListNative, SampleRateCount, + * input, output); + * } + */ +#define CONVERSION_FUNCTION_IMPL(FieldLc, Field, Input, Output) \ +bool FieldLc##Input##To##Output(Field##Input input, Field##Output &output) { \ + return convertValue(Field##List##Input, \ + Field##List##Output, Field##Count, input, output); \ +} + +//----------------------------------------------------------------------------- +// Local helper functions +//----------------------------------------------------------------------------- + +CONVERSION_FUNCTION_IMPL(sampleRate, SampleRate, Qt, Native) +CONVERSION_FUNCTION_IMPL(sampleRate, SampleRate, Native, Qt) +CONVERSION_FUNCTION_IMPL(channels, Channels, Qt, Native) +CONVERSION_FUNCTION_IMPL(channels, Channels, Native, Qt) + +bool sampleInfoQtToNative(int inputSampleSize, + QAudioFormat::Endian inputByteOrder, + QAudioFormat::SampleType inputSampleType, + TUint32 &outputFourCC, + TMMFSoundEncoding &outputEncoding) { + + bool found = false; + + for (int i=0; i &frequencies, + QList &channels, + QList &sampleSizes, + QList &byteOrders, + QList &sampleTypes) { + + frequencies.clear(); + sampleSizes.clear(); + byteOrders.clear(); + sampleTypes.clear(); + channels.clear(); + + for (int i=0; i +#include +#include +#include +#include "symbianaudio.h" + +QT_BEGIN_NAMESPACE + +namespace SymbianAudio { + +/* + * Helper class for querying DevSound codec / format support + */ +class DevSoundCapabilities { +public: + DevSoundCapabilities(CMMFDevSound &devsound, QAudio::Mode mode); + ~DevSoundCapabilities(); + + const RArray& fourCC() const { return m_fourCC; } + const TMMFCapabilities& caps() const { return m_caps; } + +private: + void constructL(CMMFDevSound &devsound, QAudio::Mode mode); + +private: + RArray m_fourCC; + TMMFCapabilities m_caps; +}; + +namespace Utils { + +/** + * Convert native audio capabilities to QAudio lists. + */ +void capabilitiesNativeToQt(const DevSoundCapabilities &caps, + QList &frequencies, + QList &channels, + QList &sampleSizes, + QList &byteOrders, + QList &sampleTypes); + +/** + * Check whether format is supported. + */ +bool isFormatSupported(const QAudioFormat &format, + const DevSoundCapabilities &caps); + +/** + * Convert QAudioFormat to native format types. + * + * Note that, despite the name, DevSound uses TMMFCapabilities to specify + * single formats as well as capabilities. + * + * Note that this function does not modify outputFormat.iBufferSize. + */ +bool formatQtToNative(const QAudioFormat &inputFormat, + TUint32 &outputFourCC, + TMMFCapabilities &outputFormat); + +/** + * Convert internal states to QAudio states. + */ +QAudio::State stateNativeToQt(State nativeState, + QAudio::State initializingState); + +/** + * Convert data length to number of samples. + */ +qint64 bytesToSamples(const QAudioFormat &format, qint64 length); + +/** + * Convert number of samples to data length. + */ +qint64 samplesToBytes(const QAudioFormat &format, qint64 samples); + +} // namespace Utils +} // namespace SymbianAudio + +QT_END_NAMESPACE + +#endif diff --git a/src/s60installs/qt.iby b/src/s60installs/qt.iby index a6a96ec..724451b 100644 --- a/src/s60installs/qt.iby +++ b/src/s60installs/qt.iby @@ -80,6 +80,9 @@ file=ABI_DIR\BUILD_DIR\qsvgicon.dll SHARED_LIB_DIR\qsvgicon.dll PAG // Phonon MMF backend file=ABI_DIR\BUILD_DIR\phonon_mmf.dll SHARED_LIB_DIR\phonon_mmf.dll PAGED +// QtMultimedia audio backend +file=ABI_DIR\BUILD_DIR\qaudio.dll SHARED_LIB_DIR\qaudio.dll PAGED + // graphicssystems file=ABI_DIR\BUILD_DIR\qvggraphicssystem.dll SHARED_LIB_DIR\qvggraphicssystem.dll PAGED @@ -109,6 +112,9 @@ data=\epoc32\data\z\resource\qt\plugins\iconengines\qsvgicon.qtplugin resou // Phonon MMF backend data=\epoc32\data\z\resource\qt\plugins\phonon_backend\phonon_mmf.qtplugin resource\qt\plugins\phonon_backend\phonon_mmf.qtplugin +// QtMultimedia audio backend +data=\epoc32\data\qt\qtlibspluginstubs\qaudio.qtplugin resource\qt\plugins\audio\qaudio.qtplugin + // graphicssystems data=\epoc32\data\z\resource\qt\plugins\graphicssystems\qvggraphicssystem.qtplugin resource\qt\plugins\graphicssystems\qvggraphicssystem.qtplugin diff --git a/src/s60installs/s60installs.pro b/src/s60installs/s60installs.pro index 5318693..1f3b4a6 100644 --- a/src/s60installs/s60installs.pro +++ b/src/s60installs/s60installs.pro @@ -78,6 +78,12 @@ symbian: { DEPLOYMENT += phonon_backend_plugins } + contains(QT_CONFIG, audio-backend) { + qaudio_backend_plugins.sources += qaudio.dll + qaudio_backend_plugins.path = c:$$QT_PLUGINS_BASE_DIR/audio + DEPLOYMENT += qaudio_backend_plugins + } + # Support backup & restore for Qt libraries qtbackup.sources = backup_registration.xml qtbackup.path = c:/private/10202D56/import/packages/$$replace(TARGET.UID3, 0x,) -- cgit v0.12 From edbacbac16b23b91209b3216505c873fbf87d1a2 Mon Sep 17 00:00:00 2001 From: Gareth Stockwell Date: Thu, 18 Feb 2010 16:37:11 +0000 Subject: Pass QAudioDeviceInfo when creating audio input/output in examples Reviewed-by: trustme --- examples/multimedia/audioinput/audioinput.cpp | 2 +- examples/multimedia/audiooutput/audiooutput.cpp | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/examples/multimedia/audioinput/audioinput.cpp b/examples/multimedia/audioinput/audioinput.cpp index 8a97640..b01a396 100644 --- a/examples/multimedia/audioinput/audioinput.cpp +++ b/examples/multimedia/audioinput/audioinput.cpp @@ -208,6 +208,7 @@ InputTest::InputTest() , m_modeButton(0) , m_suspendResumeButton(0) , m_deviceBox(0) + , m_device(QAudioDeviceInfo::defaultInputDevice()) , m_audioInfo(0) , m_audioInput(0) , m_input(0) @@ -279,7 +280,6 @@ void InputTest::initializeAudio() void InputTest::createAudioInput() { - m_audioInput = new QAudioInput(m_device, m_format, this); connect(m_audioInput, SIGNAL(notify()), SLOT(notified())); connect(m_audioInput, SIGNAL(stateChanged(QAudio::State)), SLOT(stateChanged(QAudio::State))); diff --git a/examples/multimedia/audiooutput/audiooutput.cpp b/examples/multimedia/audiooutput/audiooutput.cpp index 4866d36..cbadf02 100644 --- a/examples/multimedia/audiooutput/audiooutput.cpp +++ b/examples/multimedia/audiooutput/audiooutput.cpp @@ -160,6 +160,7 @@ AudioTest::AudioTest() , m_modeButton(0) , m_suspendResumeButton(0) , m_deviceBox(0) + , m_device(QAudioDeviceInfo::defaultOutputDevice()) , m_generator(0) , m_audioOutput(0) , m_output(0) @@ -226,7 +227,7 @@ void AudioTest::createAudioOutput() { delete m_audioOutput; m_audioOutput = 0; - m_audioOutput = new QAudioOutput(m_format, this); + m_audioOutput = new QAudioOutput(m_device, m_format, this); connect(m_audioOutput, SIGNAL(notify()), SLOT(notified())); connect(m_audioOutput, SIGNAL(stateChanged(QAudio::State)), SLOT(stateChanged(QAudio::State))); m_generator->start(); -- cgit v0.12 From 4c08defe1ac8342b9f8c6aeceebec12b839bae2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Abecasis?= Date: Thu, 18 Feb 2010 14:36:46 +0100 Subject: Simplify code, fix a compiler warning... profit! Well, it was a compiler warning on master... :-/ Reviewed-by: Janne Anttila Reviewed-by: axis --- src/gui/kernel/qsoftkeymanager.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/gui/kernel/qsoftkeymanager.cpp b/src/gui/kernel/qsoftkeymanager.cpp index d3cef86..c9a94ee 100644 --- a/src/gui/kernel/qsoftkeymanager.cpp +++ b/src/gui/kernel/qsoftkeymanager.cpp @@ -210,13 +210,11 @@ bool QSoftKeyManager::handleUpdateSoftKeys() d->requestedSoftKeyActions.clear(); bool recursiveMerging = false; QWidget *source = softkeySource(NULL, recursiveMerging); - do { - if (source) { - bool added = appendSoftkeys(*source, level); - source = softkeySource(source, recursiveMerging); - level = added ? level + 1 : level; - } - } while (source); + while (source) { + if (appendSoftkeys(*source, level)) + ++level; + source = softkeySource(source, recursiveMerging); + } d->updateSoftKeys_sys(); return true; -- cgit v0.12 From 7f01b5aa56e61048a9785040e9807fd871a4b59a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Abecasis?= Date: Thu, 18 Feb 2010 16:36:44 +0100 Subject: QTreeView: Fix premature pessimization Reviewed-by: Olivier Goffart --- src/gui/itemviews/qtreeview.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/gui/itemviews/qtreeview.cpp b/src/gui/itemviews/qtreeview.cpp index d0fa22d..706d2a8 100644 --- a/src/gui/itemviews/qtreeview.cpp +++ b/src/gui/itemviews/qtreeview.cpp @@ -2474,10 +2474,11 @@ void QTreeView::rowsInserted(const QModelIndex &parent, int start, int end) QVector insertedItems(delta); for (int i = 0; i < delta; ++i) { - insertedItems[i].index = d->model->index(i + start, 0, parent); - insertedItems[i].level = childLevel; - insertedItems[i].hasChildren = d->hasVisibleChildren(insertedItems[i].index); - insertedItems[i].hasMoreSiblings = !((i == delta - 1) && (parentRowCount == end +1)); + QTreeViewItem &item = insertedItems[i]; + item.index = d->model->index(i + start, 0, parent); + item.level = childLevel; + item.hasChildren = d->hasVisibleChildren(item.index); + item.hasMoreSiblings = !((i == delta - 1) && (parentRowCount == end +1)); } if (d->viewItems.isEmpty()) d->defaultItemHeight = indexRowSizeHint(insertedItems[0].index); -- cgit v0.12 From b408d94902ef0b2856a4c462e06fcc4412de49be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Abecasis?= Date: Fri, 12 Feb 2010 18:31:54 +0100 Subject: Fixing QDir benchmarks... The initial state of QDirIterator is ill-defined. If the hasNext returns true, then one must start by advancing the iterator to the first position. (Rinse, lather, repeat) --- tests/benchmarks/corelib/io/qdir/tst_qdir.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/benchmarks/corelib/io/qdir/tst_qdir.cpp b/tests/benchmarks/corelib/io/qdir/tst_qdir.cpp index aea9fd0..f2e52d2 100644 --- a/tests/benchmarks/corelib/io/qdir/tst_qdir.cpp +++ b/tests/benchmarks/corelib/io/qdir/tst_qdir.cpp @@ -95,9 +95,9 @@ private slots: QBENCHMARK { QDirIterator dit(testdir.path(), QDir::Files); while (dit.hasNext()) { + dit.next(); dit.fileInfo().isDir(); dit.fileInfo().size(); - dit.next(); } } } @@ -116,9 +116,9 @@ private slots: QBENCHMARK { QDirIterator dit(testdir.path()); while (dit.hasNext()) { + dit.next(); dit.fileInfo().isDir(); dit.fileInfo().size(); - dit.next(); } } } -- cgit v0.12 From b8f9453eec3b218317a3dae0acfe444bc00c3093 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Abecasis?= Date: Fri, 12 Feb 2010 18:36:41 +0100 Subject: Moving QDir benchmarks; making way for new test cases Also, removed dependency on QtGui; gave test case a more meaningful name; using bench_ prefix, instead of tst_ for benchmarks. --- tests/benchmarks/corelib/io/qdir/10000/10000.pro | 10 ++ .../corelib/io/qdir/10000/bench_qdir_10000.cpp | 198 +++++++++++++++++++++ tests/benchmarks/corelib/io/qdir/qdir.pro | 10 +- tests/benchmarks/corelib/io/qdir/tst_qdir.cpp | 198 --------------------- 4 files changed, 210 insertions(+), 206 deletions(-) create mode 100644 tests/benchmarks/corelib/io/qdir/10000/10000.pro create mode 100644 tests/benchmarks/corelib/io/qdir/10000/bench_qdir_10000.cpp delete mode 100644 tests/benchmarks/corelib/io/qdir/tst_qdir.cpp diff --git a/tests/benchmarks/corelib/io/qdir/10000/10000.pro b/tests/benchmarks/corelib/io/qdir/10000/10000.pro new file mode 100644 index 0000000..93b0992 --- /dev/null +++ b/tests/benchmarks/corelib/io/qdir/10000/10000.pro @@ -0,0 +1,10 @@ +load(qttest_p4) +TEMPLATE = app +TARGET = bench_qdir_10000 +DEPENDPATH += . +INCLUDEPATH += . + +# Input +SOURCES += bench_qdir_10000.cpp + +QT -= gui diff --git a/tests/benchmarks/corelib/io/qdir/10000/bench_qdir_10000.cpp b/tests/benchmarks/corelib/io/qdir/10000/bench_qdir_10000.cpp new file mode 100644 index 0000000..b325250 --- /dev/null +++ b/tests/benchmarks/corelib/io/qdir/10000/bench_qdir_10000.cpp @@ -0,0 +1,198 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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 module 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 + +#ifdef Q_OS_WIN +# include +#else +# include +# include +# include +# include +#endif + +class bench_QDir_10000 : public QObject{ + Q_OBJECT +public slots: + void initTestCase() { + QDir testdir = QDir::tempPath(); + + const QString subfolder_name = QLatin1String("test_speed"); + QVERIFY(testdir.mkdir(subfolder_name)); + QVERIFY(testdir.cd(subfolder_name)); + + for (uint i=0; i<10000; ++i) { + QFile file(testdir.absolutePath() + "/testfile_" + QString::number(i)); + file.open(QIODevice::WriteOnly); + } + } + void cleanupTestCase() { + { + QDir testdir(QDir::tempPath() + QLatin1String("/test_speed")); + testdir.setSorting(QDir::Unsorted); + testdir.setFilter(QDir::AllEntries | QDir::System | QDir::Hidden); + foreach (const QString &filename, testdir.entryList()) { + testdir.remove(filename); + } + } + const QDir temp = QDir(QDir::tempPath()); + temp.rmdir(QLatin1String("test_speed")); + } +private slots: + void baseline() {} + + void sizeSpeed() { + QDir testdir(QDir::tempPath() + QLatin1String("/test_speed")); + QBENCHMARK { + QFileInfoList fileInfoList = testdir.entryInfoList(QDir::Files, QDir::Unsorted); + foreach (const QFileInfo &fileInfo, fileInfoList) { + fileInfo.isDir(); + fileInfo.size(); + } + } + } + void sizeSpeedIterator() { + QDir testdir(QDir::tempPath() + QLatin1String("/test_speed")); + QBENCHMARK { + QDirIterator dit(testdir.path(), QDir::Files); + while (dit.hasNext()) { + dit.next(); + dit.fileInfo().isDir(); + dit.fileInfo().size(); + } + } + } + + void sizeSpeedWithoutFilter() { + QDir testdir(QDir::tempPath() + QLatin1String("/test_speed")); + QBENCHMARK { + QFileInfoList fileInfoList = testdir.entryInfoList(QDir::NoFilter, QDir::Unsorted); + foreach (const QFileInfo &fileInfo, fileInfoList) { + fileInfo.size(); + } + } + } + void sizeSpeedWithoutFilterIterator() { + QDir testdir(QDir::tempPath() + QLatin1String("/test_speed")); + QBENCHMARK { + QDirIterator dit(testdir.path()); + while (dit.hasNext()) { + dit.next(); + dit.fileInfo().isDir(); + dit.fileInfo().size(); + } + } + } + + void sizeSpeedWithoutFileInfoList() { + QDir testdir(QDir::tempPath() + QLatin1String("/test_speed")); + testdir.setSorting(QDir::Unsorted); + QBENCHMARK { + QStringList fileList = testdir.entryList(QDir::NoFilter, QDir::Unsorted); + foreach (const QString &filename, fileList) { + QFileInfo fileInfo(filename); + fileInfo.size(); + } + } + } + + void iDontWantAnyStat() { + QDir testdir(QDir::tempPath() + QLatin1String("/test_speed")); + testdir.setSorting(QDir::Unsorted); + testdir.setFilter(QDir::AllEntries | QDir::System | QDir::Hidden); + QBENCHMARK { + QStringList fileList = testdir.entryList(QDir::NoFilter, QDir::Unsorted); + foreach (const QString &filename, fileList) { + + } + } + } + void iDontWantAnyStatIterator() { + QBENCHMARK { + QDirIterator dit(QDir::tempPath() + QLatin1String("/test_speed")); + while (dit.hasNext()) { + dit.next(); + } + } + } + + void sizeSpeedWithoutFilterLowLevel() { +#ifdef Q_OS_WIN + const wchar_t *dirpath = (wchar_t*)testdir.absolutePath().utf16(); + wchar_t appendedPath[MAX_PATH]; + wcscpy(appendedPath, dirpath); + wcscat(appendedPath, L"\\*"); + + WIN32_FIND_DATA fd; + HANDLE hSearch = FindFirstFileW(appendedPath, &fd); + QVERIFY(hSearch == INVALID_HANDLE_VALUE); + + QBENCHMARK { + do { + + } while (FindNextFile(hSearch, &fd)); + } + FindClose(hSearch); +#else + QDir testdir(QDir::tempPath() + QLatin1String("/test_speed")); + DIR *dir = opendir(qPrintable(testdir.absolutePath())); + QVERIFY(dir); + + QVERIFY(!chdir(qPrintable(testdir.absolutePath()))); + QBENCHMARK { + struct dirent *item = readdir(dir); + while (item) { + char *fileName = item->d_name; + + struct stat fileStat; + QVERIFY(!stat(fileName, &fileStat)); + + item = readdir(dir); + } + } + closedir(dir); +#endif + } +}; + +QTEST_MAIN(bench_QDir_10000) +#include "bench_qdir_10000.moc" diff --git a/tests/benchmarks/corelib/io/qdir/qdir.pro b/tests/benchmarks/corelib/io/qdir/qdir.pro index 2cdebfd..c572566 100644 --- a/tests/benchmarks/corelib/io/qdir/qdir.pro +++ b/tests/benchmarks/corelib/io/qdir/qdir.pro @@ -1,8 +1,2 @@ -load(qttest_p4) -TEMPLATE = app -TARGET = tst_qdir -DEPENDPATH += . -INCLUDEPATH += . - -# Input -SOURCES += tst_qdir.cpp +TEMPLATE = subdirs +SUBDIRS = 10000 diff --git a/tests/benchmarks/corelib/io/qdir/tst_qdir.cpp b/tests/benchmarks/corelib/io/qdir/tst_qdir.cpp deleted file mode 100644 index f2e52d2..0000000 --- a/tests/benchmarks/corelib/io/qdir/tst_qdir.cpp +++ /dev/null @@ -1,198 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 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 module 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 - -#ifdef Q_OS_WIN -# include -#else -# include -# include -# include -# include -#endif - -class Test : public QObject{ - Q_OBJECT -public slots: - void initTestCase() { - QDir testdir = QDir::tempPath(); - - const QString subfolder_name = QLatin1String("test_speed"); - QVERIFY(testdir.mkdir(subfolder_name)); - QVERIFY(testdir.cd(subfolder_name)); - - for (uint i=0; i<10000; ++i) { - QFile file(testdir.absolutePath() + "/testfile_" + QString::number(i)); - file.open(QIODevice::WriteOnly); - } - } - void cleanupTestCase() { - { - QDir testdir(QDir::tempPath() + QLatin1String("/test_speed")); - testdir.setSorting(QDir::Unsorted); - testdir.setFilter(QDir::AllEntries | QDir::System | QDir::Hidden); - foreach (const QString &filename, testdir.entryList()) { - testdir.remove(filename); - } - } - const QDir temp = QDir(QDir::tempPath()); - temp.rmdir(QLatin1String("test_speed")); - } -private slots: - void baseline() {} - - void sizeSpeed() { - QDir testdir(QDir::tempPath() + QLatin1String("/test_speed")); - QBENCHMARK { - QFileInfoList fileInfoList = testdir.entryInfoList(QDir::Files, QDir::Unsorted); - foreach (const QFileInfo &fileInfo, fileInfoList) { - fileInfo.isDir(); - fileInfo.size(); - } - } - } - void sizeSpeedIterator() { - QDir testdir(QDir::tempPath() + QLatin1String("/test_speed")); - QBENCHMARK { - QDirIterator dit(testdir.path(), QDir::Files); - while (dit.hasNext()) { - dit.next(); - dit.fileInfo().isDir(); - dit.fileInfo().size(); - } - } - } - - void sizeSpeedWithoutFilter() { - QDir testdir(QDir::tempPath() + QLatin1String("/test_speed")); - QBENCHMARK { - QFileInfoList fileInfoList = testdir.entryInfoList(QDir::NoFilter, QDir::Unsorted); - foreach (const QFileInfo &fileInfo, fileInfoList) { - fileInfo.size(); - } - } - } - void sizeSpeedWithoutFilterIterator() { - QDir testdir(QDir::tempPath() + QLatin1String("/test_speed")); - QBENCHMARK { - QDirIterator dit(testdir.path()); - while (dit.hasNext()) { - dit.next(); - dit.fileInfo().isDir(); - dit.fileInfo().size(); - } - } - } - - void sizeSpeedWithoutFileInfoList() { - QDir testdir(QDir::tempPath() + QLatin1String("/test_speed")); - testdir.setSorting(QDir::Unsorted); - QBENCHMARK { - QStringList fileList = testdir.entryList(QDir::NoFilter, QDir::Unsorted); - foreach (const QString &filename, fileList) { - QFileInfo fileInfo(filename); - fileInfo.size(); - } - } - } - - void iDontWantAnyStat() { - QDir testdir(QDir::tempPath() + QLatin1String("/test_speed")); - testdir.setSorting(QDir::Unsorted); - testdir.setFilter(QDir::AllEntries | QDir::System | QDir::Hidden); - QBENCHMARK { - QStringList fileList = testdir.entryList(QDir::NoFilter, QDir::Unsorted); - foreach (const QString &filename, fileList) { - - } - } - } - void iDontWantAnyStatIterator() { - QBENCHMARK { - QDirIterator dit(QDir::tempPath() + QLatin1String("/test_speed")); - while (dit.hasNext()) { - dit.next(); - } - } - } - - void sizeSpeedWithoutFilterLowLevel() { -#ifdef Q_OS_WIN - const wchar_t *dirpath = (wchar_t*)testdir.absolutePath().utf16(); - wchar_t appendedPath[MAX_PATH]; - wcscpy(appendedPath, dirpath); - wcscat(appendedPath, L"\\*"); - - WIN32_FIND_DATA fd; - HANDLE hSearch = FindFirstFileW(appendedPath, &fd); - QVERIFY(hSearch == INVALID_HANDLE_VALUE); - - QBENCHMARK { - do { - - } while (FindNextFile(hSearch, &fd)); - } - FindClose(hSearch); -#else - QDir testdir(QDir::tempPath() + QLatin1String("/test_speed")); - DIR *dir = opendir(qPrintable(testdir.absolutePath())); - QVERIFY(dir); - - QVERIFY(!chdir(qPrintable(testdir.absolutePath()))); - QBENCHMARK { - struct dirent *item = readdir(dir); - while (item) { - char *fileName = item->d_name; - - struct stat fileStat; - QVERIFY(!stat(fileName, &fileStat)); - - item = readdir(dir); - } - } - closedir(dir); -#endif - } -}; - -QTEST_MAIN(Test) -#include "tst_qdir.moc" -- cgit v0.12 From 603dc7d659084c5d092de79fec08a0baca8eaa59 Mon Sep 17 00:00:00 2001 From: axis Date: Fri, 19 Feb 2010 09:50:34 +0100 Subject: Revert "Factored epocRoot implementation out of qmake" This reverts commit 13cb80be958c40077245cbc4b36448a661e30c64. It breaks non-Symbian platforms. --- qmake/Makefile.unix | 9 +- qmake/Makefile.win32 | 5 - qmake/Makefile.win32-g++ | 4 - qmake/Makefile.win32-g++-sh | 4 - qmake/generators/symbian/epocroot.h | 51 +++++ .../symbian/initprojectdeploy_symbian.cpp | 96 ++++++++- .../generators/symbian/initprojectdeploy_symbian.h | 2 + qmake/generators/symbian/symmake.cpp | 3 - qmake/generators/symbian/symmake_abld.cpp | 3 - qmake/generators/symbian/symmake_sbsv2.cpp | 3 - qmake/project.cpp | 5 +- qmake/qmake.pri | 6 +- tools/shared/symbian/epocroot.cpp | 230 --------------------- tools/shared/symbian/epocroot.h | 67 ------ 14 files changed, 151 insertions(+), 337 deletions(-) create mode 100644 qmake/generators/symbian/epocroot.h delete mode 100644 tools/shared/symbian/epocroot.cpp delete mode 100644 tools/shared/symbian/epocroot.h diff --git a/qmake/Makefile.unix b/qmake/Makefile.unix index 5469134..e343803 100644 --- a/qmake/Makefile.unix +++ b/qmake/Makefile.unix @@ -11,8 +11,7 @@ OBJS=project.o property.o main.o makefile.o unixmake2.o unixmake.o \ meta.o makefiledeps.o metamakefile.o xmloutput.o pbuilder_pbx.o \ borland_bmake.o msvc_dsp.o msvc_vcproj.o msvc_nmake.o msvc_objectmodel.o \ symmake.o initprojectdeploy_symbian.o symmake_abld.o symmake_sbsv2.o \ - registry.o \ - epocroot.o + registry.o #qt code QOBJS=qtextcodec.o qutfcodec.o qstring.o qtextstream.o qiodevice.o qmalloc.o qglobal.o \ @@ -23,7 +22,6 @@ QOBJS=qtextcodec.o qutfcodec.o qstring.o qtextstream.o qiodevice.o qmalloc.o qgl qmap.o qmetatype.o qsettings.o qlibraryinfo.o qvariant.o qvsnprintf.o \ qlocale.o qlinkedlist.o qurl.o qnumeric.o qcryptographichash.o qxmlstream.o qxmlutils.o \ registry.o \ - epocroot.o \ $(QTOBJS) @@ -37,7 +35,6 @@ DEPEND_SRC=project.cpp property.cpp meta.cpp main.cpp generators/makefile.cpp ge generators/win32/msvc_objectmodel.cpp generators/win32/msvc_nmake.cpp generators/win32/borland_bmake.cpp \ generators/symbian/symmake.cpp generators/symbian/initprojectdeploy_symbian.cpp \ $(SOURCE_PATH)/tools/shared/windows/registry.cpp \ - $(SOURCE_PATH)/tools/shared/symbian/epocroot.cpp \ generators/symbian/symmake_abld.cpp generators/symbian/symmake_sbsv2.cpp \ $(SOURCE_PATH)/src/corelib/codecs/qtextcodec.cpp $(SOURCE_PATH)/src/corelib/codecs/qutfcodec.cpp \ $(SOURCE_PATH)/src/corelib/tools/qstring.cpp $(SOURCE_PATH)/src/corelib/io/qfile.cpp \ @@ -291,9 +288,6 @@ initprojectdeploy_symbian.o: generators/symbian/initprojectdeploy_symbian.cpp registry.o: $(SOURCE_PATH)/tools/shared/windows/registry.cpp $(CXX) -c -o $@ $(CXXFLAGS) $(SOURCE_PATH)/tools/shared/windows/registry.cpp -epocroot.o: $(SOURCE_PATH)/tools/shared/symbian/epocroot.cpp - $(CXX) -c -o $@ $(CXXFLAGS) $(SOURCE_PATH)/tools/shared/symbian/epocroot.cpp - projectgenerator.o: generators/projectgenerator.cpp $(CXX) -c -o $@ $(CXXFLAGS) generators/projectgenerator.cpp @@ -302,7 +296,6 @@ qxmlstream.o: $(SOURCE_PATH)/src/corelib/xml/qxmlstream.cpp qxmlutils.o: $(SOURCE_PATH)/src/corelib/xml/qxmlutils.cpp $(CXX) -c -o $@ $(CXXFLAGS) $(SOURCE_PATH)/src/corelib/xml/qxmlutils.cpp - #default rules .cpp.o: $(CXX) -c -o $@ $(CXXFLAGS) $< diff --git a/qmake/Makefile.win32 b/qmake/Makefile.win32 index 48d84b7..3cd180c 100644 --- a/qmake/Makefile.win32 +++ b/qmake/Makefile.win32 @@ -78,7 +78,6 @@ OBJS = project.obj main.obj makefile.obj unixmake.obj unixmake2.obj mingw borland_bmake.obj msvc_nmake.obj msvc_dsp.obj msvc_vcproj.obj \ msvc_objectmodel.obj symmake.obj initprojectdeploy_symbian.obj \ registry.obj \ - epocroot.obj \ symmake_abld.obj symmake_sbsv2.obj !IFDEF QMAKE_OPENSOURCE_EDITION @@ -203,7 +202,6 @@ clean:: -del symmake_sbsv2.obj -del initprojectdeploy_symbian.obj -del registry.obj - -del epocroot.obj -del pbuilder_pbx.obj -del qxmlstream.obj -del qxmlutils.obj @@ -406,9 +404,6 @@ initprojectdeploy_symbian.obj: $(SOURCE_PATH)/qmake/generators/symbian/initproje registry.obj: $(SOURCE_PATH)/tools/shared/windows/registry.cpp $(CXX) $(CXXFLAGS) $(SOURCE_PATH)/tools/shared/windows/registry.cpp -epocroot.obj: $(SOURCE_PATH)/tools/shared/symbian/epocroot.cpp - $(CXX) $(CXXFLAGS) $(SOURCE_PATH)/tools/shared/symbian/epocroot.cpp - md5.obj: $(SOURCE_PATH)\src\3rdparty\md5\md5.cpp $(CXX) $(CXXFLAGS) $(SOURCE_PATH)\src\3rdparty\md5\md5.cpp diff --git a/qmake/Makefile.win32-g++ b/qmake/Makefile.win32-g++ index 169de3c..ebc7fe2 100644 --- a/qmake/Makefile.win32-g++ +++ b/qmake/Makefile.win32-g++ @@ -40,7 +40,6 @@ OBJS = project.o main.o makefile.o unixmake.o unixmake2.o mingw_make.o \ borland_bmake.o msvc_nmake.o msvc_dsp.o msvc_vcproj.o \ msvc_objectmodel.o symmake.o initprojectdeploy_symbian.o \ registry.o \ - epocroot.o \ symmake_abld.o symmake_sbsv2.o ifdef QMAKE_OPENSOURCE_EDITION @@ -284,9 +283,6 @@ initprojectdeploy_symbian.o: $(SOURCE_PATH)/qmake/generators/symbian/initproject registry.o: $(SOURCE_PATH)/tools/shared/windows/registry.cpp $(CXX) $(CXXFLAGS) $(SOURCE_PATH)/tools/shared/windows/registry.cpp -epocroot.o: $(SOURCE_PATH)/tools/shared/symbian/epocroot.cpp - $(CXX) $(CXXFLAGS) $(SOURCE_PATH)/tools/shared/symbian/epocroot.cpp - project.o: $(SOURCE_PATH)/qmake/project.cpp $(SOURCE_PATH)/qmake/project.h $(SOURCE_PATH)/qmake/option.h $(CXX) $(CXXFLAGS) project.cpp diff --git a/qmake/Makefile.win32-g++-sh b/qmake/Makefile.win32-g++-sh index 98237e7..1d55da2 100644 --- a/qmake/Makefile.win32-g++-sh +++ b/qmake/Makefile.win32-g++-sh @@ -40,7 +40,6 @@ OBJS = project.o main.o makefile.o unixmake.o unixmake2.o mingw_make.o \ borland_bmake.o msvc_nmake.o msvc_dsp.o msvc_vcproj.o \ msvc_objectmodel.o symmake.o initprojectdeploy_symbian.o \ registry.o \ - epocroot.o \ symmake_abld.o symmake_sbsv2.o ifdef QMAKE_OPENSOURCE_EDITION @@ -283,9 +282,6 @@ initprojectdeploy_symbian.o: $(SOURCE_PATH)/qmake/generators/symbian/initproject registry.o: $(SOURCE_PATH)/tools/shared/windows/registry.cpp $(CXX) $(CXXFLAGS) $(SOURCE_PATH)/tools/shared/windows/registry.cpp -epocroot.o: $(SOURCE_PATH)/tools/shared/symbian/epocroot.cpp - $(CXX) $(CXXFLAGS) $(SOURCE_PATH)/tools/shared/symbian/epocroot.cpp - project.o: $(SOURCE_PATH)/qmake/project.cpp $(SOURCE_PATH)/qmake/project.h $(SOURCE_PATH)/qmake/option.h $(CXX) $(CXXFLAGS) project.cpp diff --git a/qmake/generators/symbian/epocroot.h b/qmake/generators/symbian/epocroot.h new file mode 100644 index 0000000..be26438 --- /dev/null +++ b/qmake/generators/symbian/epocroot.h @@ -0,0 +1,51 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the qmake application 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$ +** +****************************************************************************/ + +#ifndef EPOCROOT_H +#define EPOCROOT_H + +#include + +// Implementation of epocRoot method is in initprojectdeploy_symbian.cpp +// Defined in separate header for inclusion clarity +extern QString epocRoot(); + +#endif // EPOCROOT_H diff --git a/qmake/generators/symbian/initprojectdeploy_symbian.cpp b/qmake/generators/symbian/initprojectdeploy_symbian.cpp index 2a22305..5fbff58 100644 --- a/qmake/generators/symbian/initprojectdeploy_symbian.cpp +++ b/qmake/generators/symbian/initprojectdeploy_symbian.cpp @@ -46,15 +46,105 @@ #include #include -// Included from tools/shared -#include - #define SYSBIN_DIR "\\sys\\bin" #define SUFFIX_DLL "dll" #define SUFFIX_EXE "exe" #define SUFFIX_QTPLUGIN "qtplugin" +static void fixEpocRootStr(QString& path) +{ + path.replace("\\", "/"); + + if (path.size() > 1 && path[1] == QChar(':')) { + path = path.mid(2); + } + + if (!path.size() || path[path.size()-1] != QChar('/')) { + path += QChar('/'); + } +} + +#define SYMBIAN_SDKS_KEY "HKEY_LOCAL_MACHINE\\Software\\Symbian\\EPOC SDKs" + +static QString epocRootStr; + +QString epocRoot() +{ + if (!epocRootStr.isEmpty()) { + return epocRootStr; + } + + // First, check the env variable + epocRootStr = qgetenv("EPOCROOT"); + + if (epocRootStr.isEmpty()) { + // No EPOCROOT set, check the default device + // First check EPOCDEVICE env variable + QString defaultDevice = qgetenv("EPOCDEVICE"); + + // Check the windows registry via QSettings for devices.xml path + QSettings settings(SYMBIAN_SDKS_KEY, QSettings::NativeFormat); + QString devicesXmlPath = settings.value("CommonPath").toString(); + + if (!devicesXmlPath.isEmpty()) { + // Parse xml for correct device + devicesXmlPath += "/devices.xml"; + QFile devicesFile(devicesXmlPath); + if (devicesFile.open(QIODevice::ReadOnly)) { + QXmlStreamReader xml(&devicesFile); + while (!xml.atEnd()) { + xml.readNext(); + if (xml.isStartElement() && xml.name() == "devices") { + if (xml.attributes().value("version") == "1.0") { + // Look for correct device + while (!(xml.isEndElement() && xml.name() == "devices") && !xml.atEnd()) { + xml.readNext(); + if (xml.isStartElement() && xml.name() == "device") { + if ((defaultDevice.isEmpty() && xml.attributes().value("default") == "yes") || + (!defaultDevice.isEmpty() && (xml.attributes().value("id").toString() + QString(":") + xml.attributes().value("name").toString()) == defaultDevice)) { + // Found the correct device + while (!(xml.isEndElement() && xml.name() == "device") && !xml.atEnd()) { + xml.readNext(); + if (xml.isStartElement() && xml.name() == "epocroot") { + epocRootStr = xml.readElementText(); + fixEpocRootStr(epocRootStr); + return epocRootStr; + } + } + xml.raiseError("No epocroot element found"); + } + } + } + } else { + xml.raiseError("Invalid 'devices' element version"); + } + } + } + if (xml.hasError()) { + fprintf(stderr, "ERROR: \"%s\" when parsing devices.xml\n", qPrintable(xml.errorString())); + } + } else { + fprintf(stderr, "Could not open devices.xml (%s)\n", qPrintable(devicesXmlPath)); + } + } else { + fprintf(stderr, "Could not retrieve " SYMBIAN_SDKS_KEY " setting\n"); + } + + fprintf(stderr, "Failed to determine epoc root.\n"); + if (!defaultDevice.isEmpty()) + fprintf(stderr, "The device indicated by EPOCDEVICE environment variable (%s) could not be found.\n", qPrintable(defaultDevice)); + fprintf(stderr, "Either set EPOCROOT or EPOCDEVICE environment variable to a valid value, or provide a default Symbian device.\n"); + + // No valid device found; set epocroot to "/" + epocRootStr = QLatin1String("/"); + } + + fixEpocRootStr(epocRootStr); + return epocRootStr; +} + + static bool isPlugin(const QFileInfo& info, const QString& devicePath) { // Libraries are plugins if deployment path is something else than diff --git a/qmake/generators/symbian/initprojectdeploy_symbian.h b/qmake/generators/symbian/initprojectdeploy_symbian.h index b409225..e23e6a9 100644 --- a/qmake/generators/symbian/initprojectdeploy_symbian.h +++ b/qmake/generators/symbian/initprojectdeploy_symbian.h @@ -50,6 +50,8 @@ #include #include +#include "epocroot.h" + #define PLUGIN_STUB_DIR "qmakepluginstubs" struct CopyItem diff --git a/qmake/generators/symbian/symmake.cpp b/qmake/generators/symbian/symmake.cpp index a712434..2055f81 100644 --- a/qmake/generators/symbian/symmake.cpp +++ b/qmake/generators/symbian/symmake.cpp @@ -49,9 +49,6 @@ #include #include -// Included from tools/shared -#include - #define RESOURCE_DIRECTORY_MMP "/resource/apps" #define RESOURCE_DIRECTORY_RESOURCE "\\\\resource\\\\apps\\\\" #define REGISTRATION_RESOURCE_DIRECTORY_HW "/private/10003a3f/import/apps" diff --git a/qmake/generators/symbian/symmake_abld.cpp b/qmake/generators/symbian/symmake_abld.cpp index 6c62412..033bcbe 100644 --- a/qmake/generators/symbian/symmake_abld.cpp +++ b/qmake/generators/symbian/symmake_abld.cpp @@ -48,9 +48,6 @@ #include #include -// Included from tools/shared -#include - #define DO_NOTHING_TARGET "do_nothing" #define CREATE_TEMPS_TARGET "create_temps" #define EXTENSION_CLEAN "extension_clean" diff --git a/qmake/generators/symbian/symmake_sbsv2.cpp b/qmake/generators/symbian/symmake_sbsv2.cpp index 8accfce..e081b19 100644 --- a/qmake/generators/symbian/symmake_sbsv2.cpp +++ b/qmake/generators/symbian/symmake_sbsv2.cpp @@ -48,9 +48,6 @@ #include #include -// Included from tools/shared -#include - SymbianSbsv2MakefileGenerator::SymbianSbsv2MakefileGenerator() : SymbianMakefileGenerator() { } SymbianSbsv2MakefileGenerator::~SymbianSbsv2MakefileGenerator() { } diff --git a/qmake/project.cpp b/qmake/project.cpp index e4ef7dd..4ce8ba4 100644 --- a/qmake/project.cpp +++ b/qmake/project.cpp @@ -44,6 +44,8 @@ #include "option.h" #include "cachekeys.h" +#include "epocroot.h" + #include #include #include @@ -62,9 +64,6 @@ #include #include -// Included from tools/shared -#include - #ifdef Q_OS_WIN32 #define QT_POPEN _popen #define QT_PCLOSE _pclose diff --git a/qmake/qmake.pri b/qmake/qmake.pri index 05debe6..a2ffe15 100644 --- a/qmake/qmake.pri +++ b/qmake/qmake.pri @@ -18,8 +18,7 @@ SOURCES += project.cpp property.cpp main.cpp generators/makefile.cpp \ generators/symbian/symmake_abld.cpp \ generators/symbian/symmake_sbsv2.cpp \ generators/symbian/initprojectdeploy_symbian.cpp \ - windows/registry.cpp \ - symbian/epocroot.cpp + windows/registry.cpp HEADERS += project.h property.h generators/makefile.h \ generators/unix/unixmake.h meta.h option.h cachekeys.h \ @@ -32,8 +31,7 @@ HEADERS += project.h property.h generators/makefile.h \ generators/symbian/symmake_abld.h \ generators/symbian/symmake_sbsv2.h \ generators/symbian/initprojectdeploy_symbian.h \ - windows/registry.h \ - symbian/epocroot.h + windows/registry.h contains(QT_EDITION, OpenSource) { DEFINES += QMAKE_OPENSOURCE_EDITION diff --git a/tools/shared/symbian/epocroot.cpp b/tools/shared/symbian/epocroot.cpp deleted file mode 100644 index 071477d..0000000 --- a/tools/shared/symbian/epocroot.cpp +++ /dev/null @@ -1,230 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the qmake application 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 - -#include "epocroot.h" -#include "../windows/registry.h" - -// Registry key under which the location of the Symbian devices.xml file is -// stored. -// Note that, on 64-bit machines, this key is located under the 32-bit -// compatibility key: -// HKEY_LOCAL_MACHINE\Software\Wow6432Node -#define SYMBIAN_SDKS_REG_SUBKEY "Software\\Symbian\\EPOC SDKs\\CommonPath" - -#ifdef Q_OS_WIN32 -# define SYMBIAN_SDKS_REG_HANDLE HKEY_LOCAL_MACHINE -#else -# define SYMBIAN_SDKS_REG_HANDLE 0 -#endif - -// Value which is populated and returned by the epocRoot() function. -// Stored as a static value in order to avoid unnecessary re-evaluation. -static QString epocRootValue; - -#ifdef QT_BUILD_QMAKE -std::ostream &operator<<(std::ostream &s, const QString &val) { - s << val.toLocal8Bit().data(); - return s; -} -#else -// Operator implemented in configureapp.cpp -std::ostream &operator<<(std::ostream &s, const QString &val); -#endif - -QString getDevicesXmlPath() - { - // Note that the following call will return a null string on platforms other - // than Windows. If support is required on other platforms for devices.xml, - // an alternative mechanism for retrieving the location of this file will - // be required. - return readRegistryKey(SYMBIAN_SDKS_REG_HANDLE, SYMBIAN_SDKS_REG_SUBKEY); - } - -/** - * Checks whether epocRootValue points to an existent directory. - * If not, epocRootValue is set to an empty string and an error message is printed. - */ -void checkEpocRootExists(const QString &source) -{ - if (!epocRootValue.isEmpty()) { - QDir dir(epocRootValue); - if (!dir.exists()) { - std::cerr << "Warning: " << source << " is set to an invalid path: " << epocRootValue << std::endl; - epocRootValue = QString(); - } - } -} - -/** - * Translate path from Windows to Qt format. - */ -static void fixEpocRoot(QString &path) -{ - path.replace("\\", "/"); - - if (path.size() > 1 && path[1] == QChar(':')) { - path = path.mid(2); - } - - if (!path.size() || path[path.size()-1] != QChar('/')) { - path += QChar('/'); - } -} - -/** - * Determine the epoc root for the currently active SDK. - */ -QString epocRoot() -{ - if (epocRootValue.isEmpty()) { - // 1. If environment variable EPOCROOT is set and points to an existent - // directory, this is returned. - epocRootValue = qgetenv("EPOCROOT"); - checkEpocRootExists("EPOCROOT"); - - if (epocRootValue.isEmpty()) { - // 2. The location of devices.xml is specified by a registry key. If this - // file exists, it is parsed. - QString devicesXmlPath = getDevicesXmlPath(); - if (devicesXmlPath.isEmpty()) { - std::cerr << "Error: Symbian SDK registry key not found" << std::endl; - } else { - devicesXmlPath += "/devices.xml"; - QFile devicesFile(devicesXmlPath); - if (devicesFile.open(QIODevice::ReadOnly)) { - - // 3. If the EPOCDEVICE environment variable is set and a corresponding - // entry is found in devices.xml, and its epocroot value points to an - // existent directory, it is returned. - // 4. If a device element marked as default is found in devices.xml and its - // epocroot value points to an existent directory, this is returned. - - const QString epocDeviceValue = qgetenv("EPOCDEVICE"); - bool epocDeviceFound = false; - - QXmlStreamReader xml(&devicesFile); - while (!xml.atEnd()) { - xml.readNext(); - if (xml.isStartElement() && xml.name() == "devices") { - if (xml.attributes().value("version") == "1.0") { - while (!(xml.isEndElement() && xml.name() == "devices") && !xml.atEnd()) { - xml.readNext(); - if (xml.isStartElement() && xml.name() == "device") { - const bool isDefault = xml.attributes().value("default") == "yes"; - const QString id = xml.attributes().value("id").toString(); - const QString name = xml.attributes().value("name").toString(); - const bool epocDeviceMatch = (id + ":" + name) == epocDeviceValue; - epocDeviceFound |= epocDeviceMatch; - - if((epocDeviceValue.isEmpty() && isDefault) || epocDeviceMatch) { - // Found a matching device - while (!(xml.isEndElement() && xml.name() == "device") && !xml.atEnd()) { - xml.readNext(); - if (xml.isStartElement() && xml.name() == "epocroot") { - epocRootValue = xml.readElementText(); - const QString deviceSource = epocDeviceValue.isEmpty() - ? "default device" - : "EPOCDEVICE (" + epocDeviceValue + ")"; - checkEpocRootExists(deviceSource); - } - } - - if (epocRootValue.isEmpty()) - xml.raiseError("No epocroot element found"); - } - } - } - } else { - xml.raiseError("Invalid 'devices' element version"); - } - } - } - if (xml.hasError()) { - std::cerr << "Error: \"" << xml.errorString() << "\" when parsing devices.xml" << std::endl; - } else { - if (epocRootValue.isEmpty()) { - if (!epocDeviceValue.isEmpty()) { - if (epocDeviceFound) { - std::cerr << "Error: missing or invalid epocroot attribute " - << "in device '" << epocDeviceValue << "'"; - } else { - std::cerr << "Error: no device matching EPOCDEVICE (" - << epocDeviceValue << ")"; - } - } else { - if (epocDeviceFound) { - std::cerr << "Error: missing or invalid epocroot attribute " - << "in default device"; - } else { - std::cerr << "Error: no default device"; - } - } - std::cerr << " found in devices.xml file." << std::endl; - } - } - } else { - std::cerr << "Error: could not open file " << devicesXmlPath << std::endl; - } - } - } - - if (epocRootValue.isEmpty()) { - // 5. An empty string is returned. - std::cerr << "Error: failed to find epoc root" << std::endl - << "Either" << std::endl - << " 1. Set EPOCROOT environment variable to a valid value" << std::endl - << " or 2. Ensure that the HKEY_LOCAL_MACHINE\\" SYMBIAN_SDKS_REG_SUBKEY - " registry key is set, and then" << std::endl - << " a. Set EPOCDEVICE environment variable to a valid device" << std::endl - << " or b. Specify a default device in the devices.xml file." << std::endl; - } else { - fixEpocRoot(epocRootValue); - } - } - - return epocRootValue; -} - diff --git a/tools/shared/symbian/epocroot.h b/tools/shared/symbian/epocroot.h deleted file mode 100644 index 9846485..0000000 --- a/tools/shared/symbian/epocroot.h +++ /dev/null @@ -1,67 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the qmake application 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$ -** -****************************************************************************/ - -#ifndef SYMBIAN_EPOCROOT_H -#define SYMBIAN_EPOCROOT_H - -#include - -/** - * Determine the epoc root for the currently active SDK. - * - * The algorithm used is as follows: - * 1. If environment variable EPOCROOT is set and points to an existent - * directory, this is returned. - * 2. The location of devices.xml is specified by a registry key. If this - * file exists, it is parsed. - * 3. If the EPOCDEVICE environment variable is set and a corresponding - * entry is found in devices.xml, and its epocroot value points to an - * existent directory, it is returned. - * 4. If a device element marked as default is found in devices.xml and its - * epocroot value points to an existent directory, this is returned. - * 5. An empty string is returned. - * - * Any return value other than the empty string therefore is guaranteed to - * point to an existent directory. - */ -QString epocRoot(); - -#endif // EPOCROOT_H -- cgit v0.12 From f5309598ddb3bf0f9e3bc182e78f1b2062540c98 Mon Sep 17 00:00:00 2001 From: axis Date: Fri, 19 Feb 2010 09:56:47 +0100 Subject: Revert "Factored readRegistryKey implementation out of qmake" This reverts commit f641369ceb7b7e2f95b9d0656b34c0517c5b95f7. It breaks non-Symbian platforms. --- qmake/Makefile.unix | 9 +- qmake/Makefile.win32 | 7 -- qmake/Makefile.win32-g++ | 5 - qmake/Makefile.win32-g++-sh | 5 - qmake/generators/win32/msvc_vcproj.cpp | 97 +++++++++++++++++++- qmake/qmake.pri | 7 +- qmake/qmake.pro | 4 - tools/shared/windows/registry.cpp | 161 --------------------------------- tools/shared/windows/registry.h | 64 ------------- 9 files changed, 100 insertions(+), 259 deletions(-) delete mode 100644 tools/shared/windows/registry.cpp delete mode 100644 tools/shared/windows/registry.h diff --git a/qmake/Makefile.unix b/qmake/Makefile.unix index e343803..fcf43c8 100644 --- a/qmake/Makefile.unix +++ b/qmake/Makefile.unix @@ -10,8 +10,7 @@ OBJS=project.o property.o main.o makefile.o unixmake2.o unixmake.o \ mingw_make.o option.o winmakefile.o projectgenerator.o \ meta.o makefiledeps.o metamakefile.o xmloutput.o pbuilder_pbx.o \ borland_bmake.o msvc_dsp.o msvc_vcproj.o msvc_nmake.o msvc_objectmodel.o \ - symmake.o initprojectdeploy_symbian.o symmake_abld.o symmake_sbsv2.o \ - registry.o + symmake.o initprojectdeploy_symbian.o symmake_abld.o symmake_sbsv2.o #qt code QOBJS=qtextcodec.o qutfcodec.o qstring.o qtextstream.o qiodevice.o qmalloc.o qglobal.o \ @@ -21,7 +20,6 @@ QOBJS=qtextcodec.o qutfcodec.o qstring.o qtextstream.o qiodevice.o qmalloc.o qgl qfileinfo.o qdatetime.o qstringlist.o qabstractfileengine.o qtemporaryfile.o \ qmap.o qmetatype.o qsettings.o qlibraryinfo.o qvariant.o qvsnprintf.o \ qlocale.o qlinkedlist.o qurl.o qnumeric.o qcryptographichash.o qxmlstream.o qxmlutils.o \ - registry.o \ $(QTOBJS) @@ -34,7 +32,6 @@ DEPEND_SRC=project.cpp property.cpp meta.cpp main.cpp generators/makefile.cpp ge generators/makefiledeps.cpp option.cpp generators/win32/mingw_make.cpp generators/makefile.cpp \ generators/win32/msvc_objectmodel.cpp generators/win32/msvc_nmake.cpp generators/win32/borland_bmake.cpp \ generators/symbian/symmake.cpp generators/symbian/initprojectdeploy_symbian.cpp \ - $(SOURCE_PATH)/tools/shared/windows/registry.cpp \ generators/symbian/symmake_abld.cpp generators/symbian/symmake_sbsv2.cpp \ $(SOURCE_PATH)/src/corelib/codecs/qtextcodec.cpp $(SOURCE_PATH)/src/corelib/codecs/qutfcodec.cpp \ $(SOURCE_PATH)/src/corelib/tools/qstring.cpp $(SOURCE_PATH)/src/corelib/io/qfile.cpp \ @@ -65,7 +62,6 @@ DEPEND_SRC=project.cpp property.cpp meta.cpp main.cpp generators/makefile.cpp ge CPPFLAGS = -I. -Igenerators -Igenerators/unix -Igenerators/win32 -Igenerators/mac -Igenerators/symbian \ -I$(BUILD_PATH)/include -I$(BUILD_PATH)/include/QtCore \ -I$(BUILD_PATH)/src/corelib/global -I$(BUILD_PATH)/src/corelib/xml \ - -I$(BUILD_PATH)/tools/shared \ -DQT_NO_PCRE \ -DQT_BUILD_QMAKE -DQT_BOOTSTRAPPED \ -DQT_NO_TEXTCODEC -DQT_NO_UNICODETABLES -DQT_NO_COMPONENT -DQT_NO_STL \ @@ -285,9 +281,6 @@ symmake_sbsv2.o: generators/symbian/symmake_sbsv2.cpp initprojectdeploy_symbian.o: generators/symbian/initprojectdeploy_symbian.cpp $(CXX) -c -o $@ $(CXXFLAGS) generators/symbian/initprojectdeploy_symbian.cpp -registry.o: $(SOURCE_PATH)/tools/shared/windows/registry.cpp - $(CXX) -c -o $@ $(CXXFLAGS) $(SOURCE_PATH)/tools/shared/windows/registry.cpp - projectgenerator.o: generators/projectgenerator.cpp $(CXX) -c -o $@ $(CXXFLAGS) generators/projectgenerator.cpp diff --git a/qmake/Makefile.win32 b/qmake/Makefile.win32 index 3cd180c..e6bbcd5 100644 --- a/qmake/Makefile.win32 +++ b/qmake/Makefile.win32 @@ -34,7 +34,6 @@ CFLAGS = -c -Fo$@ \ -I$(BUILD_PATH)\src\corelib\global \ -I$(BUILD_PATH)\src\corelib\xml \ -I$(SOURCE_PATH)\mkspecs\$(QMAKESPEC) \ - -I$(SOURCE_PATH)\tools\shared \ -DQT_NO_TEXTCODEC -DQT_NO_UNICODETABLES -DQT_LITE_COMPONENT -DQT_NODLL -DQT_NO_STL \ -DQT_NO_COMPRESS -DUNICODE -DHAVE_QCONFIG_CPP -DQT_BUILD_QMAKE -DQT_NO_THREAD \ -DQT_NO_QOBJECT -DQT_NO_GEOM_VARIANT -DQT_NO_DATASTREAM -DQT_NO_PCRE -DQT_BOOTSTRAPPED \ @@ -60,7 +59,6 @@ CFLAGS = -c -o$@ \ -I$(SOURCE_PATH)\include -I$(SOURCE_PATH)\include\QtCore \ -I$(BUILD_PATH)\src\corelib\global \ -I$(SOURCE_PATH)\mkspecs\$(QMAKESPEC) \ - -I$(SOURCE_PATH)\tools\shared \ -DQT_NO_TEXTCODEC -DQT_NO_UNICODETABLES -DQT_LITE_COMPONENT -DQT_NODLL -DQT_NO_STL \ -DQT_NO_COMPRESS -DUNICODE -DHAVE_QCONFIG_CPP -DQT_BUILD_QMAKE -DQT_NO_THREAD \ -DQT_NO_QOBJECT -DQT_NO_GEOM_VARIANT @@ -77,7 +75,6 @@ OBJS = project.obj main.obj makefile.obj unixmake.obj unixmake2.obj mingw makefiledeps.obj metamakefile.obj xmloutput.obj pbuilder_pbx.obj \ borland_bmake.obj msvc_nmake.obj msvc_dsp.obj msvc_vcproj.obj \ msvc_objectmodel.obj symmake.obj initprojectdeploy_symbian.obj \ - registry.obj \ symmake_abld.obj symmake_sbsv2.obj !IFDEF QMAKE_OPENSOURCE_EDITION @@ -201,7 +198,6 @@ clean:: -del symmake_abld.obj -del symmake_sbsv2.obj -del initprojectdeploy_symbian.obj - -del registry.obj -del pbuilder_pbx.obj -del qxmlstream.obj -del qxmlutils.obj @@ -401,9 +397,6 @@ symmake_sbsv2.obj: $(SOURCE_PATH)/qmake/generators/symbian/symmake_sbsv2.cpp initprojectdeploy_symbian.obj: $(SOURCE_PATH)/qmake/generators/symbian/initprojectdeploy_symbian.cpp $(CXX) $(CXXFLAGS) generators/symbian/initprojectdeploy_symbian.cpp -registry.obj: $(SOURCE_PATH)/tools/shared/windows/registry.cpp - $(CXX) $(CXXFLAGS) $(SOURCE_PATH)/tools/shared/windows/registry.cpp - md5.obj: $(SOURCE_PATH)\src\3rdparty\md5\md5.cpp $(CXX) $(CXXFLAGS) $(SOURCE_PATH)\src\3rdparty\md5\md5.cpp diff --git a/qmake/Makefile.win32-g++ b/qmake/Makefile.win32-g++ index ebc7fe2..ade379b 100644 --- a/qmake/Makefile.win32-g++ +++ b/qmake/Makefile.win32-g++ @@ -21,7 +21,6 @@ CFLAGS = -c -o$@ -O \ -I$(BUILD_PATH)/src/corelib/global \ -I$(BUILD_PATH)/src/corelib/xml \ -I$(SOURCE_PATH)/mkspecs/win32-g++ \ - -I$(SOURCE_PATH)/tools/shared \ -DQT_NO_TEXTCODEC -DQT_NO_UNICODETABLES -DQT_LITE_COMPONENT -DQT_NO_PCRE \ -DQT_NODLL -DQT_NO_STL -DQT_NO_COMPRESS -DUNICODE -DHAVE_QCONFIG_CPP \ -DQT_BUILD_QMAKE -DQT_NO_THREAD -DQT_NO_QOBJECT -DQT_NO_GEOM_VARIANT -DQT_NO_DATASTREAM \ @@ -39,7 +38,6 @@ OBJS = project.o main.o makefile.o unixmake.o unixmake2.o mingw_make.o \ makefiledeps.o metamakefile.o xmloutput.o pbuilder_pbx.o \ borland_bmake.o msvc_nmake.o msvc_dsp.o msvc_vcproj.o \ msvc_objectmodel.o symmake.o initprojectdeploy_symbian.o \ - registry.o \ symmake_abld.o symmake_sbsv2.o ifdef QMAKE_OPENSOURCE_EDITION @@ -280,9 +278,6 @@ symmake_sbsv2.o: $(SOURCE_PATH)/qmake/generators/symbian/symmake_sbsv2.cpp initprojectdeploy_symbian.o: $(SOURCE_PATH)/qmake/generators/symbian/initprojectdeploy_symbian.cpp $(CXX) $(CXXFLAGS) generators/symbian/initprojectdeploy_symbian.cpp -registry.o: $(SOURCE_PATH)/tools/shared/windows/registry.cpp - $(CXX) $(CXXFLAGS) $(SOURCE_PATH)/tools/shared/windows/registry.cpp - project.o: $(SOURCE_PATH)/qmake/project.cpp $(SOURCE_PATH)/qmake/project.h $(SOURCE_PATH)/qmake/option.h $(CXX) $(CXXFLAGS) project.cpp diff --git a/qmake/Makefile.win32-g++-sh b/qmake/Makefile.win32-g++-sh index 1d55da2..8d2723c 100644 --- a/qmake/Makefile.win32-g++-sh +++ b/qmake/Makefile.win32-g++-sh @@ -21,7 +21,6 @@ CFLAGS = -c -o$@ -O \ -I$(BUILD_PATH)/src/corelib/global \ -I$(BUILD_PATH)/src/corelib/xml \ -I$(SOURCE_PATH)/mkspecs/win32-g++ \ - -I$(SOURCE_PATH)/tools/shared \ -DQT_NO_TEXTCODEC -DQT_NO_UNICODETABLES -DQT_LITE_COMPONENT -DQT_NO_PCRE \ -DQT_NODLL -DQT_NO_STL -DQT_NO_COMPRESS -DUNICODE -DHAVE_QCONFIG_CPP \ -DQT_BUILD_QMAKE -DQT_NO_THREAD -DQT_NO_QOBJECT -DQT_NO_GEOM_VARIANT -DQT_NO_DATASTREAM \ @@ -39,7 +38,6 @@ OBJS = project.o main.o makefile.o unixmake.o unixmake2.o mingw_make.o \ makefiledeps.o metamakefile.o xmloutput.o pbuilder_pbx.o \ borland_bmake.o msvc_nmake.o msvc_dsp.o msvc_vcproj.o \ msvc_objectmodel.o symmake.o initprojectdeploy_symbian.o \ - registry.o \ symmake_abld.o symmake_sbsv2.o ifdef QMAKE_OPENSOURCE_EDITION @@ -279,9 +277,6 @@ symmake_sbsv2.o: $(SOURCE_PATH)/qmake/generators/symbian/symmake_sbsv2.cpp initprojectdeploy_symbian.o: $(SOURCE_PATH)/qmake/generators/symbian/initprojectdeploy_symbian.cpp $(CXX) $(CXXFLAGS) generators/symbian/initprojectdeploy_symbian.cpp -registry.o: $(SOURCE_PATH)/tools/shared/windows/registry.cpp - $(CXX) $(CXXFLAGS) $(SOURCE_PATH)/tools/shared/windows/registry.cpp - project.o: $(SOURCE_PATH)/qmake/project.cpp $(SOURCE_PATH)/qmake/project.h $(SOURCE_PATH)/qmake/option.h $(CXX) $(CXXFLAGS) project.cpp diff --git a/qmake/generators/win32/msvc_vcproj.cpp b/qmake/generators/win32/msvc_vcproj.cpp index 58f95e9..47986f5 100644 --- a/qmake/generators/win32/msvc_vcproj.cpp +++ b/qmake/generators/win32/msvc_vcproj.cpp @@ -67,7 +67,6 @@ QT_END_NAMESPACE #ifdef Q_OS_WIN32 #include -#include QT_BEGIN_NAMESPACE @@ -94,6 +93,102 @@ struct { {NETUnknown, "", ""}, }; +static QString keyPath(const QString &rKey) +{ + int idx = rKey.lastIndexOf(QLatin1Char('\\')); + if (idx == -1) + return QString(); + return rKey.left(idx + 1); +} + +static QString keyName(const QString &rKey) +{ + int idx = rKey.lastIndexOf(QLatin1Char('\\')); + if (idx == -1) + return rKey; + + QString res(rKey.mid(idx + 1)); + if (res == "Default" || res == ".") + res = ""; + return res; +} + +static QString readRegistryKey(HKEY parentHandle, const QString &rSubkey) +{ + + QString rSubkeyName = keyName(rSubkey); + QString rSubkeyPath = keyPath(rSubkey); + + HKEY handle = 0; + LONG res = RegOpenKeyEx(parentHandle, (wchar_t*)rSubkeyPath.utf16(), 0, KEY_READ, &handle); + + if (res != ERROR_SUCCESS) + return QString(); + + // get the size and type of the value + DWORD dataType; + DWORD dataSize; + res = RegQueryValueEx(handle, (wchar_t*)rSubkeyName.utf16(), 0, &dataType, 0, &dataSize); + if (res != ERROR_SUCCESS) { + RegCloseKey(handle); + return QString(); + } + + // get the value + QByteArray data(dataSize, 0); + res = RegQueryValueEx(handle, (wchar_t*)rSubkeyName.utf16(), 0, 0, + reinterpret_cast(data.data()), &dataSize); + if (res != ERROR_SUCCESS) { + RegCloseKey(handle); + return QString(); + } + + QString result; + switch (dataType) { + case REG_EXPAND_SZ: + case REG_SZ: { + result = QString::fromWCharArray(((const wchar_t *)data.constData())); + break; + } + + case REG_MULTI_SZ: { + QStringList l; + int i = 0; + for (;;) { + QString s = QString::fromWCharArray((const wchar_t *)data.constData() + i); + i += s.length() + 1; + + if (s.isEmpty()) + break; + l.append(s); + } + result = l.join(", "); + break; + } + + case REG_NONE: + case REG_BINARY: { + result = QString::fromWCharArray((const wchar_t *)data.constData(), data.size() / 2); + break; + } + + case REG_DWORD_BIG_ENDIAN: + case REG_DWORD: { + Q_ASSERT(data.size() == sizeof(int)); + int i; + memcpy((char*)&i, data.constData(), sizeof(int)); + result = QString::number(i); + break; + } + + default: + qWarning("QSettings: unknown data %d type in windows registry", dataType); + break; + } + + RegCloseKey(handle); + return result; +} QT_END_NAMESPACE #endif diff --git a/qmake/qmake.pri b/qmake/qmake.pri index a2ffe15..efe4f36 100644 --- a/qmake/qmake.pri +++ b/qmake/qmake.pri @@ -17,8 +17,7 @@ SOURCES += project.cpp property.cpp main.cpp generators/makefile.cpp \ generators/symbian/symmake.cpp \ generators/symbian/symmake_abld.cpp \ generators/symbian/symmake_sbsv2.cpp \ - generators/symbian/initprojectdeploy_symbian.cpp \ - windows/registry.cpp + generators/symbian/initprojectdeploy_symbian.cpp HEADERS += project.h property.h generators/makefile.h \ generators/unix/unixmake.h meta.h option.h cachekeys.h \ @@ -30,8 +29,8 @@ HEADERS += project.h property.h generators/makefile.h \ generators/symbian/symmake.h \ generators/symbian/symmake_abld.h \ generators/symbian/symmake_sbsv2.h \ - generators/symbian/initprojectdeploy_symbian.h \ - windows/registry.h + generators/symbian/epocroot.h \ + generators/symbian/initprojectdeploy_symbian.h contains(QT_EDITION, OpenSource) { DEFINES += QMAKE_OPENSOURCE_EDITION diff --git a/qmake/qmake.pro b/qmake/qmake.pro index f3f9d53..00dcbce 100644 --- a/qmake/qmake.pro +++ b/qmake/qmake.pro @@ -27,9 +27,5 @@ INCPATH += generators \ $$QT_SOURCE_TREE/include \ $$QT_SOURCE_TREE/include/QtCore \ $$QT_SOURCE_TREE/qmake - -VPATH += $$QT_SOURCE_TREE/tools/shared -INCPATH += $$QT_SOURCE_TREE/tools/shared - include(qmake.pri) diff --git a/tools/shared/windows/registry.cpp b/tools/shared/windows/registry.cpp deleted file mode 100644 index d342d78..0000000 --- a/tools/shared/windows/registry.cpp +++ /dev/null @@ -1,161 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the qmake application 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 "registry.h" - -/*! - Returns the path part of a registry key. - e.g. - For a key - "Software\\Microsoft\\VisualStudio\\8.0\\Setup\\VC\\ProductDir" - it returns - "Software\\Microsoft\\VisualStudio\\8.0\\Setup\\VC\\" -*/ -static QString keyPath(const QString &rKey) -{ - int idx = rKey.lastIndexOf(QLatin1Char('\\')); - if (idx == -1) - return QString(); - return rKey.left(idx + 1); -} - -/*! - Returns the name part of a registry key. - e.g. - For a key - "Software\\Microsoft\\VisualStudio\\8.0\\Setup\\VC\\ProductDir" - it returns - "ProductDir" -*/ -static QString keyName(const QString &rKey) -{ - int idx = rKey.lastIndexOf(QLatin1Char('\\')); - if (idx == -1) - return rKey; - - QString res(rKey.mid(idx + 1)); - if (res == "Default" || res == ".") - res = ""; - return res; -} - -QString readRegistryKey(HKEY parentHandle, const QString &rSubkey) -{ - QString result; - -#ifdef Q_OS_WIN32 - QString rSubkeyName = keyName(rSubkey); - QString rSubkeyPath = keyPath(rSubkey); - - HKEY handle = 0; - LONG res = RegOpenKeyEx(parentHandle, (wchar_t*)rSubkeyPath.utf16(), 0, KEY_READ, &handle); - - if (res != ERROR_SUCCESS) - return QString(); - - // get the size and type of the value - DWORD dataType; - DWORD dataSize; - res = RegQueryValueEx(handle, (wchar_t*)rSubkeyName.utf16(), 0, &dataType, 0, &dataSize); - if (res != ERROR_SUCCESS) { - RegCloseKey(handle); - return QString(); - } - - // get the value - QByteArray data(dataSize, 0); - res = RegQueryValueEx(handle, (wchar_t*)rSubkeyName.utf16(), 0, 0, - reinterpret_cast(data.data()), &dataSize); - if (res != ERROR_SUCCESS) { - RegCloseKey(handle); - return QString(); - } - - switch (dataType) { - case REG_EXPAND_SZ: - case REG_SZ: { - result = QString::fromWCharArray(((const wchar_t *)data.constData())); - break; - } - - case REG_MULTI_SZ: { - QStringList l; - int i = 0; - for (;;) { - QString s = QString::fromWCharArray((const wchar_t *)data.constData() + i); - i += s.length() + 1; - - if (s.isEmpty()) - break; - l.append(s); - } - result = l.join(", "); - break; - } - - case REG_NONE: - case REG_BINARY: { - result = QString::fromWCharArray((const wchar_t *)data.constData(), data.size() / 2); - break; - } - - case REG_DWORD_BIG_ENDIAN: - case REG_DWORD: { - Q_ASSERT(data.size() == sizeof(int)); - int i; - memcpy((char*)&i, data.constData(), sizeof(int)); - result = QString::number(i); - break; - } - - default: - qWarning("QSettings: unknown data %d type in windows registry", dataType); - break; - } - - RegCloseKey(handle); -#endif - - return result; -} - - diff --git a/tools/shared/windows/registry.h b/tools/shared/windows/registry.h deleted file mode 100644 index 3896527..0000000 --- a/tools/shared/windows/registry.h +++ /dev/null @@ -1,64 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the qmake application 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$ -** -****************************************************************************/ - -#ifndef WINDOWS_REGISTRY_H -#define WINDOWS_REGISTRY_H - -#include - -#ifdef Q_OS_WIN32 - #include -#else - typedef void* HKEY; -#endif - -#include - -/** - * Read a value from the Windows registry. - * - * If the key is not found, or the registry cannot be accessed (for example - * if this code is compiled for a platform other than Windows), a null - * string is returned. - */ -QString readRegistryKey(HKEY parentHandle, const QString &rSubkey); - -#endif // WINDOWS_REGISTRY_H -- cgit v0.12 From 868a8d5d80f9e455e68c71522c6a710345c2d9fa Mon Sep 17 00:00:00 2001 From: Sami Merila Date: Fri, 19 Feb 2010 10:58:13 +0200 Subject: Virtual keyboard can't be closed anymore after tapping the text area On Symbian^3, the virtual keyboard cannot be closed anymore when the editor area where the text is displayed is tapped and autocompletion is suggesting a word currently. This is caused by the fragile native FEP manager which assumes that client must report certain event (EAknCursorPositionChanged), after user interaction with the editor area. Otherwise the native FEP manager is in dead-lock, until somebody reports this event to it. Task-number: QTBUG-7828 Reviewed-by: axis --- src/gui/inputmethod/qcoefepinputcontext_s60.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/gui/inputmethod/qcoefepinputcontext_s60.cpp b/src/gui/inputmethod/qcoefepinputcontext_s60.cpp index 2b91711..1ac8ace 100644 --- a/src/gui/inputmethod/qcoefepinputcontext_s60.cpp +++ b/src/gui/inputmethod/qcoefepinputcontext_s60.cpp @@ -113,7 +113,7 @@ void QCoeFepInputContext::update() updateHints(false); // For pre-5.0 SDKs, we don't do text updates on S60 side. - if (QSysInfo::s60Version() != QSysInfo::SV_S60_5_0) { + if (QSysInfo::s60Version() < QSysInfo::SV_S60_5_0) { return; } @@ -740,6 +740,9 @@ void QCoeFepInputContext::GetScreenCoordinatesForFepL(TPoint& aLeftSideOfBaseLin void QCoeFepInputContext::DoCommitFepInlineEditL() { commitCurrentString(false); + if (QSysInfo::s60Version() > QSysInfo::SV_S60_5_0) + ReportAknEdStateEvent(QT_EAknCursorPositionChanged); + } void QCoeFepInputContext::commitCurrentString(bool cancelFepTransaction) -- cgit v0.12 From db0057534835356f5c471f3e0f32fad30e32becb Mon Sep 17 00:00:00 2001 From: Sami Merila Date: Fri, 19 Feb 2010 11:43:35 +0200 Subject: ColorDialog is always shown as stripped-down version (for QVGA) QColorDialog creates own instance of S60Data and fetches touch support value from that. Unfortunately, newly created S60Data is populated with default values that claim no support for touch. As a fix, QColorDialog uses the global variable "S60" to fetch touch support information. Task-number: QTBUG-8322 Reviewed-by: Shane Kearns --- src/gui/dialogs/qcolordialog.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/gui/dialogs/qcolordialog.cpp b/src/gui/dialogs/qcolordialog.cpp index 83ecc30..e6abf7f 100644 --- a/src/gui/dialogs/qcolordialog.cpp +++ b/src/gui/dialogs/qcolordialog.cpp @@ -1078,8 +1078,7 @@ QColorShower::QColorShower(QColorDialog *parent) #ifdef QT_SMALL_COLORDIALOG # ifdef Q_WS_S60 - QS60Data s60Data = QS60Data(); - const bool nonTouchUI = !s60Data.hasTouchscreen; + const bool nonTouchUI = !S60->hasTouchscreen; # elif defined Q_WS_MAEMO_5 const bool nonTouchUI = false; # endif @@ -1506,8 +1505,7 @@ void QColorDialogPrivate::init(const QColor &initial) #if defined(QT_SMALL_COLORDIALOG) # if defined(Q_WS_S60) - QS60Data s60Data = QS60Data(); - const bool nonTouchUI = !s60Data.hasTouchscreen; + const bool nonTouchUI = !S60->hasTouchscreen; # elif defined(Q_WS_MAEMO_5) const bool nonTouchUI = false; # endif -- cgit v0.12 From 254676322463778319e4a1b572d6c76f9c256393 Mon Sep 17 00:00:00 2001 From: ninerider Date: Fri, 19 Feb 2010 10:48:27 +0100 Subject: Remote lib extensions for Windows Mobile device power operations. Function to change the power mode and to reset the device were added. The reset is needed to put the device in a defined state after an error has occurred. The unattended power mode ensures that the reset can be effected and that the device will not go to sleep. Reviewed by: Joerg --- tools/qtestlib/wince/remotelib/commands.cpp | 86 +++++++++++++++++++++++++++++ tools/qtestlib/wince/remotelib/commands.h | 3 + 2 files changed, 89 insertions(+) diff --git a/tools/qtestlib/wince/remotelib/commands.cpp b/tools/qtestlib/wince/remotelib/commands.cpp index 4244424..88bf9e6 100644 --- a/tools/qtestlib/wince/remotelib/commands.cpp +++ b/tools/qtestlib/wince/remotelib/commands.cpp @@ -39,6 +39,9 @@ ** ****************************************************************************/ #include "commands.h" +#include +#include + #define CLEAN_FAIL(a) {delete appName; \ delete arguments; \ @@ -124,3 +127,86 @@ bool qRemoteExecute(const wchar_t* program, const wchar_t* arguments, int *retur } return true; } +/** +\brief Reset the device. +*/ +int qRemoteSoftReset(DWORD, BYTE*, DWORD*, BYTE**, IRAPIStream* stream) +{ + //POWER_STATE_ON On state + //POWER_STATE_OFF Off state + //POWER_STATE_CRITICAL Critical state + //POWER_STATE_BOOT Boot state + //POWER_STATE_IDLE Idle state + //POWER_STATE_SUSPEND Suspend state + //POWER_STATE_RESET Reset state + + DWORD returnValue = SetSystemPowerState(0, POWER_STATE_RESET, POWER_FORCE); + return returnValue; +} + +/** +\brief Toggle the unattended powermode of the device +*/ +int qRemoteToggleUnattendedPowerMode(DWORD, BYTE*, DWORD*, BYTE**, IRAPIStream* stream) +{ + if (!stream) + return -1; + + DWORD bytesRead; + int toggleVal = 0; + int returnValue = S_OK; + + if (S_OK != stream->Read(&toggleVal, sizeof(toggleVal), &bytesRead)) + return -2; + + //PPN_REEVALUATESTATE 0x0001 Reserved. Set dwData to zero (0). + //PPN_POWERCHANGE 0x0002 Reserved. Set dwData to zero (0). + //PPN_UNATTENDEDMODE 0x0003 Set dwData to TRUE or FALSE. + //PPN_SUSPENDKEYPRESSED or + //PPN_POWERBUTTONPRESSED 0x0004 Reserved. Set dwData to zero (0). + //PPN_SUSPENDKEYRELEASED 0x0005 Reserved. Set dwData to zero (0). + //PPN_APPBUTTONPRESSED 0x0006 Reserved. Set dwData to zero (0). + //PPN_OEMBASE Greater than or equal to 0x10000 + //You can define higher values, such as 0x10001, 0x10002, and so on. + // Reserved. Set dwData to zero (0). + returnValue = PowerPolicyNotify(PPN_UNATTENDEDMODE, toggleVal); + + if (S_OK != stream->Write(&returnValue, sizeof(returnValue), &bytesRead)) + return -3; + else + return S_OK; +} + +/** +\brief Virtually press the power button of the device +*/ +int qRemotePowerButton(DWORD, BYTE*, DWORD*, BYTE**, IRAPIStream* stream) +{ + if (!stream) + return -1; + + DWORD bytesRead; + int toggleVal = 0; + int returnValue = S_OK; + + if (S_OK != stream->Read(&toggleVal, sizeof(toggleVal), &bytesRead)) + return -2; + + //PPN_REEVALUATESTATE 0x0001 Reserved. Set dwData to zero (0). + //PPN_POWERCHANGE 0x0002 Reserved. Set dwData to zero (0). + //PPN_UNATTENDEDMODE 0x0003 Set dwData to TRUE or FALSE. + //PPN_SUSPENDKEYPRESSED or + //PPN_POWERBUTTONPRESSED 0x0004 Reserved. Set dwData to zero (0). + //PPN_SUSPENDKEYRELEASED 0x0005 Reserved. Set dwData to zero (0). + //PPN_APPBUTTONPRESSED 0x0006 Reserved. Set dwData to zero (0). + //PPN_OEMBASE Greater than or equal to 0x10000 + //You can define higher values, such as 0x10001, 0x10002, and so on. + // Reserved. Set dwData to zero (0). + returnValue = PowerPolicyNotify(PPN_POWERBUTTONPRESSED, 0); + + if (S_OK != stream->Write(&returnValue, sizeof(returnValue), &bytesRead)) + return -3; + else + return S_OK; +} + diff --git a/tools/qtestlib/wince/remotelib/commands.h b/tools/qtestlib/wince/remotelib/commands.h index c5cc926..8f202c8 100644 --- a/tools/qtestlib/wince/remotelib/commands.h +++ b/tools/qtestlib/wince/remotelib/commands.h @@ -45,6 +45,9 @@ extern "C" { int __declspec(dllexport) qRemoteLaunch(DWORD, BYTE*, DWORD*, BYTE**, IRAPIStream*); + int __declspec(dllexport) qRemoteSoftReset(DWORD, BYTE*, DWORD*, BYTE**, IRAPIStream* stream); + int __declspec(dllexport) qRemoteToggleUnattendedPowerMode(DWORD, BYTE*, DWORD*, BYTE**, IRAPIStream* stream); + int __declspec(dllexport) qRemotePowerButton(DWORD, BYTE*, DWORD*, BYTE**, IRAPIStream* stream); bool __declspec(dllexport) qRemoteExecute(const wchar_t* program, const wchar_t* arguments = NULL, int *returnValue = NULL , DWORD* error = NULL, int timeout = -1); } -- cgit v0.12 From 1d75abb9a481b058f5251b83446aa0e171217786 Mon Sep 17 00:00:00 2001 From: ninerider Date: Fri, 19 Feb 2010 10:50:47 +0100 Subject: Cetest extensions for Windows Mobile device power operations. Options to reset (-reset) and change the power mode (-wake) of the device were added. The reset is needed to put the device in a defined state after an error has occurred. The unattended power mode ensures that the reset can be effected and that the device will not go to sleep. Reviewed by: Joerg --- .../qtestlib/wince/cetest/activesyncconnection.cpp | 139 +++++++++++++++++++++ tools/qtestlib/wince/cetest/activesyncconnection.h | 3 + tools/qtestlib/wince/cetest/main.cpp | 48 +++++++ 3 files changed, 190 insertions(+) diff --git a/tools/qtestlib/wince/cetest/activesyncconnection.cpp b/tools/qtestlib/wince/cetest/activesyncconnection.cpp index 56fb173..98062ed 100644 --- a/tools/qtestlib/wince/cetest/activesyncconnection.cpp +++ b/tools/qtestlib/wince/cetest/activesyncconnection.cpp @@ -443,6 +443,145 @@ bool ActiveSyncConnection::execute(QString program, QString arguments, int timeo return result; } +bool ActiveSyncConnection::setDeviceAwake(bool activate, int *returnValue) +{ + if (!isConnected()) { + qWarning("Cannot execute, connect to device first!"); + return false; + } + bool result = false; + + // If we want to wait, we have to use CeRapiInvoke, as CeCreateProcess has no way to wait + // until the process ends. The lib must have been build and also deployed already. + if (!isConnected() && !connect()) + return false; + + HRESULT res = S_OK; + + //SYSTEM_POWER_STATUS_EX systemPowerState; + + //res = CeGetSystemPowerStatusEx(&systemPowerState, true); + + QString dllLocation = "\\Windows\\QtRemote.dll"; + QString functionName = "qRemoteToggleUnattendedPowerMode"; + + DWORD outputSize; + BYTE* output; + IRAPIStream *stream; + int returned = 0; + int toggle = int(activate); + + res = CeRapiInvoke(dllLocation.utf16(), functionName.utf16(), 0, 0, &outputSize, &output, &stream, 0); + if (S_OK != res) { + DWORD ce_error = CeGetLastError(); + if (S_OK != ce_error) { + qWarning("Error invoking %s on %s: %s", qPrintable(functionName), + qPrintable(dllLocation), strwinerror(ce_error).constData()); + } else { + qWarning("Error: %s on %s unexpectedly returned %d", qPrintable(functionName), + qPrintable(dllLocation), res); + } + } else { + DWORD written; + + if (S_OK != stream->Write(&toggle, sizeof(toggle), &written)) { + qWarning(" Could not write toggle option to process"); + return false; + } + + if (S_OK != stream->Read(&returned, sizeof(returned), &written)) { + qWarning(" Could not access return value of process"); + } + else + result = true; + } + + if (returnValue) + *returnValue = returned; + + return result; +} + +bool ActiveSyncConnection::resetDevice() +{ + if (!isConnected()) { + qWarning("Cannot execute, connect to device first!"); + return false; + } + + bool result = false; + if (!isConnected() && !connect()) + return false; + + QString dllLocation = "\\Windows\\QtRemote.dll"; + QString functionName = "qRemoteSoftReset"; + + DWORD outputSize; + BYTE* output; + IRAPIStream *stream; + + int returned = 0; + + HRESULT res = CeRapiInvoke(dllLocation.utf16(), functionName.utf16(), 0, 0, &outputSize, &output, &stream, 0); + if (S_OK != res) { + DWORD ce_error = CeGetLastError(); + if (S_OK != ce_error) { + qWarning("Error invoking %s on %s: %s", qPrintable(functionName), + qPrintable(dllLocation), strwinerror(ce_error).constData()); + } else { + qWarning("Error: %s on %s unexpectedly returned %d", qPrintable(functionName), + qPrintable(dllLocation), res); + } + } else { + result = true; + } + return result; +} + +bool ActiveSyncConnection::toggleDevicePower(int *returnValue) +{ + if (!isConnected()) { + qWarning("Cannot execute, connect to device first!"); + return false; + } + + bool result = false; + if (!isConnected() && !connect()) + return false; + + QString dllLocation = "\\Windows\\QtRemote.dll"; + QString functionName = "qRemotePowerButton"; + + DWORD outputSize; + BYTE* output; + IRAPIStream *stream; + int returned = 0; + + HRESULT res = CeRapiInvoke(dllLocation.utf16(), functionName.utf16(), 0, 0, &outputSize, &output, &stream, 0); + if (S_OK != res) { + DWORD ce_error = CeGetLastError(); + if (S_OK != ce_error) { + qWarning("Error invoking %s on %s: %s", qPrintable(functionName), + qPrintable(dllLocation), strwinerror(ce_error).constData()); + } else { + qWarning("Error: %s on %s unexpectedly returned %d", qPrintable(functionName), + qPrintable(dllLocation), res); + } + } else { + DWORD written; + if (S_OK != stream->Read(&returned, sizeof(returned), &written)) { + qWarning(" Could not access return value of process"); + } + else { + result = true; + } + } + + if (returnValue) + *returnValue = returned; + return result; +} + bool ActiveSyncConnection::createDirectory(const QString &path, bool deleteBefore) { if (deleteBefore) diff --git a/tools/qtestlib/wince/cetest/activesyncconnection.h b/tools/qtestlib/wince/cetest/activesyncconnection.h index 1891514..4502fc7 100644 --- a/tools/qtestlib/wince/cetest/activesyncconnection.h +++ b/tools/qtestlib/wince/cetest/activesyncconnection.h @@ -79,6 +79,9 @@ public: bool createDirectory(const QString&, bool deleteBefore=false); bool execute(QString program, QString arguments = QString(), int timeout = -1, int *returnValue = NULL); + bool resetDevice(); + bool toggleDevicePower(int *returnValue = NULL); + bool setDeviceAwake(bool activate, int *returnValue = NULL); private: bool connected; }; diff --git a/tools/qtestlib/wince/cetest/main.cpp b/tools/qtestlib/wince/cetest/main.cpp index 146cc5a..9fe5f02 100644 --- a/tools/qtestlib/wince/cetest/main.cpp +++ b/tools/qtestlib/wince/cetest/main.cpp @@ -45,6 +45,9 @@ # include "activesyncconnection.h" #endif +const int SLEEP_AFTER_RESET = 60000; // sleep for 1 minute +const int SLEEP_RECONNECT = 2000; // sleep for 2 seconds before trying another reconnect + #include "deployment.h" #include #include @@ -123,6 +126,8 @@ void usage() " -debug : Test debug version[default]\n" " -release : Test release version\n" " -libpath : Remote path to deploy Qt libraries to\n" + " -reset : Reset device before starting a test\n" + " -awake : Device does not go sleep mode\n" " -qt-delete : Delete the Qt libraries after execution\n" " -project-delete : Delete the project file(s) after execution\n" " -delete : Delete everything deployed after execution\n" @@ -152,6 +157,8 @@ int main(int argc, char **argv) int timeout = -1; bool cleanupQt = false; bool cleanupProject = false; + bool deviceReset = false; + bool keepAwake = false; for (int i=1; i Date: Wed, 10 Feb 2010 13:20:09 +0000 Subject: Factored readRegistryKey implementation out of qmake This function is now implemented with its own header and source files, rather than being embedded within the MSVC qmake generator. The motivation for this is to allow code to be shared between qmake and configure, both of which query the registry when built for Windows. Reviewed-by: Miikka Heikkinen --- qmake/Makefile.unix | 9 +- qmake/Makefile.win32 | 7 ++ qmake/Makefile.win32-g++ | 5 + qmake/Makefile.win32-g++-sh | 5 + qmake/generators/win32/msvc_vcproj.cpp | 97 +------------------- qmake/qmake.pri | 7 +- qmake/qmake.pro | 4 + tools/shared/windows/registry.cpp | 161 +++++++++++++++++++++++++++++++++ tools/shared/windows/registry.h | 64 +++++++++++++ 9 files changed, 259 insertions(+), 100 deletions(-) create mode 100644 tools/shared/windows/registry.cpp create mode 100644 tools/shared/windows/registry.h diff --git a/qmake/Makefile.unix b/qmake/Makefile.unix index fcf43c8..e343803 100644 --- a/qmake/Makefile.unix +++ b/qmake/Makefile.unix @@ -10,7 +10,8 @@ OBJS=project.o property.o main.o makefile.o unixmake2.o unixmake.o \ mingw_make.o option.o winmakefile.o projectgenerator.o \ meta.o makefiledeps.o metamakefile.o xmloutput.o pbuilder_pbx.o \ borland_bmake.o msvc_dsp.o msvc_vcproj.o msvc_nmake.o msvc_objectmodel.o \ - symmake.o initprojectdeploy_symbian.o symmake_abld.o symmake_sbsv2.o + symmake.o initprojectdeploy_symbian.o symmake_abld.o symmake_sbsv2.o \ + registry.o #qt code QOBJS=qtextcodec.o qutfcodec.o qstring.o qtextstream.o qiodevice.o qmalloc.o qglobal.o \ @@ -20,6 +21,7 @@ QOBJS=qtextcodec.o qutfcodec.o qstring.o qtextstream.o qiodevice.o qmalloc.o qgl qfileinfo.o qdatetime.o qstringlist.o qabstractfileengine.o qtemporaryfile.o \ qmap.o qmetatype.o qsettings.o qlibraryinfo.o qvariant.o qvsnprintf.o \ qlocale.o qlinkedlist.o qurl.o qnumeric.o qcryptographichash.o qxmlstream.o qxmlutils.o \ + registry.o \ $(QTOBJS) @@ -32,6 +34,7 @@ DEPEND_SRC=project.cpp property.cpp meta.cpp main.cpp generators/makefile.cpp ge generators/makefiledeps.cpp option.cpp generators/win32/mingw_make.cpp generators/makefile.cpp \ generators/win32/msvc_objectmodel.cpp generators/win32/msvc_nmake.cpp generators/win32/borland_bmake.cpp \ generators/symbian/symmake.cpp generators/symbian/initprojectdeploy_symbian.cpp \ + $(SOURCE_PATH)/tools/shared/windows/registry.cpp \ generators/symbian/symmake_abld.cpp generators/symbian/symmake_sbsv2.cpp \ $(SOURCE_PATH)/src/corelib/codecs/qtextcodec.cpp $(SOURCE_PATH)/src/corelib/codecs/qutfcodec.cpp \ $(SOURCE_PATH)/src/corelib/tools/qstring.cpp $(SOURCE_PATH)/src/corelib/io/qfile.cpp \ @@ -62,6 +65,7 @@ DEPEND_SRC=project.cpp property.cpp meta.cpp main.cpp generators/makefile.cpp ge CPPFLAGS = -I. -Igenerators -Igenerators/unix -Igenerators/win32 -Igenerators/mac -Igenerators/symbian \ -I$(BUILD_PATH)/include -I$(BUILD_PATH)/include/QtCore \ -I$(BUILD_PATH)/src/corelib/global -I$(BUILD_PATH)/src/corelib/xml \ + -I$(BUILD_PATH)/tools/shared \ -DQT_NO_PCRE \ -DQT_BUILD_QMAKE -DQT_BOOTSTRAPPED \ -DQT_NO_TEXTCODEC -DQT_NO_UNICODETABLES -DQT_NO_COMPONENT -DQT_NO_STL \ @@ -281,6 +285,9 @@ symmake_sbsv2.o: generators/symbian/symmake_sbsv2.cpp initprojectdeploy_symbian.o: generators/symbian/initprojectdeploy_symbian.cpp $(CXX) -c -o $@ $(CXXFLAGS) generators/symbian/initprojectdeploy_symbian.cpp +registry.o: $(SOURCE_PATH)/tools/shared/windows/registry.cpp + $(CXX) -c -o $@ $(CXXFLAGS) $(SOURCE_PATH)/tools/shared/windows/registry.cpp + projectgenerator.o: generators/projectgenerator.cpp $(CXX) -c -o $@ $(CXXFLAGS) generators/projectgenerator.cpp diff --git a/qmake/Makefile.win32 b/qmake/Makefile.win32 index e6bbcd5..3cd180c 100644 --- a/qmake/Makefile.win32 +++ b/qmake/Makefile.win32 @@ -34,6 +34,7 @@ CFLAGS = -c -Fo$@ \ -I$(BUILD_PATH)\src\corelib\global \ -I$(BUILD_PATH)\src\corelib\xml \ -I$(SOURCE_PATH)\mkspecs\$(QMAKESPEC) \ + -I$(SOURCE_PATH)\tools\shared \ -DQT_NO_TEXTCODEC -DQT_NO_UNICODETABLES -DQT_LITE_COMPONENT -DQT_NODLL -DQT_NO_STL \ -DQT_NO_COMPRESS -DUNICODE -DHAVE_QCONFIG_CPP -DQT_BUILD_QMAKE -DQT_NO_THREAD \ -DQT_NO_QOBJECT -DQT_NO_GEOM_VARIANT -DQT_NO_DATASTREAM -DQT_NO_PCRE -DQT_BOOTSTRAPPED \ @@ -59,6 +60,7 @@ CFLAGS = -c -o$@ \ -I$(SOURCE_PATH)\include -I$(SOURCE_PATH)\include\QtCore \ -I$(BUILD_PATH)\src\corelib\global \ -I$(SOURCE_PATH)\mkspecs\$(QMAKESPEC) \ + -I$(SOURCE_PATH)\tools\shared \ -DQT_NO_TEXTCODEC -DQT_NO_UNICODETABLES -DQT_LITE_COMPONENT -DQT_NODLL -DQT_NO_STL \ -DQT_NO_COMPRESS -DUNICODE -DHAVE_QCONFIG_CPP -DQT_BUILD_QMAKE -DQT_NO_THREAD \ -DQT_NO_QOBJECT -DQT_NO_GEOM_VARIANT @@ -75,6 +77,7 @@ OBJS = project.obj main.obj makefile.obj unixmake.obj unixmake2.obj mingw makefiledeps.obj metamakefile.obj xmloutput.obj pbuilder_pbx.obj \ borland_bmake.obj msvc_nmake.obj msvc_dsp.obj msvc_vcproj.obj \ msvc_objectmodel.obj symmake.obj initprojectdeploy_symbian.obj \ + registry.obj \ symmake_abld.obj symmake_sbsv2.obj !IFDEF QMAKE_OPENSOURCE_EDITION @@ -198,6 +201,7 @@ clean:: -del symmake_abld.obj -del symmake_sbsv2.obj -del initprojectdeploy_symbian.obj + -del registry.obj -del pbuilder_pbx.obj -del qxmlstream.obj -del qxmlutils.obj @@ -397,6 +401,9 @@ symmake_sbsv2.obj: $(SOURCE_PATH)/qmake/generators/symbian/symmake_sbsv2.cpp initprojectdeploy_symbian.obj: $(SOURCE_PATH)/qmake/generators/symbian/initprojectdeploy_symbian.cpp $(CXX) $(CXXFLAGS) generators/symbian/initprojectdeploy_symbian.cpp +registry.obj: $(SOURCE_PATH)/tools/shared/windows/registry.cpp + $(CXX) $(CXXFLAGS) $(SOURCE_PATH)/tools/shared/windows/registry.cpp + md5.obj: $(SOURCE_PATH)\src\3rdparty\md5\md5.cpp $(CXX) $(CXXFLAGS) $(SOURCE_PATH)\src\3rdparty\md5\md5.cpp diff --git a/qmake/Makefile.win32-g++ b/qmake/Makefile.win32-g++ index ade379b..ebc7fe2 100644 --- a/qmake/Makefile.win32-g++ +++ b/qmake/Makefile.win32-g++ @@ -21,6 +21,7 @@ CFLAGS = -c -o$@ -O \ -I$(BUILD_PATH)/src/corelib/global \ -I$(BUILD_PATH)/src/corelib/xml \ -I$(SOURCE_PATH)/mkspecs/win32-g++ \ + -I$(SOURCE_PATH)/tools/shared \ -DQT_NO_TEXTCODEC -DQT_NO_UNICODETABLES -DQT_LITE_COMPONENT -DQT_NO_PCRE \ -DQT_NODLL -DQT_NO_STL -DQT_NO_COMPRESS -DUNICODE -DHAVE_QCONFIG_CPP \ -DQT_BUILD_QMAKE -DQT_NO_THREAD -DQT_NO_QOBJECT -DQT_NO_GEOM_VARIANT -DQT_NO_DATASTREAM \ @@ -38,6 +39,7 @@ OBJS = project.o main.o makefile.o unixmake.o unixmake2.o mingw_make.o \ makefiledeps.o metamakefile.o xmloutput.o pbuilder_pbx.o \ borland_bmake.o msvc_nmake.o msvc_dsp.o msvc_vcproj.o \ msvc_objectmodel.o symmake.o initprojectdeploy_symbian.o \ + registry.o \ symmake_abld.o symmake_sbsv2.o ifdef QMAKE_OPENSOURCE_EDITION @@ -278,6 +280,9 @@ symmake_sbsv2.o: $(SOURCE_PATH)/qmake/generators/symbian/symmake_sbsv2.cpp initprojectdeploy_symbian.o: $(SOURCE_PATH)/qmake/generators/symbian/initprojectdeploy_symbian.cpp $(CXX) $(CXXFLAGS) generators/symbian/initprojectdeploy_symbian.cpp +registry.o: $(SOURCE_PATH)/tools/shared/windows/registry.cpp + $(CXX) $(CXXFLAGS) $(SOURCE_PATH)/tools/shared/windows/registry.cpp + project.o: $(SOURCE_PATH)/qmake/project.cpp $(SOURCE_PATH)/qmake/project.h $(SOURCE_PATH)/qmake/option.h $(CXX) $(CXXFLAGS) project.cpp diff --git a/qmake/Makefile.win32-g++-sh b/qmake/Makefile.win32-g++-sh index 8d2723c..1d55da2 100644 --- a/qmake/Makefile.win32-g++-sh +++ b/qmake/Makefile.win32-g++-sh @@ -21,6 +21,7 @@ CFLAGS = -c -o$@ -O \ -I$(BUILD_PATH)/src/corelib/global \ -I$(BUILD_PATH)/src/corelib/xml \ -I$(SOURCE_PATH)/mkspecs/win32-g++ \ + -I$(SOURCE_PATH)/tools/shared \ -DQT_NO_TEXTCODEC -DQT_NO_UNICODETABLES -DQT_LITE_COMPONENT -DQT_NO_PCRE \ -DQT_NODLL -DQT_NO_STL -DQT_NO_COMPRESS -DUNICODE -DHAVE_QCONFIG_CPP \ -DQT_BUILD_QMAKE -DQT_NO_THREAD -DQT_NO_QOBJECT -DQT_NO_GEOM_VARIANT -DQT_NO_DATASTREAM \ @@ -38,6 +39,7 @@ OBJS = project.o main.o makefile.o unixmake.o unixmake2.o mingw_make.o \ makefiledeps.o metamakefile.o xmloutput.o pbuilder_pbx.o \ borland_bmake.o msvc_nmake.o msvc_dsp.o msvc_vcproj.o \ msvc_objectmodel.o symmake.o initprojectdeploy_symbian.o \ + registry.o \ symmake_abld.o symmake_sbsv2.o ifdef QMAKE_OPENSOURCE_EDITION @@ -277,6 +279,9 @@ symmake_sbsv2.o: $(SOURCE_PATH)/qmake/generators/symbian/symmake_sbsv2.cpp initprojectdeploy_symbian.o: $(SOURCE_PATH)/qmake/generators/symbian/initprojectdeploy_symbian.cpp $(CXX) $(CXXFLAGS) generators/symbian/initprojectdeploy_symbian.cpp +registry.o: $(SOURCE_PATH)/tools/shared/windows/registry.cpp + $(CXX) $(CXXFLAGS) $(SOURCE_PATH)/tools/shared/windows/registry.cpp + project.o: $(SOURCE_PATH)/qmake/project.cpp $(SOURCE_PATH)/qmake/project.h $(SOURCE_PATH)/qmake/option.h $(CXX) $(CXXFLAGS) project.cpp diff --git a/qmake/generators/win32/msvc_vcproj.cpp b/qmake/generators/win32/msvc_vcproj.cpp index 47986f5..58f95e9 100644 --- a/qmake/generators/win32/msvc_vcproj.cpp +++ b/qmake/generators/win32/msvc_vcproj.cpp @@ -67,6 +67,7 @@ QT_END_NAMESPACE #ifdef Q_OS_WIN32 #include +#include QT_BEGIN_NAMESPACE @@ -93,102 +94,6 @@ struct { {NETUnknown, "", ""}, }; -static QString keyPath(const QString &rKey) -{ - int idx = rKey.lastIndexOf(QLatin1Char('\\')); - if (idx == -1) - return QString(); - return rKey.left(idx + 1); -} - -static QString keyName(const QString &rKey) -{ - int idx = rKey.lastIndexOf(QLatin1Char('\\')); - if (idx == -1) - return rKey; - - QString res(rKey.mid(idx + 1)); - if (res == "Default" || res == ".") - res = ""; - return res; -} - -static QString readRegistryKey(HKEY parentHandle, const QString &rSubkey) -{ - - QString rSubkeyName = keyName(rSubkey); - QString rSubkeyPath = keyPath(rSubkey); - - HKEY handle = 0; - LONG res = RegOpenKeyEx(parentHandle, (wchar_t*)rSubkeyPath.utf16(), 0, KEY_READ, &handle); - - if (res != ERROR_SUCCESS) - return QString(); - - // get the size and type of the value - DWORD dataType; - DWORD dataSize; - res = RegQueryValueEx(handle, (wchar_t*)rSubkeyName.utf16(), 0, &dataType, 0, &dataSize); - if (res != ERROR_SUCCESS) { - RegCloseKey(handle); - return QString(); - } - - // get the value - QByteArray data(dataSize, 0); - res = RegQueryValueEx(handle, (wchar_t*)rSubkeyName.utf16(), 0, 0, - reinterpret_cast(data.data()), &dataSize); - if (res != ERROR_SUCCESS) { - RegCloseKey(handle); - return QString(); - } - - QString result; - switch (dataType) { - case REG_EXPAND_SZ: - case REG_SZ: { - result = QString::fromWCharArray(((const wchar_t *)data.constData())); - break; - } - - case REG_MULTI_SZ: { - QStringList l; - int i = 0; - for (;;) { - QString s = QString::fromWCharArray((const wchar_t *)data.constData() + i); - i += s.length() + 1; - - if (s.isEmpty()) - break; - l.append(s); - } - result = l.join(", "); - break; - } - - case REG_NONE: - case REG_BINARY: { - result = QString::fromWCharArray((const wchar_t *)data.constData(), data.size() / 2); - break; - } - - case REG_DWORD_BIG_ENDIAN: - case REG_DWORD: { - Q_ASSERT(data.size() == sizeof(int)); - int i; - memcpy((char*)&i, data.constData(), sizeof(int)); - result = QString::number(i); - break; - } - - default: - qWarning("QSettings: unknown data %d type in windows registry", dataType); - break; - } - - RegCloseKey(handle); - return result; -} QT_END_NAMESPACE #endif diff --git a/qmake/qmake.pri b/qmake/qmake.pri index efe4f36..a2ffe15 100644 --- a/qmake/qmake.pri +++ b/qmake/qmake.pri @@ -17,7 +17,8 @@ SOURCES += project.cpp property.cpp main.cpp generators/makefile.cpp \ generators/symbian/symmake.cpp \ generators/symbian/symmake_abld.cpp \ generators/symbian/symmake_sbsv2.cpp \ - generators/symbian/initprojectdeploy_symbian.cpp + generators/symbian/initprojectdeploy_symbian.cpp \ + windows/registry.cpp HEADERS += project.h property.h generators/makefile.h \ generators/unix/unixmake.h meta.h option.h cachekeys.h \ @@ -29,8 +30,8 @@ HEADERS += project.h property.h generators/makefile.h \ generators/symbian/symmake.h \ generators/symbian/symmake_abld.h \ generators/symbian/symmake_sbsv2.h \ - generators/symbian/epocroot.h \ - generators/symbian/initprojectdeploy_symbian.h + generators/symbian/initprojectdeploy_symbian.h \ + windows/registry.h contains(QT_EDITION, OpenSource) { DEFINES += QMAKE_OPENSOURCE_EDITION diff --git a/qmake/qmake.pro b/qmake/qmake.pro index 00dcbce..f3f9d53 100644 --- a/qmake/qmake.pro +++ b/qmake/qmake.pro @@ -27,5 +27,9 @@ INCPATH += generators \ $$QT_SOURCE_TREE/include \ $$QT_SOURCE_TREE/include/QtCore \ $$QT_SOURCE_TREE/qmake + +VPATH += $$QT_SOURCE_TREE/tools/shared +INCPATH += $$QT_SOURCE_TREE/tools/shared + include(qmake.pri) diff --git a/tools/shared/windows/registry.cpp b/tools/shared/windows/registry.cpp new file mode 100644 index 0000000..d342d78 --- /dev/null +++ b/tools/shared/windows/registry.cpp @@ -0,0 +1,161 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the qmake application 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 "registry.h" + +/*! + Returns the path part of a registry key. + e.g. + For a key + "Software\\Microsoft\\VisualStudio\\8.0\\Setup\\VC\\ProductDir" + it returns + "Software\\Microsoft\\VisualStudio\\8.0\\Setup\\VC\\" +*/ +static QString keyPath(const QString &rKey) +{ + int idx = rKey.lastIndexOf(QLatin1Char('\\')); + if (idx == -1) + return QString(); + return rKey.left(idx + 1); +} + +/*! + Returns the name part of a registry key. + e.g. + For a key + "Software\\Microsoft\\VisualStudio\\8.0\\Setup\\VC\\ProductDir" + it returns + "ProductDir" +*/ +static QString keyName(const QString &rKey) +{ + int idx = rKey.lastIndexOf(QLatin1Char('\\')); + if (idx == -1) + return rKey; + + QString res(rKey.mid(idx + 1)); + if (res == "Default" || res == ".") + res = ""; + return res; +} + +QString readRegistryKey(HKEY parentHandle, const QString &rSubkey) +{ + QString result; + +#ifdef Q_OS_WIN32 + QString rSubkeyName = keyName(rSubkey); + QString rSubkeyPath = keyPath(rSubkey); + + HKEY handle = 0; + LONG res = RegOpenKeyEx(parentHandle, (wchar_t*)rSubkeyPath.utf16(), 0, KEY_READ, &handle); + + if (res != ERROR_SUCCESS) + return QString(); + + // get the size and type of the value + DWORD dataType; + DWORD dataSize; + res = RegQueryValueEx(handle, (wchar_t*)rSubkeyName.utf16(), 0, &dataType, 0, &dataSize); + if (res != ERROR_SUCCESS) { + RegCloseKey(handle); + return QString(); + } + + // get the value + QByteArray data(dataSize, 0); + res = RegQueryValueEx(handle, (wchar_t*)rSubkeyName.utf16(), 0, 0, + reinterpret_cast(data.data()), &dataSize); + if (res != ERROR_SUCCESS) { + RegCloseKey(handle); + return QString(); + } + + switch (dataType) { + case REG_EXPAND_SZ: + case REG_SZ: { + result = QString::fromWCharArray(((const wchar_t *)data.constData())); + break; + } + + case REG_MULTI_SZ: { + QStringList l; + int i = 0; + for (;;) { + QString s = QString::fromWCharArray((const wchar_t *)data.constData() + i); + i += s.length() + 1; + + if (s.isEmpty()) + break; + l.append(s); + } + result = l.join(", "); + break; + } + + case REG_NONE: + case REG_BINARY: { + result = QString::fromWCharArray((const wchar_t *)data.constData(), data.size() / 2); + break; + } + + case REG_DWORD_BIG_ENDIAN: + case REG_DWORD: { + Q_ASSERT(data.size() == sizeof(int)); + int i; + memcpy((char*)&i, data.constData(), sizeof(int)); + result = QString::number(i); + break; + } + + default: + qWarning("QSettings: unknown data %d type in windows registry", dataType); + break; + } + + RegCloseKey(handle); +#endif + + return result; +} + + diff --git a/tools/shared/windows/registry.h b/tools/shared/windows/registry.h new file mode 100644 index 0000000..3896527 --- /dev/null +++ b/tools/shared/windows/registry.h @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the qmake application 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$ +** +****************************************************************************/ + +#ifndef WINDOWS_REGISTRY_H +#define WINDOWS_REGISTRY_H + +#include + +#ifdef Q_OS_WIN32 + #include +#else + typedef void* HKEY; +#endif + +#include + +/** + * Read a value from the Windows registry. + * + * If the key is not found, or the registry cannot be accessed (for example + * if this code is compiled for a platform other than Windows), a null + * string is returned. + */ +QString readRegistryKey(HKEY parentHandle, const QString &rSubkey); + +#endif // WINDOWS_REGISTRY_H -- cgit v0.12 From 6ebcf2c24b43fdc1d6da50e9d7ec9dd63dd507d7 Mon Sep 17 00:00:00 2001 From: Gareth Stockwell Date: Wed, 10 Feb 2010 14:57:51 +0000 Subject: Factored epocRoot implementation out of qmake This function is now implemented in its own source file, rather than being embedded within the Symbian qmake generator. The motivation for this is to allow code to be shared between qmake and configure - the latter needs to determine the epoc root path in order to perform feature detection on Symbian SDKs. Reviewed-by: Miikka Heikkinen --- qmake/Makefile.unix | 9 +- qmake/Makefile.win32 | 5 + qmake/Makefile.win32-g++ | 4 + qmake/Makefile.win32-g++-sh | 4 + qmake/generators/symbian/epocroot.h | 51 ----- .../symbian/initprojectdeploy_symbian.cpp | 96 +-------- .../generators/symbian/initprojectdeploy_symbian.h | 2 - qmake/generators/symbian/symmake.cpp | 3 + qmake/generators/symbian/symmake_abld.cpp | 3 + qmake/generators/symbian/symmake_sbsv2.cpp | 3 + qmake/project.cpp | 5 +- qmake/qmake.pri | 6 +- tools/shared/symbian/epocroot.cpp | 230 +++++++++++++++++++++ tools/shared/symbian/epocroot.h | 67 ++++++ 14 files changed, 337 insertions(+), 151 deletions(-) delete mode 100644 qmake/generators/symbian/epocroot.h create mode 100644 tools/shared/symbian/epocroot.cpp create mode 100644 tools/shared/symbian/epocroot.h diff --git a/qmake/Makefile.unix b/qmake/Makefile.unix index e343803..5469134 100644 --- a/qmake/Makefile.unix +++ b/qmake/Makefile.unix @@ -11,7 +11,8 @@ OBJS=project.o property.o main.o makefile.o unixmake2.o unixmake.o \ meta.o makefiledeps.o metamakefile.o xmloutput.o pbuilder_pbx.o \ borland_bmake.o msvc_dsp.o msvc_vcproj.o msvc_nmake.o msvc_objectmodel.o \ symmake.o initprojectdeploy_symbian.o symmake_abld.o symmake_sbsv2.o \ - registry.o + registry.o \ + epocroot.o #qt code QOBJS=qtextcodec.o qutfcodec.o qstring.o qtextstream.o qiodevice.o qmalloc.o qglobal.o \ @@ -22,6 +23,7 @@ QOBJS=qtextcodec.o qutfcodec.o qstring.o qtextstream.o qiodevice.o qmalloc.o qgl qmap.o qmetatype.o qsettings.o qlibraryinfo.o qvariant.o qvsnprintf.o \ qlocale.o qlinkedlist.o qurl.o qnumeric.o qcryptographichash.o qxmlstream.o qxmlutils.o \ registry.o \ + epocroot.o \ $(QTOBJS) @@ -35,6 +37,7 @@ DEPEND_SRC=project.cpp property.cpp meta.cpp main.cpp generators/makefile.cpp ge generators/win32/msvc_objectmodel.cpp generators/win32/msvc_nmake.cpp generators/win32/borland_bmake.cpp \ generators/symbian/symmake.cpp generators/symbian/initprojectdeploy_symbian.cpp \ $(SOURCE_PATH)/tools/shared/windows/registry.cpp \ + $(SOURCE_PATH)/tools/shared/symbian/epocroot.cpp \ generators/symbian/symmake_abld.cpp generators/symbian/symmake_sbsv2.cpp \ $(SOURCE_PATH)/src/corelib/codecs/qtextcodec.cpp $(SOURCE_PATH)/src/corelib/codecs/qutfcodec.cpp \ $(SOURCE_PATH)/src/corelib/tools/qstring.cpp $(SOURCE_PATH)/src/corelib/io/qfile.cpp \ @@ -288,6 +291,9 @@ initprojectdeploy_symbian.o: generators/symbian/initprojectdeploy_symbian.cpp registry.o: $(SOURCE_PATH)/tools/shared/windows/registry.cpp $(CXX) -c -o $@ $(CXXFLAGS) $(SOURCE_PATH)/tools/shared/windows/registry.cpp +epocroot.o: $(SOURCE_PATH)/tools/shared/symbian/epocroot.cpp + $(CXX) -c -o $@ $(CXXFLAGS) $(SOURCE_PATH)/tools/shared/symbian/epocroot.cpp + projectgenerator.o: generators/projectgenerator.cpp $(CXX) -c -o $@ $(CXXFLAGS) generators/projectgenerator.cpp @@ -296,6 +302,7 @@ qxmlstream.o: $(SOURCE_PATH)/src/corelib/xml/qxmlstream.cpp qxmlutils.o: $(SOURCE_PATH)/src/corelib/xml/qxmlutils.cpp $(CXX) -c -o $@ $(CXXFLAGS) $(SOURCE_PATH)/src/corelib/xml/qxmlutils.cpp + #default rules .cpp.o: $(CXX) -c -o $@ $(CXXFLAGS) $< diff --git a/qmake/Makefile.win32 b/qmake/Makefile.win32 index 3cd180c..48d84b7 100644 --- a/qmake/Makefile.win32 +++ b/qmake/Makefile.win32 @@ -78,6 +78,7 @@ OBJS = project.obj main.obj makefile.obj unixmake.obj unixmake2.obj mingw borland_bmake.obj msvc_nmake.obj msvc_dsp.obj msvc_vcproj.obj \ msvc_objectmodel.obj symmake.obj initprojectdeploy_symbian.obj \ registry.obj \ + epocroot.obj \ symmake_abld.obj symmake_sbsv2.obj !IFDEF QMAKE_OPENSOURCE_EDITION @@ -202,6 +203,7 @@ clean:: -del symmake_sbsv2.obj -del initprojectdeploy_symbian.obj -del registry.obj + -del epocroot.obj -del pbuilder_pbx.obj -del qxmlstream.obj -del qxmlutils.obj @@ -404,6 +406,9 @@ initprojectdeploy_symbian.obj: $(SOURCE_PATH)/qmake/generators/symbian/initproje registry.obj: $(SOURCE_PATH)/tools/shared/windows/registry.cpp $(CXX) $(CXXFLAGS) $(SOURCE_PATH)/tools/shared/windows/registry.cpp +epocroot.obj: $(SOURCE_PATH)/tools/shared/symbian/epocroot.cpp + $(CXX) $(CXXFLAGS) $(SOURCE_PATH)/tools/shared/symbian/epocroot.cpp + md5.obj: $(SOURCE_PATH)\src\3rdparty\md5\md5.cpp $(CXX) $(CXXFLAGS) $(SOURCE_PATH)\src\3rdparty\md5\md5.cpp diff --git a/qmake/Makefile.win32-g++ b/qmake/Makefile.win32-g++ index ebc7fe2..169de3c 100644 --- a/qmake/Makefile.win32-g++ +++ b/qmake/Makefile.win32-g++ @@ -40,6 +40,7 @@ OBJS = project.o main.o makefile.o unixmake.o unixmake2.o mingw_make.o \ borland_bmake.o msvc_nmake.o msvc_dsp.o msvc_vcproj.o \ msvc_objectmodel.o symmake.o initprojectdeploy_symbian.o \ registry.o \ + epocroot.o \ symmake_abld.o symmake_sbsv2.o ifdef QMAKE_OPENSOURCE_EDITION @@ -283,6 +284,9 @@ initprojectdeploy_symbian.o: $(SOURCE_PATH)/qmake/generators/symbian/initproject registry.o: $(SOURCE_PATH)/tools/shared/windows/registry.cpp $(CXX) $(CXXFLAGS) $(SOURCE_PATH)/tools/shared/windows/registry.cpp +epocroot.o: $(SOURCE_PATH)/tools/shared/symbian/epocroot.cpp + $(CXX) $(CXXFLAGS) $(SOURCE_PATH)/tools/shared/symbian/epocroot.cpp + project.o: $(SOURCE_PATH)/qmake/project.cpp $(SOURCE_PATH)/qmake/project.h $(SOURCE_PATH)/qmake/option.h $(CXX) $(CXXFLAGS) project.cpp diff --git a/qmake/Makefile.win32-g++-sh b/qmake/Makefile.win32-g++-sh index 1d55da2..98237e7 100644 --- a/qmake/Makefile.win32-g++-sh +++ b/qmake/Makefile.win32-g++-sh @@ -40,6 +40,7 @@ OBJS = project.o main.o makefile.o unixmake.o unixmake2.o mingw_make.o \ borland_bmake.o msvc_nmake.o msvc_dsp.o msvc_vcproj.o \ msvc_objectmodel.o symmake.o initprojectdeploy_symbian.o \ registry.o \ + epocroot.o \ symmake_abld.o symmake_sbsv2.o ifdef QMAKE_OPENSOURCE_EDITION @@ -282,6 +283,9 @@ initprojectdeploy_symbian.o: $(SOURCE_PATH)/qmake/generators/symbian/initproject registry.o: $(SOURCE_PATH)/tools/shared/windows/registry.cpp $(CXX) $(CXXFLAGS) $(SOURCE_PATH)/tools/shared/windows/registry.cpp +epocroot.o: $(SOURCE_PATH)/tools/shared/symbian/epocroot.cpp + $(CXX) $(CXXFLAGS) $(SOURCE_PATH)/tools/shared/symbian/epocroot.cpp + project.o: $(SOURCE_PATH)/qmake/project.cpp $(SOURCE_PATH)/qmake/project.h $(SOURCE_PATH)/qmake/option.h $(CXX) $(CXXFLAGS) project.cpp diff --git a/qmake/generators/symbian/epocroot.h b/qmake/generators/symbian/epocroot.h deleted file mode 100644 index be26438..0000000 --- a/qmake/generators/symbian/epocroot.h +++ /dev/null @@ -1,51 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the qmake application 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$ -** -****************************************************************************/ - -#ifndef EPOCROOT_H -#define EPOCROOT_H - -#include - -// Implementation of epocRoot method is in initprojectdeploy_symbian.cpp -// Defined in separate header for inclusion clarity -extern QString epocRoot(); - -#endif // EPOCROOT_H diff --git a/qmake/generators/symbian/initprojectdeploy_symbian.cpp b/qmake/generators/symbian/initprojectdeploy_symbian.cpp index 5fbff58..2a22305 100644 --- a/qmake/generators/symbian/initprojectdeploy_symbian.cpp +++ b/qmake/generators/symbian/initprojectdeploy_symbian.cpp @@ -46,105 +46,15 @@ #include #include +// Included from tools/shared +#include + #define SYSBIN_DIR "\\sys\\bin" #define SUFFIX_DLL "dll" #define SUFFIX_EXE "exe" #define SUFFIX_QTPLUGIN "qtplugin" -static void fixEpocRootStr(QString& path) -{ - path.replace("\\", "/"); - - if (path.size() > 1 && path[1] == QChar(':')) { - path = path.mid(2); - } - - if (!path.size() || path[path.size()-1] != QChar('/')) { - path += QChar('/'); - } -} - -#define SYMBIAN_SDKS_KEY "HKEY_LOCAL_MACHINE\\Software\\Symbian\\EPOC SDKs" - -static QString epocRootStr; - -QString epocRoot() -{ - if (!epocRootStr.isEmpty()) { - return epocRootStr; - } - - // First, check the env variable - epocRootStr = qgetenv("EPOCROOT"); - - if (epocRootStr.isEmpty()) { - // No EPOCROOT set, check the default device - // First check EPOCDEVICE env variable - QString defaultDevice = qgetenv("EPOCDEVICE"); - - // Check the windows registry via QSettings for devices.xml path - QSettings settings(SYMBIAN_SDKS_KEY, QSettings::NativeFormat); - QString devicesXmlPath = settings.value("CommonPath").toString(); - - if (!devicesXmlPath.isEmpty()) { - // Parse xml for correct device - devicesXmlPath += "/devices.xml"; - QFile devicesFile(devicesXmlPath); - if (devicesFile.open(QIODevice::ReadOnly)) { - QXmlStreamReader xml(&devicesFile); - while (!xml.atEnd()) { - xml.readNext(); - if (xml.isStartElement() && xml.name() == "devices") { - if (xml.attributes().value("version") == "1.0") { - // Look for correct device - while (!(xml.isEndElement() && xml.name() == "devices") && !xml.atEnd()) { - xml.readNext(); - if (xml.isStartElement() && xml.name() == "device") { - if ((defaultDevice.isEmpty() && xml.attributes().value("default") == "yes") || - (!defaultDevice.isEmpty() && (xml.attributes().value("id").toString() + QString(":") + xml.attributes().value("name").toString()) == defaultDevice)) { - // Found the correct device - while (!(xml.isEndElement() && xml.name() == "device") && !xml.atEnd()) { - xml.readNext(); - if (xml.isStartElement() && xml.name() == "epocroot") { - epocRootStr = xml.readElementText(); - fixEpocRootStr(epocRootStr); - return epocRootStr; - } - } - xml.raiseError("No epocroot element found"); - } - } - } - } else { - xml.raiseError("Invalid 'devices' element version"); - } - } - } - if (xml.hasError()) { - fprintf(stderr, "ERROR: \"%s\" when parsing devices.xml\n", qPrintable(xml.errorString())); - } - } else { - fprintf(stderr, "Could not open devices.xml (%s)\n", qPrintable(devicesXmlPath)); - } - } else { - fprintf(stderr, "Could not retrieve " SYMBIAN_SDKS_KEY " setting\n"); - } - - fprintf(stderr, "Failed to determine epoc root.\n"); - if (!defaultDevice.isEmpty()) - fprintf(stderr, "The device indicated by EPOCDEVICE environment variable (%s) could not be found.\n", qPrintable(defaultDevice)); - fprintf(stderr, "Either set EPOCROOT or EPOCDEVICE environment variable to a valid value, or provide a default Symbian device.\n"); - - // No valid device found; set epocroot to "/" - epocRootStr = QLatin1String("/"); - } - - fixEpocRootStr(epocRootStr); - return epocRootStr; -} - - static bool isPlugin(const QFileInfo& info, const QString& devicePath) { // Libraries are plugins if deployment path is something else than diff --git a/qmake/generators/symbian/initprojectdeploy_symbian.h b/qmake/generators/symbian/initprojectdeploy_symbian.h index e23e6a9..b409225 100644 --- a/qmake/generators/symbian/initprojectdeploy_symbian.h +++ b/qmake/generators/symbian/initprojectdeploy_symbian.h @@ -50,8 +50,6 @@ #include #include -#include "epocroot.h" - #define PLUGIN_STUB_DIR "qmakepluginstubs" struct CopyItem diff --git a/qmake/generators/symbian/symmake.cpp b/qmake/generators/symbian/symmake.cpp index 2055f81..a712434 100644 --- a/qmake/generators/symbian/symmake.cpp +++ b/qmake/generators/symbian/symmake.cpp @@ -49,6 +49,9 @@ #include #include +// Included from tools/shared +#include + #define RESOURCE_DIRECTORY_MMP "/resource/apps" #define RESOURCE_DIRECTORY_RESOURCE "\\\\resource\\\\apps\\\\" #define REGISTRATION_RESOURCE_DIRECTORY_HW "/private/10003a3f/import/apps" diff --git a/qmake/generators/symbian/symmake_abld.cpp b/qmake/generators/symbian/symmake_abld.cpp index 033bcbe..6c62412 100644 --- a/qmake/generators/symbian/symmake_abld.cpp +++ b/qmake/generators/symbian/symmake_abld.cpp @@ -48,6 +48,9 @@ #include #include +// Included from tools/shared +#include + #define DO_NOTHING_TARGET "do_nothing" #define CREATE_TEMPS_TARGET "create_temps" #define EXTENSION_CLEAN "extension_clean" diff --git a/qmake/generators/symbian/symmake_sbsv2.cpp b/qmake/generators/symbian/symmake_sbsv2.cpp index e081b19..8accfce 100644 --- a/qmake/generators/symbian/symmake_sbsv2.cpp +++ b/qmake/generators/symbian/symmake_sbsv2.cpp @@ -48,6 +48,9 @@ #include #include +// Included from tools/shared +#include + SymbianSbsv2MakefileGenerator::SymbianSbsv2MakefileGenerator() : SymbianMakefileGenerator() { } SymbianSbsv2MakefileGenerator::~SymbianSbsv2MakefileGenerator() { } diff --git a/qmake/project.cpp b/qmake/project.cpp index 4ce8ba4..e4ef7dd 100644 --- a/qmake/project.cpp +++ b/qmake/project.cpp @@ -44,8 +44,6 @@ #include "option.h" #include "cachekeys.h" -#include "epocroot.h" - #include #include #include @@ -64,6 +62,9 @@ #include #include +// Included from tools/shared +#include + #ifdef Q_OS_WIN32 #define QT_POPEN _popen #define QT_PCLOSE _pclose diff --git a/qmake/qmake.pri b/qmake/qmake.pri index a2ffe15..05debe6 100644 --- a/qmake/qmake.pri +++ b/qmake/qmake.pri @@ -18,7 +18,8 @@ SOURCES += project.cpp property.cpp main.cpp generators/makefile.cpp \ generators/symbian/symmake_abld.cpp \ generators/symbian/symmake_sbsv2.cpp \ generators/symbian/initprojectdeploy_symbian.cpp \ - windows/registry.cpp + windows/registry.cpp \ + symbian/epocroot.cpp HEADERS += project.h property.h generators/makefile.h \ generators/unix/unixmake.h meta.h option.h cachekeys.h \ @@ -31,7 +32,8 @@ HEADERS += project.h property.h generators/makefile.h \ generators/symbian/symmake_abld.h \ generators/symbian/symmake_sbsv2.h \ generators/symbian/initprojectdeploy_symbian.h \ - windows/registry.h + windows/registry.h \ + symbian/epocroot.h contains(QT_EDITION, OpenSource) { DEFINES += QMAKE_OPENSOURCE_EDITION diff --git a/tools/shared/symbian/epocroot.cpp b/tools/shared/symbian/epocroot.cpp new file mode 100644 index 0000000..071477d --- /dev/null +++ b/tools/shared/symbian/epocroot.cpp @@ -0,0 +1,230 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the qmake application 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 + +#include "epocroot.h" +#include "../windows/registry.h" + +// Registry key under which the location of the Symbian devices.xml file is +// stored. +// Note that, on 64-bit machines, this key is located under the 32-bit +// compatibility key: +// HKEY_LOCAL_MACHINE\Software\Wow6432Node +#define SYMBIAN_SDKS_REG_SUBKEY "Software\\Symbian\\EPOC SDKs\\CommonPath" + +#ifdef Q_OS_WIN32 +# define SYMBIAN_SDKS_REG_HANDLE HKEY_LOCAL_MACHINE +#else +# define SYMBIAN_SDKS_REG_HANDLE 0 +#endif + +// Value which is populated and returned by the epocRoot() function. +// Stored as a static value in order to avoid unnecessary re-evaluation. +static QString epocRootValue; + +#ifdef QT_BUILD_QMAKE +std::ostream &operator<<(std::ostream &s, const QString &val) { + s << val.toLocal8Bit().data(); + return s; +} +#else +// Operator implemented in configureapp.cpp +std::ostream &operator<<(std::ostream &s, const QString &val); +#endif + +QString getDevicesXmlPath() + { + // Note that the following call will return a null string on platforms other + // than Windows. If support is required on other platforms for devices.xml, + // an alternative mechanism for retrieving the location of this file will + // be required. + return readRegistryKey(SYMBIAN_SDKS_REG_HANDLE, SYMBIAN_SDKS_REG_SUBKEY); + } + +/** + * Checks whether epocRootValue points to an existent directory. + * If not, epocRootValue is set to an empty string and an error message is printed. + */ +void checkEpocRootExists(const QString &source) +{ + if (!epocRootValue.isEmpty()) { + QDir dir(epocRootValue); + if (!dir.exists()) { + std::cerr << "Warning: " << source << " is set to an invalid path: " << epocRootValue << std::endl; + epocRootValue = QString(); + } + } +} + +/** + * Translate path from Windows to Qt format. + */ +static void fixEpocRoot(QString &path) +{ + path.replace("\\", "/"); + + if (path.size() > 1 && path[1] == QChar(':')) { + path = path.mid(2); + } + + if (!path.size() || path[path.size()-1] != QChar('/')) { + path += QChar('/'); + } +} + +/** + * Determine the epoc root for the currently active SDK. + */ +QString epocRoot() +{ + if (epocRootValue.isEmpty()) { + // 1. If environment variable EPOCROOT is set and points to an existent + // directory, this is returned. + epocRootValue = qgetenv("EPOCROOT"); + checkEpocRootExists("EPOCROOT"); + + if (epocRootValue.isEmpty()) { + // 2. The location of devices.xml is specified by a registry key. If this + // file exists, it is parsed. + QString devicesXmlPath = getDevicesXmlPath(); + if (devicesXmlPath.isEmpty()) { + std::cerr << "Error: Symbian SDK registry key not found" << std::endl; + } else { + devicesXmlPath += "/devices.xml"; + QFile devicesFile(devicesXmlPath); + if (devicesFile.open(QIODevice::ReadOnly)) { + + // 3. If the EPOCDEVICE environment variable is set and a corresponding + // entry is found in devices.xml, and its epocroot value points to an + // existent directory, it is returned. + // 4. If a device element marked as default is found in devices.xml and its + // epocroot value points to an existent directory, this is returned. + + const QString epocDeviceValue = qgetenv("EPOCDEVICE"); + bool epocDeviceFound = false; + + QXmlStreamReader xml(&devicesFile); + while (!xml.atEnd()) { + xml.readNext(); + if (xml.isStartElement() && xml.name() == "devices") { + if (xml.attributes().value("version") == "1.0") { + while (!(xml.isEndElement() && xml.name() == "devices") && !xml.atEnd()) { + xml.readNext(); + if (xml.isStartElement() && xml.name() == "device") { + const bool isDefault = xml.attributes().value("default") == "yes"; + const QString id = xml.attributes().value("id").toString(); + const QString name = xml.attributes().value("name").toString(); + const bool epocDeviceMatch = (id + ":" + name) == epocDeviceValue; + epocDeviceFound |= epocDeviceMatch; + + if((epocDeviceValue.isEmpty() && isDefault) || epocDeviceMatch) { + // Found a matching device + while (!(xml.isEndElement() && xml.name() == "device") && !xml.atEnd()) { + xml.readNext(); + if (xml.isStartElement() && xml.name() == "epocroot") { + epocRootValue = xml.readElementText(); + const QString deviceSource = epocDeviceValue.isEmpty() + ? "default device" + : "EPOCDEVICE (" + epocDeviceValue + ")"; + checkEpocRootExists(deviceSource); + } + } + + if (epocRootValue.isEmpty()) + xml.raiseError("No epocroot element found"); + } + } + } + } else { + xml.raiseError("Invalid 'devices' element version"); + } + } + } + if (xml.hasError()) { + std::cerr << "Error: \"" << xml.errorString() << "\" when parsing devices.xml" << std::endl; + } else { + if (epocRootValue.isEmpty()) { + if (!epocDeviceValue.isEmpty()) { + if (epocDeviceFound) { + std::cerr << "Error: missing or invalid epocroot attribute " + << "in device '" << epocDeviceValue << "'"; + } else { + std::cerr << "Error: no device matching EPOCDEVICE (" + << epocDeviceValue << ")"; + } + } else { + if (epocDeviceFound) { + std::cerr << "Error: missing or invalid epocroot attribute " + << "in default device"; + } else { + std::cerr << "Error: no default device"; + } + } + std::cerr << " found in devices.xml file." << std::endl; + } + } + } else { + std::cerr << "Error: could not open file " << devicesXmlPath << std::endl; + } + } + } + + if (epocRootValue.isEmpty()) { + // 5. An empty string is returned. + std::cerr << "Error: failed to find epoc root" << std::endl + << "Either" << std::endl + << " 1. Set EPOCROOT environment variable to a valid value" << std::endl + << " or 2. Ensure that the HKEY_LOCAL_MACHINE\\" SYMBIAN_SDKS_REG_SUBKEY + " registry key is set, and then" << std::endl + << " a. Set EPOCDEVICE environment variable to a valid device" << std::endl + << " or b. Specify a default device in the devices.xml file." << std::endl; + } else { + fixEpocRoot(epocRootValue); + } + } + + return epocRootValue; +} + diff --git a/tools/shared/symbian/epocroot.h b/tools/shared/symbian/epocroot.h new file mode 100644 index 0000000..9846485 --- /dev/null +++ b/tools/shared/symbian/epocroot.h @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the qmake application 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$ +** +****************************************************************************/ + +#ifndef SYMBIAN_EPOCROOT_H +#define SYMBIAN_EPOCROOT_H + +#include + +/** + * Determine the epoc root for the currently active SDK. + * + * The algorithm used is as follows: + * 1. If environment variable EPOCROOT is set and points to an existent + * directory, this is returned. + * 2. The location of devices.xml is specified by a registry key. If this + * file exists, it is parsed. + * 3. If the EPOCDEVICE environment variable is set and a corresponding + * entry is found in devices.xml, and its epocroot value points to an + * existent directory, it is returned. + * 4. If a device element marked as default is found in devices.xml and its + * epocroot value points to an existent directory, this is returned. + * 5. An empty string is returned. + * + * Any return value other than the empty string therefore is guaranteed to + * point to an existent directory. + */ +QString epocRoot(); + +#endif // EPOCROOT_H -- cgit v0.12 From 480f3df2eab9ad13e0d7ea1245158866a0b942bd Mon Sep 17 00:00:00 2001 From: Gareth Stockwell Date: Fri, 19 Feb 2010 11:16:34 +0100 Subject: Fixed linkage failure when building qmake on Unix platforms Commits f641369c/5254184c and 13cb80be/6ebcf2c2 caused registry.o and epocroot.o respectively to be included twice during the linkage step of qmake/Makefile.unix. --- qmake/Makefile.unix | 2 -- 1 file changed, 2 deletions(-) diff --git a/qmake/Makefile.unix b/qmake/Makefile.unix index 5469134..fa98fd6 100644 --- a/qmake/Makefile.unix +++ b/qmake/Makefile.unix @@ -22,8 +22,6 @@ QOBJS=qtextcodec.o qutfcodec.o qstring.o qtextstream.o qiodevice.o qmalloc.o qgl qfileinfo.o qdatetime.o qstringlist.o qabstractfileengine.o qtemporaryfile.o \ qmap.o qmetatype.o qsettings.o qlibraryinfo.o qvariant.o qvsnprintf.o \ qlocale.o qlinkedlist.o qurl.o qnumeric.o qcryptographichash.o qxmlstream.o qxmlutils.o \ - registry.o \ - epocroot.o \ $(QTOBJS) -- cgit v0.12 From 1f56953fca1a38b31734ce8a87c01c85f1f0f901 Mon Sep 17 00:00:00 2001 From: Miikka Heikkinen Date: Fri, 19 Feb 2010 12:38:30 +0200 Subject: Fixed libstdcpp.dll version autodetection for Symbian Libstdcpp.dll version autodetection was broken for clean builds, so made it default for new version when neither new or old can be detected. Task-number: QT-1171 Reviewed-by: Janne Anttila --- mkspecs/features/symbian/stl.prf | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/mkspecs/features/symbian/stl.prf b/mkspecs/features/symbian/stl.prf index e21ee5c..85c758a 100644 --- a/mkspecs/features/symbian/stl.prf +++ b/mkspecs/features/symbian/stl.prf @@ -15,11 +15,18 @@ INCLUDEPATH += $$OS_LAYER_STDCPP_SYSTEMINCLUDE INCLUDEPATH -= $$[QT_INSTALL_PREFIX]/mkspecs/common/symbian/stl-off # libstdcppv5 is preferred over libstdcpp as it has/uses the throwing version of operator new -exists($${EPOCROOT}epoc32/release/armv5/urel/libstdcppv5.dll)|exists($${EPOCROOT}epoc32/release/winscw/udeb/libstdcppv5.dll) { - LIBS *= -llibstdcppv5.dll +STL_LIB = -llibstdcppv5.dll - # STDCPP turns on standard C++ new behaviour (ie. throwing new) - MMP_RULES += "STDCPP" -} else { - LIBS *= -llibstdcpp.dll +# STDCPP turns on standard C++ new behaviour (ie. throwing new) +STL_MMP_RULE = "STDCPP" + +# Fall back to old implementation if that is the only one that is found +exists($${EPOCROOT}epoc32/release/armv5/urel/libstdcpp.dll)|exists($${EPOCROOT}epoc32/release/winscw/udeb/libstdcpp.dll) { + !exists($${EPOCROOT}epoc32/release/armv5/urel/libstdcppv5.dll):!exists($${EPOCROOT}epoc32/release/winscw/udeb/libstdcppv5.dll) { + STL_LIB = -llibstdcpp.dll + STL_MMP_RULE = + } } + +LIBS *= $$STL_LIB +MMP_RULES *= $$STL_MMP_RULE -- cgit v0.12 From e9dedf5b10fcc25454d01a588d5000437cb46e12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20R=C3=B8dal?= Date: Fri, 19 Feb 2010 11:35:17 +0100 Subject: Fixed off-by-one blending errors in the NEON drawhelper code. For example blending alpha 0xff with alpha 0xff and a 0.5 opacity gave a result of 0xfe instead of the correct 0xff. This caused some autotests to fail on ARM/NEON. Reviewed-by: TrustMe --- src/gui/painting/qdrawhelper_neon.cpp | 130 +++++++++++++++++----------------- 1 file changed, 65 insertions(+), 65 deletions(-) diff --git a/src/gui/painting/qdrawhelper_neon.cpp b/src/gui/painting/qdrawhelper_neon.cpp index 25860a0..77c5202 100644 --- a/src/gui/painting/qdrawhelper_neon.cpp +++ b/src/gui/painting/qdrawhelper_neon.cpp @@ -48,43 +48,43 @@ QT_BEGIN_NAMESPACE -static inline int16x8_t qvdiv_255_s16(int16x8_t x, int16x8_t half) +static inline uint16x8_t qvdiv_255_u16(uint16x8_t x, uint16x8_t half) { // result = (x + (x >> 8) + 0x80) >> 8 - const int16x8_t temp = vshrq_n_s16(x, 8); // x >> 8 - const int16x8_t sum_part = vaddq_s16(x, half); // x + 0x80 - const int16x8_t sum = vaddq_s16(temp, sum_part); + const uint16x8_t temp = vshrq_n_u16(x, 8); // x >> 8 + const uint16x8_t sum_part = vaddq_u16(x, half); // x + 0x80 + const uint16x8_t sum = vaddq_u16(temp, sum_part); - return vreinterpretq_s16_u16(vshrq_n_u16(vreinterpretq_u16_s16(sum), 8)); + return vshrq_n_u16(sum, 8); } -static inline int16x8_t qvbyte_mul_s16(int16x8_t x, int16x8_t alpha, int16x8_t half) +static inline uint16x8_t qvbyte_mul_u16(uint16x8_t x, uint16x8_t alpha, uint16x8_t half) { // t = qRound(x * alpha / 255.0) - const int16x8_t t = vmulq_s16(x, alpha); // t - return qvdiv_255_s16(t, half); + const uint16x8_t t = vmulq_u16(x, alpha); // t + return qvdiv_255_u16(t, half); } -static inline int16x8_t qvinterpolate_pixel_255(int16x8_t x, int16x8_t a, int16x8_t y, int16x8_t b, int16x8_t half) +static inline uint16x8_t qvinterpolate_pixel_255(uint16x8_t x, uint16x8_t a, uint16x8_t y, uint16x8_t b, uint16x8_t half) { // t = x * a + y * b - const int16x8_t ta = vmulq_s16(x, a); - const int16x8_t tb = vmulq_s16(y, b); + const uint16x8_t ta = vmulq_u16(x, a); + const uint16x8_t tb = vmulq_u16(y, b); - return qvdiv_255_s16(vaddq_s16(ta, tb), half); + return qvdiv_255_u16(vaddq_u16(ta, tb), half); } -static inline int16x8_t qvsource_over_s16(int16x8_t src16, int16x8_t dst16, int16x8_t half, int16x8_t full) +static inline uint16x8_t qvsource_over_u16(uint16x8_t src16, uint16x8_t dst16, uint16x8_t half, uint16x8_t full) { - const int16x4_t alpha16_high = vdup_lane_s16(vget_high_s16(src16), 3); - const int16x4_t alpha16_low = vdup_lane_s16(vget_low_s16(src16), 3); + const uint16x4_t alpha16_high = vdup_lane_u16(vget_high_u16(src16), 3); + const uint16x4_t alpha16_low = vdup_lane_u16(vget_low_u16(src16), 3); - const int16x8_t alpha16 = vsubq_s16(full, vcombine_s16(alpha16_low, alpha16_high)); + const uint16x8_t alpha16 = vsubq_u16(full, vcombine_u16(alpha16_low, alpha16_high)); - return vaddq_s16(src16, qvbyte_mul_s16(dst16, alpha16, half)); + return vaddq_u16(src16, qvbyte_mul_u16(dst16, alpha16, half)); } void qt_blend_argb32_on_argb32_neon(uchar *destPixels, int dbpl, @@ -94,21 +94,21 @@ void qt_blend_argb32_on_argb32_neon(uchar *destPixels, int dbpl, { const uint *src = (const uint *) srcPixels; uint *dst = (uint *) destPixels; - int16x8_t half = vdupq_n_s16(0x80); - int16x8_t full = vdupq_n_s16(0xff); + uint16x8_t half = vdupq_n_u16(0x80); + uint16x8_t full = vdupq_n_u16(0xff); if (const_alpha == 256) { for (int y = 0; y < h; ++y) { int x = 0; for (; x < w-3; x += 4) { - int32x4_t src32 = vld1q_s32((int32_t *)&src[x]); + uint32x4_t src32 = vld1q_u32((uint32_t *)&src[x]); if ((src[x] & src[x+1] & src[x+2] & src[x+3]) >= 0xff000000) { // all opaque - vst1q_s32((int32_t *)&dst[x], src32); + vst1q_u32((uint32_t *)&dst[x], src32); } else if (src[x] | src[x+1] | src[x+2] | src[x+3]) { - int32x4_t dst32 = vld1q_s32((int32_t *)&dst[x]); + uint32x4_t dst32 = vld1q_u32((uint32_t *)&dst[x]); - const uint8x16_t src8 = vreinterpretq_u8_s32(src32); - const uint8x16_t dst8 = vreinterpretq_u8_s32(dst32); + const uint8x16_t src8 = vreinterpretq_u8_u32(src32); + const uint8x16_t dst8 = vreinterpretq_u8_u32(dst32); const uint8x8_t src8_low = vget_low_u8(src8); const uint8x8_t dst8_low = vget_low_u8(dst8); @@ -116,19 +116,19 @@ void qt_blend_argb32_on_argb32_neon(uchar *destPixels, int dbpl, const uint8x8_t src8_high = vget_high_u8(src8); const uint8x8_t dst8_high = vget_high_u8(dst8); - const int16x8_t src16_low = vreinterpretq_s16_u16(vmovl_u8(src8_low)); - const int16x8_t dst16_low = vreinterpretq_s16_u16(vmovl_u8(dst8_low)); + const uint16x8_t src16_low = vmovl_u8(src8_low); + const uint16x8_t dst16_low = vmovl_u8(dst8_low); - const int16x8_t src16_high = vreinterpretq_s16_u16(vmovl_u8(src8_high)); - const int16x8_t dst16_high = vreinterpretq_s16_u16(vmovl_u8(dst8_high)); + const uint16x8_t src16_high = vmovl_u8(src8_high); + const uint16x8_t dst16_high = vmovl_u8(dst8_high); - const int16x8_t result16_low = qvsource_over_s16(src16_low, dst16_low, half, full); - const int16x8_t result16_high = qvsource_over_s16(src16_high, dst16_high, half, full); + const uint16x8_t result16_low = qvsource_over_u16(src16_low, dst16_low, half, full); + const uint16x8_t result16_high = qvsource_over_u16(src16_high, dst16_high, half, full); - const int32x2_t result32_low = vreinterpret_s32_s8(vmovn_s16(result16_low)); - const int32x2_t result32_high = vreinterpret_s32_s8(vmovn_s16(result16_high)); + const uint32x2_t result32_low = vreinterpret_u32_u8(vmovn_u16(result16_low)); + const uint32x2_t result32_high = vreinterpret_u32_u8(vmovn_u16(result16_high)); - vst1q_s32((int32_t *)&dst[x], vcombine_s32(result32_low, result32_high)); + vst1q_u32((uint32_t *)&dst[x], vcombine_u32(result32_low, result32_high)); } } for (; x> 8; - int16x8_t const_alpha16 = vdupq_n_s16(const_alpha); + uint16x8_t const_alpha16 = vdupq_n_u16(const_alpha); for (int y = 0; y < h; ++y) { int x = 0; for (; x < w-3; x += 4) { if (src[x] | src[x+1] | src[x+2] | src[x+3]) { - int32x4_t src32 = vld1q_s32((int32_t *)&src[x]); - int32x4_t dst32 = vld1q_s32((int32_t *)&dst[x]); + uint32x4_t src32 = vld1q_u32((uint32_t *)&src[x]); + uint32x4_t dst32 = vld1q_u32((uint32_t *)&dst[x]); - const uint8x16_t src8 = vreinterpretq_u8_s32(src32); - const uint8x16_t dst8 = vreinterpretq_u8_s32(dst32); + const uint8x16_t src8 = vreinterpretq_u8_u32(src32); + const uint8x16_t dst8 = vreinterpretq_u8_u32(dst32); const uint8x8_t src8_low = vget_low_u8(src8); const uint8x8_t dst8_low = vget_low_u8(dst8); @@ -160,22 +160,22 @@ void qt_blend_argb32_on_argb32_neon(uchar *destPixels, int dbpl, const uint8x8_t src8_high = vget_high_u8(src8); const uint8x8_t dst8_high = vget_high_u8(dst8); - const int16x8_t src16_low = vreinterpretq_s16_u16(vmovl_u8(src8_low)); - const int16x8_t dst16_low = vreinterpretq_s16_u16(vmovl_u8(dst8_low)); + const uint16x8_t src16_low = vmovl_u8(src8_low); + const uint16x8_t dst16_low = vmovl_u8(dst8_low); - const int16x8_t src16_high = vreinterpretq_s16_u16(vmovl_u8(src8_high)); - const int16x8_t dst16_high = vreinterpretq_s16_u16(vmovl_u8(dst8_high)); + const uint16x8_t src16_high = vmovl_u8(src8_high); + const uint16x8_t dst16_high = vmovl_u8(dst8_high); - const int16x8_t srcalpha16_low = qvbyte_mul_s16(src16_low, const_alpha16, half); - const int16x8_t srcalpha16_high = qvbyte_mul_s16(src16_high, const_alpha16, half); + const uint16x8_t srcalpha16_low = qvbyte_mul_u16(src16_low, const_alpha16, half); + const uint16x8_t srcalpha16_high = qvbyte_mul_u16(src16_high, const_alpha16, half); - const int16x8_t result16_low = qvsource_over_s16(srcalpha16_low, dst16_low, half, full); - const int16x8_t result16_high = qvsource_over_s16(srcalpha16_high, dst16_high, half, full); + const uint16x8_t result16_low = qvsource_over_u16(srcalpha16_low, dst16_low, half, full); + const uint16x8_t result16_high = qvsource_over_u16(srcalpha16_high, dst16_high, half, full); - const int32x2_t result32_low = vreinterpret_s32_s8(vmovn_s16(result16_low)); - const int32x2_t result32_high = vreinterpret_s32_s8(vmovn_s16(result16_high)); + const uint32x2_t result32_low = vreinterpret_u32_u8(vmovn_u16(result16_low)); + const uint32x2_t result32_high = vreinterpret_u32_u8(vmovn_u16(result16_high)); - vst1q_s32((int32_t *)&dst[x], vcombine_s32(result32_low, result32_high)); + vst1q_u32((uint32_t *)&dst[x], vcombine_u32(result32_low, result32_high)); } } for (; x> 8; int one_minus_const_alpha = 255 - const_alpha; - int16x8_t const_alpha16 = vdupq_n_s16(const_alpha); - int16x8_t one_minus_const_alpha16 = vdupq_n_s16(255 - const_alpha); + uint16x8_t const_alpha16 = vdupq_n_u16(const_alpha); + uint16x8_t one_minus_const_alpha16 = vdupq_n_u16(255 - const_alpha); for (int y = 0; y < h; ++y) { int x = 0; for (; x < w-3; x += 4) { - int32x4_t src32 = vld1q_s32((int32_t *)&src[x]); - int32x4_t dst32 = vld1q_s32((int32_t *)&dst[x]); + uint32x4_t src32 = vld1q_u32((uint32_t *)&src[x]); + uint32x4_t dst32 = vld1q_u32((uint32_t *)&dst[x]); - const uint8x16_t src8 = vreinterpretq_u8_s32(src32); - const uint8x16_t dst8 = vreinterpretq_u8_s32(dst32); + const uint8x16_t src8 = vreinterpretq_u8_u32(src32); + const uint8x16_t dst8 = vreinterpretq_u8_u32(dst32); const uint8x8_t src8_low = vget_low_u8(src8); const uint8x8_t dst8_low = vget_low_u8(dst8); @@ -226,19 +226,19 @@ void qt_blend_rgb32_on_rgb32_neon(uchar *destPixels, int dbpl, const uint8x8_t src8_high = vget_high_u8(src8); const uint8x8_t dst8_high = vget_high_u8(dst8); - const int16x8_t src16_low = vreinterpretq_s16_u16(vmovl_u8(src8_low)); - const int16x8_t dst16_low = vreinterpretq_s16_u16(vmovl_u8(dst8_low)); + const uint16x8_t src16_low = vmovl_u8(src8_low); + const uint16x8_t dst16_low = vmovl_u8(dst8_low); - const int16x8_t src16_high = vreinterpretq_s16_u16(vmovl_u8(src8_high)); - const int16x8_t dst16_high = vreinterpretq_s16_u16(vmovl_u8(dst8_high)); + const uint16x8_t src16_high = vmovl_u8(src8_high); + const uint16x8_t dst16_high = vmovl_u8(dst8_high); - const int16x8_t result16_low = qvinterpolate_pixel_255(src16_low, const_alpha16, dst16_low, one_minus_const_alpha16, half); - const int16x8_t result16_high = qvinterpolate_pixel_255(src16_high, const_alpha16, dst16_high, one_minus_const_alpha16, half); + const uint16x8_t result16_low = qvinterpolate_pixel_255(src16_low, const_alpha16, dst16_low, one_minus_const_alpha16, half); + const uint16x8_t result16_high = qvinterpolate_pixel_255(src16_high, const_alpha16, dst16_high, one_minus_const_alpha16, half); - const int32x2_t result32_low = vreinterpret_s32_s8(vmovn_s16(result16_low)); - const int32x2_t result32_high = vreinterpret_s32_s8(vmovn_s16(result16_high)); + const uint32x2_t result32_low = vreinterpret_u32_u8(vmovn_u16(result16_low)); + const uint32x2_t result32_high = vreinterpret_u32_u8(vmovn_u16(result16_high)); - vst1q_s32((int32_t *)&dst[x], vcombine_s32(result32_low, result32_high)); + vst1q_u32((uint32_t *)&dst[x], vcombine_u32(result32_low, result32_high)); } for (; x Date: Fri, 19 Feb 2010 13:12:06 +0100 Subject: Ensure that posted events are sent on Windows Commit f21d183 introduced a GetMessage hook that would try to post a message to the Windows queue if the hook received an event that was not the WM_QT_SENDPOSTEDEVENTS message. However, the logic used is flawed, and would never post the message unless we received a message for a window that was not the event dispatcher's internal window. Timer messages DO go to the internal window, and the last handled timer message SHOULD trigger the hook to post a new WM_QT_SENDPOSTEDEVENTS, but due to the flawed logic, it would not. The most notable side effect of this bug is that regular repaints and animations would not become visible unless the user moved the mouse or used the keyboard. Task-number: QTBUG-7728 Reviewed-by: Andreas Aardal Hanssen Fix verified by 2 users in the Jira report mentioned above. --- src/corelib/kernel/qeventdispatcher_win.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/corelib/kernel/qeventdispatcher_win.cpp b/src/corelib/kernel/qeventdispatcher_win.cpp index 93becc8..8010a76 100644 --- a/src/corelib/kernel/qeventdispatcher_win.cpp +++ b/src/corelib/kernel/qeventdispatcher_win.cpp @@ -510,8 +510,8 @@ LRESULT CALLBACK qt_GetMessageHook(int code, WPARAM wp, LPARAM lp) MSG *msg = (MSG *) lp; if (localSerialNumber != d->lastSerialNumber // if this message IS the one that triggers sendPostedEvents(), no need to post it again - && msg->hwnd != d->internalHwnd - && msg->message != WM_QT_SENDPOSTEDEVENTS) { + && (msg->hwnd != d->internalHwnd + || msg->message != WM_QT_SENDPOSTEDEVENTS)) { PostMessage(d->internalHwnd, WM_QT_SENDPOSTEDEVENTS, 0, 0); } } -- cgit v0.12 From 145f46347bdcdf0efe2821b8ae2c34f53c543d1c Mon Sep 17 00:00:00 2001 From: Sami Merila Date: Fri, 19 Feb 2010 14:23:47 +0200 Subject: Supressed Icon sizes on QPushButton in QS60Style QS60Style should have smaller button margins when icon height is larger than text height within a button. Task-number: QTBUG-7586 Reviewed-by: Alessandro Portale --- src/gui/styles/qs60style.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/gui/styles/qs60style.cpp b/src/gui/styles/qs60style.cpp index 74707af..565cc2c 100644 --- a/src/gui/styles/qs60style.cpp +++ b/src/gui/styles/qs60style.cpp @@ -2396,10 +2396,20 @@ QSize QS60Style::sizeFromContents(ContentsType ct, const QStyleOption *opt, case CT_PushButton: sz = QCommonStyle::sizeFromContents( ct, opt, csz, widget); //FIXME properly - style should calculate the location of border frame-part - sz += QSize(2 * pixelMetric(PM_ButtonMargin), 2 * pixelMetric(PM_ButtonMargin)); - if (const QAbstractButton *buttonWidget = (qobject_cast(widget))) + if (const QAbstractButton *buttonWidget = (qobject_cast(widget))) { if (buttonWidget->isCheckable()) sz += QSize(pixelMetric(PM_IndicatorWidth) + pixelMetric(PM_CheckBoxLabelSpacing), 0); + const int iconHeight = (!buttonWidget->icon().isNull()) ? buttonWidget->iconSize().height() : 0; + const int textHeight = (buttonWidget->text().length() > 0) ? + buttonWidget->fontMetrics().size(Qt::TextSingleLine, buttonWidget->text()).height() : 0; + const int decoratorHeight = (buttonWidget->isCheckable()) ? pixelMetric(PM_IndicatorHeight) : 0; + + const int contentHeight = + qMax(qMax(iconHeight, decoratorHeight) + pixelMetric(PM_ButtonMargin), + textHeight + 2*pixelMetric(PM_ButtonMargin)); + sz.setHeight(contentHeight); + sz += QSize(2 * pixelMetric(PM_ButtonMargin), 0); + } break; case CT_LineEdit: if (const QStyleOptionFrame *f = qstyleoption_cast(opt)) -- cgit v0.12 From 53fce0ced68ae5d828dc19d05caa09e05b4e5151 Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Fri, 19 Feb 2010 14:47:38 +0100 Subject: Fix building in a namespace on Windows Reviewed-by: hjk --- src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp index 8235a5c..c08d04a 100644 --- a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp +++ b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp @@ -89,6 +89,9 @@ QT_BEGIN_NAMESPACE //#define QT_GL_NO_SCISSOR_TEST +#if defined(Q_WS_WIN) +extern Q_GUI_EXPORT bool qt_cleartype_enabled; +#endif extern QImage qt_imageForBrush(int brushStyle, bool invert); @@ -1555,7 +1558,6 @@ bool QGL2PaintEngineEx::begin(QPaintDevice *pdev) #if !defined(QT_OPENGL_ES_2) #if defined(Q_WS_WIN) - extern Q_GUI_EXPORT bool qt_cleartype_enabled; if (qt_cleartype_enabled) #endif d->glyphCacheType = QFontEngineGlyphCache::Raster_RGBMask; -- cgit v0.12 From 7ce06afb341240b102edcc83b33d0da3d9e7ab5e Mon Sep 17 00:00:00 2001 From: Markus Goetz Date: Fri, 19 Feb 2010 13:49:58 +0100 Subject: tst_qnetworkreply: Check if TCP/HTTP connection got re-used Reviewed-by: Peter Hartmann --- tests/auto/qnetworkreply/tst_qnetworkreply.cpp | 131 +++++++++++++++++++++++-- 1 file changed, 124 insertions(+), 7 deletions(-) diff --git a/tests/auto/qnetworkreply/tst_qnetworkreply.cpp b/tests/auto/qnetworkreply/tst_qnetworkreply.cpp index 049bbb8..78b4d98 100644 --- a/tests/auto/qnetworkreply/tst_qnetworkreply.cpp +++ b/tests/auto/qnetworkreply/tst_qnetworkreply.cpp @@ -257,6 +257,11 @@ private Q_SLOTS: void httpConnectionCount(); + void httpReUsingConnectionSequential_data(); + void httpReUsingConnectionSequential(); + void httpReUsingConnectionFromFinishedSlot_data(); + void httpReUsingConnectionFromFinishedSlot(); + void httpRecursiveCreation(); #ifndef QT_NO_OPENSSL @@ -314,18 +319,20 @@ QT_END_NAMESPACE QFAIL(qPrintable(errorMsg)); \ } while (0); + +// Does not work for POST/PUT! class MiniHttpServer: public QTcpServer { Q_OBJECT - QTcpSocket *client; - public: + QTcpSocket *client; // always the last one that was received QByteArray dataToTransmit; QByteArray receivedData; bool doClose; + bool multiple; int totalConnections; - MiniHttpServer(const QByteArray &data) : client(0), dataToTransmit(data), doClose(true), totalConnections(0) + MiniHttpServer(const QByteArray &data) : client(0), dataToTransmit(data), doClose(true), multiple(false), totalConnections(0) { listen(); connect(this, SIGNAL(newConnection()), this, SLOT(doAccept())); @@ -335,15 +342,21 @@ public slots: void doAccept() { client = nextPendingConnection(); + client->setParent(this); ++totalConnections; - connect(client, SIGNAL(readyRead()), this, SLOT(sendData())); + connect(client, SIGNAL(readyRead()), this, SLOT(readyReadSlot())); } - void sendData() + void readyReadSlot() { receivedData += client->readAll(); - if (receivedData.contains("\r\n\r\n") || - receivedData.contains("\n\n")) { + int doubleEndlPos = receivedData.indexOf("\r\n\r\n"); + + if (doubleEndlPos != -1) { + // multiple requests incoming. remove the bytes of the current one + if (multiple) + receivedData.remove(0, doubleEndlPos+4); + client->write(dataToTransmit); if (doClose) { client->disconnectFromHost(); @@ -3790,6 +3803,110 @@ void tst_QNetworkReply::httpConnectionCount() #endif } +void tst_QNetworkReply::httpReUsingConnectionSequential_data() +{ + QTest::addColumn("doDeleteLater"); + QTest::newRow("deleteLater") << true; + QTest::newRow("noDeleteLater") << false; +} + +void tst_QNetworkReply::httpReUsingConnectionSequential() +{ + QFETCH(bool, doDeleteLater); + + QByteArray response("HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n"); + MiniHttpServer server(response); + server.multiple = true; + server.doClose = false; + + QUrl url; + url.setScheme("http"); + url.setPort(server.serverPort()); + url.setHost("127.0.0.1"); + // first request + QNetworkReply* reply1 = manager.get(QNetworkRequest(url)); + connect(reply1, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); + QTestEventLoop::instance().enterLoop(2); + QVERIFY(!QTestEventLoop::instance().timeout()); + QVERIFY(!reply1->error()); + int reply1port = server.client->peerPort(); + + if (doDeleteLater) + reply1->deleteLater(); + + // finished received, send the next one + QNetworkReply*reply2 = manager.get(QNetworkRequest(url)); + connect(reply2, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); + QTestEventLoop::instance().enterLoop(2); + QVERIFY(!QTestEventLoop::instance().timeout()); + QVERIFY(!reply2->error()); + int reply2port = server.client->peerPort(); // should still be the same object + + QVERIFY(reply1port > 0); + QCOMPARE(server.totalConnections, 1); + QCOMPARE(reply2port, reply1port); + + if (!doDeleteLater) + reply1->deleteLater(); // only do it if it was not done earlier + reply2->deleteLater(); +} + +class HttpReUsingConnectionFromFinishedSlot : public QObject { + Q_OBJECT; +public: + QNetworkReply* reply1; + QNetworkReply* reply2; + QUrl url; + QNetworkAccessManager manager; +public slots: + void finishedSlot() { + QVERIFY(!reply1->error()); + + QFETCH(bool, doDeleteLater); + if (doDeleteLater) { + reply1->deleteLater(); + reply1 = 0; + } + + // kick off 2nd request and exit the loop when it is done + reply2 = manager.get(QNetworkRequest(url)); + reply2->setParent(this); + connect(reply2, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); + } +}; + +void tst_QNetworkReply::httpReUsingConnectionFromFinishedSlot_data() +{ + httpReUsingConnectionSequential_data(); +} + +void tst_QNetworkReply::httpReUsingConnectionFromFinishedSlot() +{ + QByteArray response("HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n"); + MiniHttpServer server(response); + server.multiple = true; + server.doClose = false; + + HttpReUsingConnectionFromFinishedSlot helper; + helper.reply1 = 0; + helper.reply2 = 0; + helper.url.setScheme("http"); + helper.url.setPort(server.serverPort()); + helper.url.setHost("127.0.0.1"); + + // first request + helper.reply1 = helper.manager.get(QNetworkRequest(helper.url)); + helper.reply1->setParent(&helper); + connect(helper.reply1, SIGNAL(finished()), &helper, SLOT(finishedSlot())); + QTestEventLoop::instance().enterLoop(4); + QVERIFY(!QTestEventLoop::instance().timeout()); + + QVERIFY(helper.reply2); + QVERIFY(!helper.reply2->error()); + + QCOMPARE(server.totalConnections, 1); +} + class HttpRecursiveCreationHelper : public QObject { Q_OBJECT public: -- cgit v0.12 From 4cabe964bc02e07fe96dd8fda5f8c73a6e1d6a12 Mon Sep 17 00:00:00 2001 From: Gareth Stockwell Date: Fri, 19 Feb 2010 14:32:17 +0000 Subject: Fix incorrect license headers Fixes incorrect license headers used on files added by 28610950. --- src/plugins/audio/symbian/main.cpp | 36 +++++++++++----------- src/plugins/audio/symbian/symbianaudio.h | 36 +++++++++++----------- .../audio/symbian/symbianaudiodeviceinfo.cpp | 36 +++++++++++----------- src/plugins/audio/symbian/symbianaudiodeviceinfo.h | 36 +++++++++++----------- src/plugins/audio/symbian/symbianaudioinput.cpp | 36 +++++++++++----------- src/plugins/audio/symbian/symbianaudioinput.h | 36 +++++++++++----------- src/plugins/audio/symbian/symbianaudiooutput.cpp | 36 +++++++++++----------- src/plugins/audio/symbian/symbianaudiooutput.h | 36 +++++++++++----------- src/plugins/audio/symbian/symbianaudioutils.cpp | 36 +++++++++++----------- src/plugins/audio/symbian/symbianaudioutils.h | 36 +++++++++++----------- 10 files changed, 180 insertions(+), 180 deletions(-) diff --git a/src/plugins/audio/symbian/main.cpp b/src/plugins/audio/symbian/main.cpp index 377944b..2299f8e 100644 --- a/src/plugins/audio/symbian/main.cpp +++ b/src/plugins/audio/symbian/main.cpp @@ -1,16 +1,17 @@ /**************************************************************************** ** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the plugins of the Qt Toolkit. +** This file is part of the FOO module 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 either Technology Preview License Agreement or the -** Beta Release License Agreement. +** 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 @@ -20,21 +21,20 @@ ** 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.0, included in the file LGPL_EXCEPTION.txt in this -** package. +** 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. +** +** +** +** +** +** ** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. ** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/src/plugins/audio/symbian/symbianaudio.h b/src/plugins/audio/symbian/symbianaudio.h index 527aa55..cfd08f1 100644 --- a/src/plugins/audio/symbian/symbianaudio.h +++ b/src/plugins/audio/symbian/symbianaudio.h @@ -1,16 +1,17 @@ /**************************************************************************** ** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the plugins of the Qt Toolkit. +** This file is part of the FOO module 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 either Technology Preview License Agreement or the -** Beta Release License Agreement. +** 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 @@ -20,21 +21,20 @@ ** 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.0, included in the file LGPL_EXCEPTION.txt in this -** package. +** 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. +** +** +** +** +** +** ** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. ** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/src/plugins/audio/symbian/symbianaudiodeviceinfo.cpp b/src/plugins/audio/symbian/symbianaudiodeviceinfo.cpp index b8d59de..1e57a06 100644 --- a/src/plugins/audio/symbian/symbianaudiodeviceinfo.cpp +++ b/src/plugins/audio/symbian/symbianaudiodeviceinfo.cpp @@ -1,16 +1,17 @@ /**************************************************************************** ** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the plugins of the Qt Toolkit. +** This file is part of the FOO module 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 either Technology Preview License Agreement or the -** Beta Release License Agreement. +** 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 @@ -20,21 +21,20 @@ ** 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.0, included in the file LGPL_EXCEPTION.txt in this -** package. +** 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. +** +** +** +** +** +** ** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. ** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/src/plugins/audio/symbian/symbianaudiodeviceinfo.h b/src/plugins/audio/symbian/symbianaudiodeviceinfo.h index 1df6afb..7916ddb 100644 --- a/src/plugins/audio/symbian/symbianaudiodeviceinfo.h +++ b/src/plugins/audio/symbian/symbianaudiodeviceinfo.h @@ -1,16 +1,17 @@ /**************************************************************************** ** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the plugins of the Qt Toolkit. +** This file is part of the FOO module 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 either Technology Preview License Agreement or the -** Beta Release License Agreement. +** 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 @@ -20,21 +21,20 @@ ** 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.0, included in the file LGPL_EXCEPTION.txt in this -** package. +** 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. +** +** +** +** +** +** ** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. ** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/src/plugins/audio/symbian/symbianaudioinput.cpp b/src/plugins/audio/symbian/symbianaudioinput.cpp index c1a6299..e442c11 100644 --- a/src/plugins/audio/symbian/symbianaudioinput.cpp +++ b/src/plugins/audio/symbian/symbianaudioinput.cpp @@ -1,16 +1,17 @@ /**************************************************************************** ** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the plugins of the Qt Toolkit. +** This file is part of the FOO module 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 either Technology Preview License Agreement or the -** Beta Release License Agreement. +** 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 @@ -20,21 +21,20 @@ ** 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.0, included in the file LGPL_EXCEPTION.txt in this -** package. +** 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. +** +** +** +** +** +** ** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. ** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/src/plugins/audio/symbian/symbianaudioinput.h b/src/plugins/audio/symbian/symbianaudioinput.h index 0497d7a..3f27ec5 100644 --- a/src/plugins/audio/symbian/symbianaudioinput.h +++ b/src/plugins/audio/symbian/symbianaudioinput.h @@ -1,16 +1,17 @@ /**************************************************************************** ** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the plugins of the Qt Toolkit. +** This file is part of the FOO module 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 either Technology Preview License Agreement or the -** Beta Release License Agreement. +** 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 @@ -20,21 +21,20 @@ ** 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.0, included in the file LGPL_EXCEPTION.txt in this -** package. +** 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. +** +** +** +** +** +** ** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. ** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/src/plugins/audio/symbian/symbianaudiooutput.cpp b/src/plugins/audio/symbian/symbianaudiooutput.cpp index 7e05211..501a262 100644 --- a/src/plugins/audio/symbian/symbianaudiooutput.cpp +++ b/src/plugins/audio/symbian/symbianaudiooutput.cpp @@ -1,16 +1,17 @@ /**************************************************************************** ** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the plugins of the Qt Toolkit. +** This file is part of the FOO module 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 either Technology Preview License Agreement or the -** Beta Release License Agreement. +** 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 @@ -20,21 +21,20 @@ ** 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.0, included in the file LGPL_EXCEPTION.txt in this -** package. +** 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. +** +** +** +** +** +** ** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. ** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/src/plugins/audio/symbian/symbianaudiooutput.h b/src/plugins/audio/symbian/symbianaudiooutput.h index 4db97c3..5bfcf44 100644 --- a/src/plugins/audio/symbian/symbianaudiooutput.h +++ b/src/plugins/audio/symbian/symbianaudiooutput.h @@ -1,16 +1,17 @@ /**************************************************************************** ** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the plugins of the Qt Toolkit. +** This file is part of the FOO module 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 either Technology Preview License Agreement or the -** Beta Release License Agreement. +** 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 @@ -20,21 +21,20 @@ ** 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.0, included in the file LGPL_EXCEPTION.txt in this -** package. +** 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. +** +** +** +** +** +** ** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. ** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/src/plugins/audio/symbian/symbianaudioutils.cpp b/src/plugins/audio/symbian/symbianaudioutils.cpp index 13ea03d..64288f9 100644 --- a/src/plugins/audio/symbian/symbianaudioutils.cpp +++ b/src/plugins/audio/symbian/symbianaudioutils.cpp @@ -1,16 +1,17 @@ /**************************************************************************** ** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the plugins of the Qt Toolkit. +** This file is part of the FOO module 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 either Technology Preview License Agreement or the -** Beta Release License Agreement. +** 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 @@ -20,21 +21,20 @@ ** 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.0, included in the file LGPL_EXCEPTION.txt in this -** package. +** 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. +** +** +** +** +** +** ** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. ** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. ** $QT_END_LICENSE$ ** ****************************************************************************/ diff --git a/src/plugins/audio/symbian/symbianaudioutils.h b/src/plugins/audio/symbian/symbianaudioutils.h index d9f992a..4aa891e 100644 --- a/src/plugins/audio/symbian/symbianaudioutils.h +++ b/src/plugins/audio/symbian/symbianaudioutils.h @@ -1,16 +1,17 @@ /**************************************************************************** ** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Qt Software Information (qt-info@nokia.com) +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the plugins of the Qt Toolkit. +** This file is part of the FOO module 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 either Technology Preview License Agreement or the -** Beta Release License Agreement. +** 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 @@ -20,21 +21,20 @@ ** 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.0, included in the file LGPL_EXCEPTION.txt in this -** package. +** 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. +** +** +** +** +** +** ** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. ** -** If you are unsure which license is appropriate for your use, please -** contact the sales department at qt-sales@nokia.com. ** $QT_END_LICENSE$ ** ****************************************************************************/ -- cgit v0.12 From fb5a1ad19109fe0eb88a84dd5e4b86c9849b90e6 Mon Sep 17 00:00:00 2001 From: Gareth Stockwell Date: Fri, 19 Feb 2010 14:39:48 +0000 Subject: Fix incorrect license headers Forgot to fill in the module name in 4cabe964. --- src/plugins/audio/symbian/main.cpp | 2 +- src/plugins/audio/symbian/symbianaudio.h | 2 +- src/plugins/audio/symbian/symbianaudiodeviceinfo.cpp | 2 +- src/plugins/audio/symbian/symbianaudiodeviceinfo.h | 2 +- src/plugins/audio/symbian/symbianaudioinput.cpp | 2 +- src/plugins/audio/symbian/symbianaudioinput.h | 2 +- src/plugins/audio/symbian/symbianaudiooutput.cpp | 2 +- src/plugins/audio/symbian/symbianaudiooutput.h | 2 +- src/plugins/audio/symbian/symbianaudioutils.cpp | 2 +- src/plugins/audio/symbian/symbianaudioutils.h | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/plugins/audio/symbian/main.cpp b/src/plugins/audio/symbian/main.cpp index 2299f8e..536a8ec 100644 --- a/src/plugins/audio/symbian/main.cpp +++ b/src/plugins/audio/symbian/main.cpp @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the FOO module of the Qt Toolkit. +** This file is part of the QtMultimedia module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/src/plugins/audio/symbian/symbianaudio.h b/src/plugins/audio/symbian/symbianaudio.h index cfd08f1..3fc0419 100644 --- a/src/plugins/audio/symbian/symbianaudio.h +++ b/src/plugins/audio/symbian/symbianaudio.h @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the FOO module of the Qt Toolkit. +** This file is part of the QtMultimedia module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/src/plugins/audio/symbian/symbianaudiodeviceinfo.cpp b/src/plugins/audio/symbian/symbianaudiodeviceinfo.cpp index 1e57a06..9701dad 100644 --- a/src/plugins/audio/symbian/symbianaudiodeviceinfo.cpp +++ b/src/plugins/audio/symbian/symbianaudiodeviceinfo.cpp @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the FOO module of the Qt Toolkit. +** This file is part of the QtMultimedia module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/src/plugins/audio/symbian/symbianaudiodeviceinfo.h b/src/plugins/audio/symbian/symbianaudiodeviceinfo.h index 7916ddb..250804d 100644 --- a/src/plugins/audio/symbian/symbianaudiodeviceinfo.h +++ b/src/plugins/audio/symbian/symbianaudiodeviceinfo.h @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the FOO module of the Qt Toolkit. +** This file is part of the QtMultimedia module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/src/plugins/audio/symbian/symbianaudioinput.cpp b/src/plugins/audio/symbian/symbianaudioinput.cpp index e442c11..8200925 100644 --- a/src/plugins/audio/symbian/symbianaudioinput.cpp +++ b/src/plugins/audio/symbian/symbianaudioinput.cpp @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the FOO module of the Qt Toolkit. +** This file is part of the QtMultimedia module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/src/plugins/audio/symbian/symbianaudioinput.h b/src/plugins/audio/symbian/symbianaudioinput.h index 3f27ec5..34b7d38 100644 --- a/src/plugins/audio/symbian/symbianaudioinput.h +++ b/src/plugins/audio/symbian/symbianaudioinput.h @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the FOO module of the Qt Toolkit. +** This file is part of the QtMultimedia module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/src/plugins/audio/symbian/symbianaudiooutput.cpp b/src/plugins/audio/symbian/symbianaudiooutput.cpp index 501a262..385e169 100644 --- a/src/plugins/audio/symbian/symbianaudiooutput.cpp +++ b/src/plugins/audio/symbian/symbianaudiooutput.cpp @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the FOO module of the Qt Toolkit. +** This file is part of the QtMultimedia module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/src/plugins/audio/symbian/symbianaudiooutput.h b/src/plugins/audio/symbian/symbianaudiooutput.h index 5bfcf44..8994e46 100644 --- a/src/plugins/audio/symbian/symbianaudiooutput.h +++ b/src/plugins/audio/symbian/symbianaudiooutput.h @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the FOO module of the Qt Toolkit. +** This file is part of the QtMultimedia module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/src/plugins/audio/symbian/symbianaudioutils.cpp b/src/plugins/audio/symbian/symbianaudioutils.cpp index 64288f9..f04c198 100644 --- a/src/plugins/audio/symbian/symbianaudioutils.cpp +++ b/src/plugins/audio/symbian/symbianaudioutils.cpp @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the FOO module of the Qt Toolkit. +** This file is part of the QtMultimedia module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/src/plugins/audio/symbian/symbianaudioutils.h b/src/plugins/audio/symbian/symbianaudioutils.h index 4aa891e..53274e0 100644 --- a/src/plugins/audio/symbian/symbianaudioutils.h +++ b/src/plugins/audio/symbian/symbianaudioutils.h @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the FOO module of the Qt Toolkit. +** This file is part of the QtMultimedia module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage -- cgit v0.12 From 0a7816943b11bb0338ee2cf880382825185058b4 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Fri, 19 Feb 2010 15:07:31 +0100 Subject: Get rid of the dependency on the Symbian app layer miutset.h is coming from the app layer that we are not supposed to use. Since we still need the constant we're better off working around the dependency and to forward declare the one constant we need from the file. Reviewed-By: Iain --- src/gui/util/qdesktopservices_s60.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/gui/util/qdesktopservices_s60.cpp b/src/gui/util/qdesktopservices_s60.cpp index 319c4b0..adc4fc1 100644 --- a/src/gui/util/qdesktopservices_s60.cpp +++ b/src/gui/util/qdesktopservices_s60.cpp @@ -48,7 +48,6 @@ #include #include -#include // KUidMsgTypeSMTP #include // CRichText #include // TDriveUnit etc #include // CEikonEnv @@ -57,6 +56,9 @@ #include // RSendAs #include // RSendAsMessage +// copied from miutset.h, so we don't get a dependency into the app layer +const TUid KUidMsgTypeSMTP = {0x10001028}; // 268439592 + #ifdef Q_WS_S60 # include // PathInfo # ifdef USE_DOCUMENTHANDLER -- cgit v0.12 From 54ac311352fd69e05481b739ddd2c937f4e7b858 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Fri, 19 Feb 2010 15:55:45 +0100 Subject: work around the current include file structure on Symbian^3 Reviewed-By: Iain --- src/qbase.pri | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/qbase.pri b/src/qbase.pri index db55365..6f2dfa4 100644 --- a/src/qbase.pri +++ b/src/qbase.pri @@ -108,6 +108,10 @@ symbian { } } load(armcc_warnings) + + # workaround for the fact that some of our required includes in Symbian^3 + # now depend upon files in epoc32/include/platform + INCLUDEPATH += $$OS_LAYER_SYSTEMINCLUDE } win32-borland:INCLUDEPATH += kernel -- cgit v0.12 From ee395a5b2f9e0d5f26884dbf40d06f3df7671282 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Fri, 19 Feb 2010 15:12:28 +0100 Subject: use egl properties when creating surfaces on symbian We are currently getting non premultiplied surfaces on symbian since we do not forward the egl properties that we'd like to have to the driver. Reviewed-By: Jason Barron --- src/gui/egl/qegl_symbian.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gui/egl/qegl_symbian.cpp b/src/gui/egl/qegl_symbian.cpp index b1c9408..5a010cd 100644 --- a/src/gui/egl/qegl_symbian.cpp +++ b/src/gui/egl/qegl_symbian.cpp @@ -78,9 +78,9 @@ EGLSurface QEglContext::createSurface(QPaintDevice *device, const QEglProperties props = 0; EGLSurface surf; if (devType == QInternal::Widget) - surf = eglCreateWindowSurface(dpy, cfg, windowDrawable, 0); + surf = eglCreateWindowSurface(dpy, cfg, windowDrawable, props); else - surf = eglCreatePixmapSurface(dpy, cfg, pixmapDrawable, 0); + surf = eglCreatePixmapSurface(dpy, cfg, pixmapDrawable, props); if (surf == EGL_NO_SURFACE) qWarning("QEglContext::createSurface(): Unable to create EGL surface, error = 0x%x", eglGetError()); return surf; -- cgit v0.12 From 1f049c91f91e069a975a72c1087a279d011535a5 Mon Sep 17 00:00:00 2001 From: Markus Goetz Date: Sun, 21 Feb 2010 19:47:01 +0100 Subject: loopback network example: Make use of bytesToWrite() Reviewed-by: TrustMe --- examples/network/loopback/dialog.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/examples/network/loopback/dialog.cpp b/examples/network/loopback/dialog.cpp index 27cff31..b504e36 100644 --- a/examples/network/loopback/dialog.cpp +++ b/examples/network/loopback/dialog.cpp @@ -44,12 +44,12 @@ #include "dialog.h" -#if !defined(Q_OS_WINCE) +#if !defined(Q_OS_WINCE) && !defined(Q_OS_SYMBIAN) static const int TotalBytes = 50 * 1024 * 1024; #else static const int TotalBytes = 5 * 1024 * 1024; #endif -static const int PayloadSize = 65536; +static const int PayloadSize = 64 * 1024; // 64 KB Dialog::Dialog(QWidget *parent) : QDialog(parent) @@ -130,6 +130,7 @@ void Dialog::acceptConnection() void Dialog::startTransfer() { + // called when the TCP client connected to the loopback server bytesToWrite = TotalBytes - (int)tcpClient.write(QByteArray(PayloadSize, '@')); clientStatusLabel->setText(tr("Connected")); } @@ -155,8 +156,11 @@ void Dialog::updateServerProgress() void Dialog::updateClientProgress(qint64 numBytes) { + // callen when the TCP client has written some bytes bytesWritten += (int)numBytes; - if (bytesToWrite > 0) + + // only write more if not finished and when the Qt write buffer is below a certain size. + if (bytesToWrite > 0 && tcpClient.bytesToWrite() <= 4*PayloadSize) bytesToWrite -= (int)tcpClient.write(QByteArray(qMin(bytesToWrite, PayloadSize), '@')); clientProgressBar->setMaximum(TotalBytes); -- cgit v0.12 From 2c924630caf449a26d92f227152bd4e0a19138f3 Mon Sep 17 00:00:00 2001 From: Rohan McGovern Date: Mon, 22 Feb 2010 11:29:28 +1000 Subject: Fixed failure of tst_symbols when Qt is configured with -qtnamespace Blacklist some symbols which cannot be namespaced when Qt is configured in a namespace. --- tests/auto/symbols/tst_symbols.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/auto/symbols/tst_symbols.cpp b/tests/auto/symbols/tst_symbols.cpp index e30481a..d6fb65a 100644 --- a/tests/auto/symbols/tst_symbols.cpp +++ b/tests/auto/symbols/tst_symbols.cpp @@ -212,6 +212,10 @@ void tst_Symbols::prefix() << "winfnt_driver_class" << "pshinter_module_class" << "psnames_module_class" + // C symbols from Qt + << "qt_addObject" + << "qt_removeObject" + << "qt_startup_hook" ; QHash excusedPrefixes; @@ -279,6 +283,10 @@ void tst_Symbols::prefix() << "cti" // ctiTrampoline and ctiVMThrowTrampoline from the JIT #ifdef QT_NAMESPACE << "QWeb" // Webkit is only 'namespace aware' + << "qWeb" + << "qt" + << "QGraphicsWebView" + << "operator" #endif ; @@ -331,6 +339,8 @@ void tst_Symbols::prefix() symbol = symbol.mid(symbol.indexOf(' ') + 1); } + if (symbol.mid(symbol.indexOf(' ')+1).startsWith("std::")) + continue; if (symbol.startsWith("_") || symbol.startsWith("std::")) continue; if (symbol.startsWith("vtable ") || symbol.startsWith("VTT for ") || @@ -342,6 +352,8 @@ void tst_Symbols::prefix() continue; if (symbol.startsWith(ns + "operator")) continue; + if (symbol.startsWith("operator new") || symbol.startsWith("operator delete")) + continue; if (symbol.startsWith("guard variable for ")) continue; if (symbol.contains("(" + ns + "QTextStream")) -- cgit v0.12 From f0c374a107c6f66b9d013fd25a6ba38bda13916d Mon Sep 17 00:00:00 2001 From: Rohan McGovern Date: Mon, 22 Feb 2010 11:54:06 +1000 Subject: Don't process uic3 subdir if qt3support is disabled. --- tests/auto/auto.pro | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro index af9832c..3d25656 100644 --- a/tests/auto/auto.pro +++ b/tests/auto/auto.pro @@ -11,7 +11,6 @@ TEMPLATE = subdirs maketestselftest \ moc \ uic \ - uic3 \ guiapplauncher \ #atwrapper \ # These tests need significant updating, #uiloader \ # they have hardcoded machine names etc. @@ -69,6 +68,9 @@ Q3SUBDIRS += \ q3uridrag \ q3widgetstack +!cross_compile:Q3SUBDIRS += \ + uic3 + SUBDIRS += \ # exceptionsafety_objects \ shouldn't enable it languagechange \ -- cgit v0.12 From 6f63f4a78090f50f40f2c65af85120a715835dab Mon Sep 17 00:00:00 2001 From: Rohan McGovern Date: Mon, 22 Feb 2010 13:17:11 +1000 Subject: Fixed shadow builds on Unix. --- qmake/Makefile.unix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qmake/Makefile.unix b/qmake/Makefile.unix index fa98fd6..d4f5849 100644 --- a/qmake/Makefile.unix +++ b/qmake/Makefile.unix @@ -66,7 +66,7 @@ DEPEND_SRC=project.cpp property.cpp meta.cpp main.cpp generators/makefile.cpp ge CPPFLAGS = -I. -Igenerators -Igenerators/unix -Igenerators/win32 -Igenerators/mac -Igenerators/symbian \ -I$(BUILD_PATH)/include -I$(BUILD_PATH)/include/QtCore \ -I$(BUILD_PATH)/src/corelib/global -I$(BUILD_PATH)/src/corelib/xml \ - -I$(BUILD_PATH)/tools/shared \ + -I$(SOURCE_PATH)/tools/shared \ -DQT_NO_PCRE \ -DQT_BUILD_QMAKE -DQT_BOOTSTRAPPED \ -DQT_NO_TEXTCODEC -DQT_NO_UNICODETABLES -DQT_NO_COMPONENT -DQT_NO_STL \ -- cgit v0.12 From 30ae64eaf42a2d7f80f70fb01c77a6ebcdfd1e98 Mon Sep 17 00:00:00 2001 From: Bill King Date: Mon, 22 Feb 2010 16:17:46 +1000 Subject: Fixes: make check not checking that target is up to date Builds the target executable if needed before running the test LR on BKing's machine. Reviewed-by: Lincoln Ramsay --- mkspecs/features/qttest_p4.prf | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/mkspecs/features/qttest_p4.prf b/mkspecs/features/qttest_p4.prf index e0b22f2..53c0d74 100644 --- a/mkspecs/features/qttest_p4.prf +++ b/mkspecs/features/qttest_p4.prf @@ -20,12 +20,32 @@ check.path = . macx: check.commands += ./$(QMAKE_TARGET).app/Contents/MacOS/$(QMAKE_TARGET) else:unix: check.commands += ./$(QMAKE_TARGET) else:win32: { - CONFIG(debug, debug|release):check.commands += debug\\$(QMAKE_TARGET) - else:check.commands += release\\$(QMAKE_TARGET) + CONFIG(debug, debug|release):check.commands += $(DESTDIR_TARGET) + else:check.commands += $(DESTDIR_TARGET) } embedded: check.commands += -qws QMAKE_EXTRA_TARGETS += check +!debug_and_release|build_pass { + check.depends = $(DESTDIR_TARGET) +} else { + check.CONFIG = recursive + # In debug and release mode, only run the test once. + # Run debug if available, release otherwise. + debug_and_release { + check.target = dummy_check + check.recurse_target = check + debug { + real_check.depends = debug-check + real_check.target = check + QMAKE_EXTRA_TARGETS += real_check + } else { + real_check.depends = release-check + real_check.target = check + QMAKE_EXTRA_TARGETS += real_check + } + } +} target.path += $$[QT_INSTALL_PREFIX]/tests/qt4 INSTALLS += target -- cgit v0.12 From 0a1e2e645bc1952c89d6ef560eccbe68e51f6ca8 Mon Sep 17 00:00:00 2001 From: ninerider Date: Mon, 22 Feb 2010 09:34:19 +0100 Subject: Fixes for the Windows Mobile plattform These fixes mainly concern compiling issues. --- tests/benchmarks/corelib/io/qdir/10000/bench_qdir_10000.cpp | 2 +- tests/benchmarks/corelib/io/qfileinfo/qfileinfo.pro | 2 +- .../gui/graphicsview/qgraphicsview/benchapps/chipTest/view.cpp | 7 +++++++ .../gui/graphicsview/qgraphicsview/benchapps/moveItems/main.cpp | 6 ++++++ .../gui/graphicsview/qgraphicsview/benchapps/scrolltest/main.cpp | 6 ++++++ .../qfile_vs_qnetworkaccessmanager.pro | 2 +- 6 files changed, 22 insertions(+), 3 deletions(-) diff --git a/tests/benchmarks/corelib/io/qdir/10000/bench_qdir_10000.cpp b/tests/benchmarks/corelib/io/qdir/10000/bench_qdir_10000.cpp index b325250..1238804 100644 --- a/tests/benchmarks/corelib/io/qdir/10000/bench_qdir_10000.cpp +++ b/tests/benchmarks/corelib/io/qdir/10000/bench_qdir_10000.cpp @@ -156,6 +156,7 @@ private slots: } void sizeSpeedWithoutFilterLowLevel() { + QDir testdir(QDir::tempPath() + QLatin1String("/test_speed")); #ifdef Q_OS_WIN const wchar_t *dirpath = (wchar_t*)testdir.absolutePath().utf16(); wchar_t appendedPath[MAX_PATH]; @@ -173,7 +174,6 @@ private slots: } FindClose(hSearch); #else - QDir testdir(QDir::tempPath() + QLatin1String("/test_speed")); DIR *dir = opendir(qPrintable(testdir.absolutePath())); QVERIFY(dir); diff --git a/tests/benchmarks/corelib/io/qfileinfo/qfileinfo.pro b/tests/benchmarks/corelib/io/qfileinfo/qfileinfo.pro index 295cb50..eca619f 100644 --- a/tests/benchmarks/corelib/io/qfileinfo/qfileinfo.pro +++ b/tests/benchmarks/corelib/io/qfileinfo/qfileinfo.pro @@ -1,6 +1,6 @@ load(qttest_p4) TEMPLATE = app -TARGET = qfileinfo +TARGET = tst_qfileinfo DEPENDPATH += . INCLUDEPATH += . diff --git a/tests/benchmarks/gui/graphicsview/qgraphicsview/benchapps/chipTest/view.cpp b/tests/benchmarks/gui/graphicsview/qgraphicsview/benchapps/chipTest/view.cpp index 1028f42..6c4ca08 100644 --- a/tests/benchmarks/gui/graphicsview/qgraphicsview/benchapps/chipTest/view.cpp +++ b/tests/benchmarks/gui/graphicsview/qgraphicsview/benchapps/chipTest/view.cpp @@ -42,7 +42,14 @@ #include "view.h" #include + +#ifdef Q_WS_WIN +#define CALLGRIND_START_INSTRUMENTATION {} +#define CALLGRIND_STOP_INSTRUMENTATION {} +#else #include "valgrind/callgrind.h" +#endif + #ifndef QT_NO_OPENGL #include #endif diff --git a/tests/benchmarks/gui/graphicsview/qgraphicsview/benchapps/moveItems/main.cpp b/tests/benchmarks/gui/graphicsview/qgraphicsview/benchapps/moveItems/main.cpp index 527713f..63b0da9 100644 --- a/tests/benchmarks/gui/graphicsview/qgraphicsview/benchapps/moveItems/main.cpp +++ b/tests/benchmarks/gui/graphicsview/qgraphicsview/benchapps/moveItems/main.cpp @@ -39,7 +39,13 @@ ** ****************************************************************************/ #include + +#ifdef Q_WS_WIN +#define CALLGRIND_START_INSTRUMENTATION {} +#define CALLGRIND_STOP_INSTRUMENTATION {} +#else #include "valgrind/callgrind.h" +#endif #ifdef Q_WS_X11 extern void qt_x11_wait_for_window_manager(QWidget *); diff --git a/tests/benchmarks/gui/graphicsview/qgraphicsview/benchapps/scrolltest/main.cpp b/tests/benchmarks/gui/graphicsview/qgraphicsview/benchapps/scrolltest/main.cpp index 7419206..3f30393 100644 --- a/tests/benchmarks/gui/graphicsview/qgraphicsview/benchapps/scrolltest/main.cpp +++ b/tests/benchmarks/gui/graphicsview/qgraphicsview/benchapps/scrolltest/main.cpp @@ -39,7 +39,13 @@ ** ****************************************************************************/ #include + +#ifdef Q_WS_WIN +#define CALLGRIND_START_INSTRUMENTATION {} +#define CALLGRIND_STOP_INSTRUMENTATION {} +#else #include "valgrind/callgrind.h" +#endif class ItemMover : public QObject { diff --git a/tests/benchmarks/network/access/qfile_vs_qnetworkaccessmanager/qfile_vs_qnetworkaccessmanager.pro b/tests/benchmarks/network/access/qfile_vs_qnetworkaccessmanager/qfile_vs_qnetworkaccessmanager.pro index 99d1935..89f5d31 100644 --- a/tests/benchmarks/network/access/qfile_vs_qnetworkaccessmanager/qfile_vs_qnetworkaccessmanager.pro +++ b/tests/benchmarks/network/access/qfile_vs_qnetworkaccessmanager/qfile_vs_qnetworkaccessmanager.pro @@ -1,6 +1,6 @@ load(qttest_p4) TEMPLATE = app -TARGET = qfile_vs_qnetworkaccessmanager +TARGET = tst_qfile_vs_qnetworkaccessmanager DEPENDPATH += . INCLUDEPATH += . -- cgit v0.12 From 1eb303d4f14dfcffcca3f11cacca7a73f1e53342 Mon Sep 17 00:00:00 2001 From: Jason Barron Date: Fri, 19 Feb 2010 12:05:44 +0100 Subject: Don't use vgClear() for semi-transparent brushes. If the brush is not totally opaque we should not use vgClear() at this point because vgClear() does not support blending. Instead it writes the values directly into the surface which clobbers any existing content. The bug exhibits itself when a child widget fills itself with any transparent color. Instead of blending with the parent widget's content, it writes the semi-transparent color directly to the surface, overwriting the parent content and leaving the surface in a somewhat undefined state because the alpha channel is not honoured unless Qt::WA_TranslucentBackground is set. Task-number: QTBUG-8007 Reviewed-by: Rhys Weatherley --- src/openvg/qpaintengine_vg.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/openvg/qpaintengine_vg.cpp b/src/openvg/qpaintengine_vg.cpp index 6813d2f..da47f06 100644 --- a/src/openvg/qpaintengine_vg.cpp +++ b/src/openvg/qpaintengine_vg.cpp @@ -2399,7 +2399,7 @@ void QVGPaintEngine::fillRect(const QRectF &rect, const QBrush &brush) return; // Check to see if we can use vgClear() for faster filling. - if (brush.style() == Qt::SolidPattern && + if (brush.style() == Qt::SolidPattern && brush.isOpaque() && clipTransformIsSimple(d->transform) && d->opacity == 1.0f && clearRect(rect, brush.color())) { return; @@ -2442,7 +2442,7 @@ void QVGPaintEngine::fillRect(const QRectF &rect, const QColor &color) Q_D(QVGPaintEngine); // Check to see if we can use vgClear() for faster filling. - if (clipTransformIsSimple(d->transform) && d->opacity == 1.0f && + if (clipTransformIsSimple(d->transform) && d->opacity == 1.0f && color.alpha() == 255 && clearRect(rect, color)) { return; } -- cgit v0.12 From a8af0c1aba81716bd0f609b1d9afe5c10951b303 Mon Sep 17 00:00:00 2001 From: Miikka Heikkinen Date: Mon, 22 Feb 2010 10:44:32 +0200 Subject: Changed canonical paths to absolute paths in symmake. Canonical paths were resolving to empty if the paths didn't exist, which causes problems for clean platform builds. Using absolute paths instead will generate all required paths. This will cause a minor inconvenience of warnings about some nonexistent paths during makefile generation phase of abld builds, but this is unavoidable. Sbsv2 builds do not display any warnings. Reviewed-by: Janne Anttila --- qmake/generators/symbian/symmake.cpp | 35 +++++++++++++---------------------- qmake/generators/symbian/symmake.h | 2 +- 2 files changed, 14 insertions(+), 23 deletions(-) diff --git a/qmake/generators/symbian/symmake.cpp b/qmake/generators/symbian/symmake.cpp index a712434..217c1c3 100644 --- a/qmake/generators/symbian/symmake.cpp +++ b/qmake/generators/symbian/symmake.cpp @@ -109,11 +109,13 @@ QString SymbianMakefileGenerator::fixPathForMmp(const QString& origPath, const Q { static QString epocRootStr; if (epocRootStr.isEmpty()) { - QFileInfo efi(epocRoot()); - epocRootStr = efi.canonicalFilePath(); - if (epocRootStr.isEmpty()) { + epocRootStr = epocRoot(); + QFileInfo efi(epocRootStr); + if (!efi.exists() || epocRootStr.isEmpty()) { fprintf(stderr, "Unable to resolve epocRoot '%s' to real dir on current drive, defaulting to '/' for mmp paths\n", qPrintable(epocRoot())); epocRootStr = "/"; + } else { + epocRootStr = efi.absoluteFilePath(); } if (!epocRootStr.endsWith("/")) epocRootStr += "/"; @@ -137,16 +139,8 @@ QString SymbianMakefileGenerator::fixPathForMmp(const QString& origPath, const Q return resultPath; } -QString SymbianMakefileGenerator::canonizePath(const QString& origPath) +QString SymbianMakefileGenerator::absolutizePath(const QString& origPath) { - // Since current path gets appended almost always anyway, use it as default - // for nonexisting paths. - static QString defaultPath; - if (defaultPath.isEmpty()) { - QFileInfo fi("."); - defaultPath = fi.canonicalFilePath(); - } - // Prepend epocroot to any paths beginning with "/epoc32/" QString resultPath = QDir::fromNativeSeparators(origPath); if (resultPath.startsWith("/epoc32/", Qt::CaseInsensitive)) @@ -154,16 +148,13 @@ QString SymbianMakefileGenerator::canonizePath(const QString& origPath) QFileInfo fi(fileInfo(resultPath)); if (fi.isDir()) { - resultPath = fi.canonicalFilePath(); + resultPath = fi.absoluteFilePath(); } else { - resultPath = fi.canonicalPath(); + resultPath = fi.absolutePath(); } resultPath = QDir::cleanPath(resultPath); - if (resultPath.isEmpty()) - resultPath = defaultPath; - return resultPath; } @@ -695,7 +686,7 @@ void SymbianMakefileGenerator::initMmpVariables() srcpaths << project->values("UI_DIR"); QDir current = QDir::current(); - QString canonizedCurrent = canonizePath("."); + QString absolutizedCurrent = absolutizePath("."); for (int j = 0; j < srcpaths.size(); ++j) { QFileInfo fi(fileInfo(srcpaths.at(j))); @@ -703,10 +694,10 @@ void SymbianMakefileGenerator::initMmpVariables() if (fi.suffix().startsWith("c")) { if (fi.filePath().length() > fi.fileName().length()) { appendIfnotExist(srcincpaths, fi.path()); - sources[canonizePath(fi.path())] += fi.fileName(); + sources[absolutizePath(fi.path())] += fi.fileName(); } else { - sources[canonizedCurrent] += fi.fileName(); - appendIfnotExist(srcincpaths, canonizedCurrent); + sources[absolutizedCurrent] += fi.fileName(); + appendIfnotExist(srcincpaths, absolutizedCurrent); } } } @@ -720,7 +711,7 @@ void SymbianMakefileGenerator::initMmpVariables() incpaths << project->values("UI_DIR"); for (int j = 0; j < incpaths.size(); ++j) { - QString includepath = canonizePath(incpaths.at(j)); + QString includepath = absolutizePath(incpaths.at(j)); appendIfnotExist(sysincspaths, includepath); appendAbldTempDirs(sysincspaths, includepath); } diff --git a/qmake/generators/symbian/symmake.h b/qmake/generators/symbian/symmake.h index 77d61da..542284c 100644 --- a/qmake/generators/symbian/symmake.h +++ b/qmake/generators/symbian/symmake.h @@ -84,7 +84,7 @@ protected: void removeSpecialCharacters(QString& str); QString fixPathForMmp(const QString& origPath, const QDir& parentDir); - QString canonizePath(const QString& origPath); + QString absolutizePath(const QString& origPath); virtual bool writeMakefile(QTextStream &t); void generatePkgFile(const QString &iconFile, DeploymentList &depList); -- cgit v0.12 From 561f2a3bf1ec74df87c3cd7c2641d34ce321c842 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Nilsen?= Date: Mon, 22 Feb 2010 11:40:41 +0100 Subject: Stabilize style sheet benchmarks. --- tests/benchmarks/gui/styles/qstylesheetstyle/main.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/benchmarks/gui/styles/qstylesheetstyle/main.cpp b/tests/benchmarks/gui/styles/qstylesheetstyle/main.cpp index 226b661..d051b12 100644 --- a/tests/benchmarks/gui/styles/qstylesheetstyle/main.cpp +++ b/tests/benchmarks/gui/styles/qstylesheetstyle/main.cpp @@ -82,6 +82,7 @@ void tst_qstylesheetstyle::empty() { QWidget *w = buildSimpleWidgets(); w->setStyleSheet("/* */"); + QApplication::processEvents(); int i = 0; QBENCHMARK { w->setStyleSheet("/*" + QString::number(i) + "*/"); @@ -94,6 +95,7 @@ void tst_qstylesheetstyle::empty_events() { QWidget *w = buildSimpleWidgets(); w->setStyleSheet("/* */"); + QApplication::processEvents(); int i = 0; QBENCHMARK { w->setStyleSheet("/*" + QString::number(i) + "*/"); @@ -112,6 +114,7 @@ void tst_qstylesheetstyle::simple() { QWidget *w = buildSimpleWidgets(); w->setStyleSheet("/* */"); + QApplication::processEvents(); int i = 0; QBENCHMARK { w->setStyleSheet(QString(simple_css) + "/*" + QString::number(i) + "*/"); @@ -124,6 +127,7 @@ void tst_qstylesheetstyle::simple_events() { QWidget *w = buildSimpleWidgets(); w->setStyleSheet("/* */"); + QApplication::processEvents(); int i = 0; QBENCHMARK { w->setStyleSheet(QString(simple_css) + "/*" + QString::number(i) + "*/"); @@ -175,8 +179,13 @@ void tst_qstylesheetstyle::grid() w->setStyleSheet("/* */"); if(show) { w->show(); + QTest::qWaitForWindowShown(w); + QApplication::flush(); + QApplication::processEvents(); QTest::qWait(30); + QApplication::processEvents(); } + QApplication::processEvents(); int i = 0; QBENCHMARK { w->setStyleSheet(stylesheet + "/*" + QString::number(i) + "*/"); -- cgit v0.12 From 0406b2665167d85b3cf348b615a049fb757afa62 Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Mon, 22 Feb 2010 12:32:58 +0100 Subject: amend the doc, as suggested by rittk Task-number: QTBUG-8070 --- src/corelib/io/qdatastream.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/corelib/io/qdatastream.cpp b/src/corelib/io/qdatastream.cpp index f27ecc1..0b98e1e 100644 --- a/src/corelib/io/qdatastream.cpp +++ b/src/corelib/io/qdatastream.cpp @@ -158,10 +158,9 @@ QT_BEGIN_NAMESPACE \section1 Reading and writing Qt collection classes - The Qt collection classes can also be serialized to a QDataStream. + The Qt container classes can also be serialized to a QDataStream. These include QList, QLinkedList, QVector, QSet, QHash, and QMap. - These classes have have stream operators declared as non-member of - the class. + The stream operators are declared as non-members of the classes. \target Serializing Qt Classes \section1 Reading and writing other Qt classes. -- cgit v0.12 From 4f2d34ed13bd63413e726229fd50c4b33f2d0127 Mon Sep 17 00:00:00 2001 From: Markus Goetz Date: Mon, 22 Feb 2010 12:36:30 +0100 Subject: Port http example to QNetworkAccessManager QHttp. Must. Die. Reviewed-by: Peter Hartmann --- examples/network/http/httpwindow.cpp | 129 ++++++++++++++++++----------------- examples/network/http/httpwindow.h | 23 ++++--- examples/network/http/main.cpp | 1 - 3 files changed, 82 insertions(+), 71 deletions(-) diff --git a/examples/network/http/httpwindow.cpp b/examples/network/http/httpwindow.cpp index 95fc82f..ec7cd33 100644 --- a/examples/network/http/httpwindow.cpp +++ b/examples/network/http/httpwindow.cpp @@ -49,9 +49,9 @@ HttpWindow::HttpWindow(QWidget *parent) : QDialog(parent) { #ifndef QT_NO_OPENSSL - urlLineEdit = new QLineEdit("https://"); + urlLineEdit = new QLineEdit("https://qt.nokia.com/"); #else - urlLineEdit = new QLineEdit("http://"); + urlLineEdit = new QLineEdit("http://qt.nokia.com/"); #endif urlLabel = new QLabel(tr("&URL:")); @@ -70,21 +70,14 @@ HttpWindow::HttpWindow(QWidget *parent) progressDialog = new QProgressDialog(this); - http = new QHttp(this); - connect(urlLineEdit, SIGNAL(textChanged(QString)), this, SLOT(enableDownloadButton())); - connect(http, SIGNAL(requestFinished(int,bool)), - this, SLOT(httpRequestFinished(int,bool))); - connect(http, SIGNAL(dataReadProgress(int,int)), - this, SLOT(updateDataReadProgress(int,int))); - connect(http, SIGNAL(responseHeaderReceived(QHttpResponseHeader)), - this, SLOT(readResponseHeader(QHttpResponseHeader))); - connect(http, SIGNAL(authenticationRequired(QString,quint16,QAuthenticator*)), - this, SLOT(slotAuthenticationRequired(QString,quint16,QAuthenticator*))); + + connect(&qnam, SIGNAL(authenticationRequired(QNetworkReply*,QAuthenticator*)), + this, SLOT(slotAuthenticationRequired(QNetworkReply*,QAuthenticator*))); #ifndef QT_NO_OPENSSL - connect(http, SIGNAL(sslErrors(QList)), - this, SLOT(sslErrors(QList))); + connect(&qnam, SIGNAL(sslErrors(QNetworkReply*,QList)), + this, SLOT(sslErrors(QNetworkReply*,QList))); #endif connect(progressDialog, SIGNAL(canceled()), this, SLOT(cancelDownload())); connect(downloadButton, SIGNAL(clicked()), this, SLOT(downloadFile())); @@ -104,9 +97,21 @@ HttpWindow::HttpWindow(QWidget *parent) urlLineEdit->setFocus(); } +void HttpWindow::startRequest(QUrl url) +{ + reply = qnam.get(QNetworkRequest(url)); + connect(reply, SIGNAL(finished()), + this, SLOT(httpFinished())); + connect(reply, SIGNAL(readyRead()), + this, SLOT(httpReadyRead())); + connect(reply, SIGNAL(downloadProgress(qint64,qint64)), + this, SLOT(updateDataReadProgress(qint64,qint64))); +} + void HttpWindow::downloadFile() { - QUrl url(urlLineEdit->text()); + url = urlLineEdit->text(); + QFileInfo fileInfo(url.path()); QString fileName = fileInfo.fileName(); if (fileName.isEmpty()) @@ -132,35 +137,26 @@ void HttpWindow::downloadFile() return; } - QHttp::ConnectionMode mode = url.scheme().toLower() == "https" ? QHttp::ConnectionModeHttps : QHttp::ConnectionModeHttp; - http->setHost(url.host(), mode, url.port() == -1 ? 0 : url.port()); - - if (!url.userName().isEmpty()) - http->setUser(url.userName(), url.password()); - - httpRequestAborted = false; - QByteArray path = QUrl::toPercentEncoding(url.path(), "!$&'()*+,;=:@/"); - if (path.isEmpty()) - path = "/"; - httpGetId = http->get(path, file); progressDialog->setWindowTitle(tr("HTTP")); progressDialog->setLabelText(tr("Downloading %1.").arg(fileName)); downloadButton->setEnabled(false); + + // schedule the request + httpRequestAborted = false; + startRequest(url); } void HttpWindow::cancelDownload() { statusLabel->setText(tr("Download canceled.")); httpRequestAborted = true; - http->abort(); + reply->abort(); downloadButton->setEnabled(true); } -void HttpWindow::httpRequestFinished(int requestId, bool error) +void HttpWindow::httpFinished() { - if (requestId != httpGetId) - return; if (httpRequestAborted) { if (file) { file->close(); @@ -168,54 +164,58 @@ void HttpWindow::httpRequestFinished(int requestId, bool error) delete file; file = 0; } - + reply->deleteLater(); progressDialog->hide(); return; } - if (requestId != httpGetId) - return; - progressDialog->hide(); + file->flush(); file->close(); - if (error) { + + QVariant redirectionTarget = reply->attribute(QNetworkRequest::RedirectionTargetAttribute); + if (reply->error()) { file->remove(); QMessageBox::information(this, tr("HTTP"), tr("Download failed: %1.") - .arg(http->errorString())); + .arg(reply->errorString())); + downloadButton->setEnabled(true); + } else if (!redirectionTarget.isNull()) { + QUrl newUrl = url.resolved(redirectionTarget.toUrl()); + if (QMessageBox::question(this, tr("HTTP"), + tr("Redirect to %1 ?").arg(newUrl.toString()), + QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) { + url = newUrl; + reply->deleteLater(); + file->open(QIODevice::WriteOnly); + file->resize(0); + startRequest(url); + return; + } } else { QString fileName = QFileInfo(QUrl(urlLineEdit->text()).path()).fileName(); statusLabel->setText(tr("Downloaded %1 to current directory.").arg(fileName)); + downloadButton->setEnabled(true); } - downloadButton->setEnabled(true); + reply->deleteLater(); + reply = 0; delete file; file = 0; } -void HttpWindow::readResponseHeader(const QHttpResponseHeader &responseHeader) +void HttpWindow::httpReadyRead() { - switch (responseHeader.statusCode()) { - case 200: // Ok - case 301: // Moved Permanently - case 302: // Found - case 303: // See Other - case 307: // Temporary Redirect - // these are not error conditions - break; - - default: - QMessageBox::information(this, tr("HTTP"), - tr("Download failed: %1.") - .arg(responseHeader.reasonPhrase())); - httpRequestAborted = true; - progressDialog->hide(); - http->abort(); - } + // this slot gets called everytime the QNetworkReply has new data. + // We read all of its new data and write it into the file. + // That way we use less RAM than when reading it at the finished() + // signal of the QNetworkReply + if (file) + file->write(reply->readAll()); } -void HttpWindow::updateDataReadProgress(int bytesRead, int totalBytes) +void HttpWindow::updateDataReadProgress(qint64 bytesRead, qint64 totalBytes) { if (httpRequestAborted) return; @@ -229,14 +229,19 @@ void HttpWindow::enableDownloadButton() downloadButton->setEnabled(!urlLineEdit->text().isEmpty()); } -void HttpWindow::slotAuthenticationRequired(const QString &hostName, quint16, QAuthenticator *authenticator) +void HttpWindow::slotAuthenticationRequired(QNetworkReply*,QAuthenticator *authenticator) { QDialog dlg; Ui::Dialog ui; ui.setupUi(&dlg); dlg.adjustSize(); - ui.siteDescription->setText(tr("%1 at %2").arg(authenticator->realm()).arg(hostName)); - + ui.siteDescription->setText(tr("%1 at %2").arg(authenticator->realm()).arg(url.host())); + + // Did the URL have information? Fill the UI + // This is only relevant if the URL-supplied credentials were wrong + ui.userEdit->setText(url.userName()); + ui.passwordEdit->setText(url.password()); + if (dlg.exec() == QDialog::Accepted) { authenticator->setUser(ui.userEdit->text()); authenticator->setPassword(ui.passwordEdit->text()); @@ -244,7 +249,7 @@ void HttpWindow::slotAuthenticationRequired(const QString &hostName, quint16, QA } #ifndef QT_NO_OPENSSL -void HttpWindow::sslErrors(const QList &errors) +void HttpWindow::sslErrors(QNetworkReply*,const QList &errors) { QString errorString; foreach (const QSslError &error, errors) { @@ -253,10 +258,10 @@ void HttpWindow::sslErrors(const QList &errors) errorString += error.errorString(); } - if (QMessageBox::warning(this, tr("HTTP Example"), + if (QMessageBox::warning(this, tr("HTTP"), tr("One or more SSL errors has occurred: %1").arg(errorString), QMessageBox::Ignore | QMessageBox::Abort) == QMessageBox::Ignore) { - http->ignoreSslErrors(); + reply->ignoreSslErrors(); } } #endif diff --git a/examples/network/http/httpwindow.h b/examples/network/http/httpwindow.h index 9dca8a5..83898af 100644 --- a/examples/network/http/httpwindow.h +++ b/examples/network/http/httpwindow.h @@ -43,18 +43,21 @@ #define HTTPWINDOW_H #include +#include +#include QT_BEGIN_NAMESPACE class QDialogButtonBox; class QFile; -class QHttp; -class QHttpResponseHeader; class QLabel; class QLineEdit; class QProgressDialog; class QPushButton; class QSslError; class QAuthenticator; +class QNetworkReply; + + QT_END_NAMESPACE class HttpWindow : public QDialog @@ -64,16 +67,18 @@ class HttpWindow : public QDialog public: HttpWindow(QWidget *parent = 0); + void startRequest(QUrl url); + private slots: void downloadFile(); void cancelDownload(); - void httpRequestFinished(int requestId, bool error); - void readResponseHeader(const QHttpResponseHeader &responseHeader); - void updateDataReadProgress(int bytesRead, int totalBytes); + void httpFinished(); + void httpReadyRead(); + void updateDataReadProgress(qint64 bytesRead, qint64 totalBytes); void enableDownloadButton(); - void slotAuthenticationRequired(const QString &, quint16, QAuthenticator *); + void slotAuthenticationRequired(QNetworkReply*,QAuthenticator *); #ifndef QT_NO_OPENSSL - void sslErrors(const QList &errors); + void sslErrors(QNetworkReply*,const QList &errors); #endif private: @@ -85,7 +90,9 @@ private: QPushButton *quitButton; QDialogButtonBox *buttonBox; - QHttp *http; + QUrl url; + QNetworkAccessManager qnam; + QNetworkReply *reply; QFile *file; int httpGetId; bool httpRequestAborted; diff --git a/examples/network/http/main.cpp b/examples/network/http/main.cpp index ecbe100..817b2be 100644 --- a/examples/network/http/main.cpp +++ b/examples/network/http/main.cpp @@ -46,7 +46,6 @@ int main(int argc, char *argv[]) { QApplication app(argc, argv); - qWarning("The usage of QHttp is not recommended anymore, please use QNetworkAccessManager."); HttpWindow httpWin; httpWin.show(); return httpWin.exec(); -- cgit v0.12 From 5e95e1bb510d24b9b7889191144a4842fd8569c1 Mon Sep 17 00:00:00 2001 From: Markus Goetz Date: Mon, 22 Feb 2010 12:43:57 +0100 Subject: QNetworkRequest: Doc enhancement Reviewed-by: David Boddie --- src/network/access/qnetworkrequest.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/network/access/qnetworkrequest.cpp b/src/network/access/qnetworkrequest.cpp index a2bef67..c4ff24d 100644 --- a/src/network/access/qnetworkrequest.cpp +++ b/src/network/access/qnetworkrequest.cpp @@ -138,6 +138,8 @@ QT_BEGIN_NAMESPACE default follow redirections: it's up to the application to determine if the requested redirection should be allowed, according to its security policies. + The returned URL might be relative. Use QUrl::resolved() + to create an absolute URL out of it. \value ConnectionEncryptedAttribute Replies only, type: QVariant::Bool (default: false) -- cgit v0.12 From bab18de3932a802568d6d9e0cea9e76f02e6bf5d Mon Sep 17 00:00:00 2001 From: Joerg Bornemann Date: Mon, 22 Feb 2010 12:53:50 +0100 Subject: fix crash on Windows CE on WM_SETTINGCHANGE On Windows CE, lParam parameter is a constant, not a char pointer. The only valid value is INI_INTL. Task-number: QTBUG-7943 Reviewed-by: ninerider --- src/gui/kernel/qapplication_win.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/gui/kernel/qapplication_win.cpp b/src/gui/kernel/qapplication_win.cpp index 0a4869b..aac834d 100644 --- a/src/gui/kernel/qapplication_win.cpp +++ b/src/gui/kernel/qapplication_win.cpp @@ -1905,8 +1905,13 @@ LRESULT CALLBACK QtWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam break; if (!msg.wParam) { +#ifdef Q_WS_WINCE + // On Windows CE, lParam parameter is a constant, not a char pointer. + if (msg.lParam == INI_INTL) { +#else QString area = QString::fromWCharArray((wchar_t*)msg.lParam); if (area == QLatin1String("intl")) { +#endif QLocalePrivate::updateSystemPrivate(); if (!widget->testAttribute(Qt::WA_SetLocale)) widget->dptr()->setLocale_helper(QLocale(), true); -- cgit v0.12 From 93ba9e3bc2bb4879d6b35b98d7d16c19f7c8221f Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Mon, 22 Feb 2010 13:39:40 +0100 Subject: Stylesheet: Fix size specified in QToolbar::handle Regression since f0243e70e05a3368582fd0478d840096d6b60c3f We added a new rule (SE_ToolBarHandle) and the baseStyle was calling pixelMetric(PM_ToolBarHandleExtent) on itself, bypassing the QStyleSheetStyle Reviewed-by: Thierry Task-number: QTBUG-8348 --- src/gui/styles/qstylesheetstyle.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/gui/styles/qstylesheetstyle.cpp b/src/gui/styles/qstylesheetstyle.cpp index b36294a..c550938 100644 --- a/src/gui/styles/qstylesheetstyle.cpp +++ b/src/gui/styles/qstylesheetstyle.cpp @@ -5743,6 +5743,13 @@ QRect QStyleSheetStyle::subElementRect(SubElement se, const QStyleOption *opt, c return positionRect(w, subRule, subRule2, pe, opt->rect, opt->direction); } +#ifndef QT_NO_TOOLBAR + case SE_ToolBarHandle: + if (hasStyleRule(w, PseudoElement_ToolBarHandle)) + return ParentStyle::subElementRect(se, opt, w); + break; +#endif //QT_NO_TOOLBAR + default: break; } -- cgit v0.12 From d9838f300b652fe58c8c5af7097b236d93eb9725 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Nilsen?= Date: Mon, 22 Feb 2010 14:33:19 +0100 Subject: Stabilize QWidget benchmarks. This commit also removes the complexToplevelResize test; it is not suitable for automated testing as the output is too unstable. --- .../benchmarks/gui/kernel/qwidget/tst_qwidget.cpp | 297 ++++++++------------- 1 file changed, 110 insertions(+), 187 deletions(-) diff --git a/tests/benchmarks/gui/kernel/qwidget/tst_qwidget.cpp b/tests/benchmarks/gui/kernel/qwidget/tst_qwidget.cpp index f21bd44..8c30be4 100644 --- a/tests/benchmarks/gui/kernel/qwidget/tst_qwidget.cpp +++ b/tests/benchmarks/gui/kernel/qwidget/tst_qwidget.cpp @@ -42,33 +42,35 @@ #include #include -class tst_QWidget : public QObject +static void processEvents() { - Q_OBJECT - - -private slots: - void update_data(); - void updateOpaque_data(); - void updateOpaque(); - void updateTransparent_data(); - void updateTransparent(); - void updatePartial_data(); - void updatePartial(); - void updateComplex_data(); - void updateComplex(); - - void complexToplevelResize(); -}; + QApplication::flush(); + QApplication::processEvents(); + QApplication::processEvents(); +} class UpdateWidget : public QWidget { public: - UpdateWidget(int rows, int columns) : QWidget(0) + UpdateWidget(int rows, int columns) + : QWidget(0), rowCount(0), columnCount(0), opaqueChildren(false) { + fill(rows, columns); + } + + UpdateWidget(QWidget *parent = 0) + : QWidget(parent), rowCount(0), columnCount(0), opaqueChildren(false) {} + + void fill(int rows, int columns) + { + if (rows == rowCount && columns == columnCount) + return; + delete layout(); QGridLayout *layout = new QGridLayout; - for (int row = 0; row < rows; ++row) { - for (int column = 0; column < columns; ++column) { + rowCount = rows; + columnCount = columns; + for (int row = 0; row < rowCount; ++row) { + for (int column = 0; column < columnCount; ++column) { UpdateWidget *widget = new UpdateWidget; widget->setFixedSize(20, 20); layout->addWidget(widget, row, column); @@ -76,9 +78,20 @@ public: } } setLayout(layout); + adjustSize(); + QTest::qWait(250); + processEvents(); } - UpdateWidget(QWidget *parent = 0) : QWidget(parent) {} + void setOpaqueChildren(bool enable) + { + if (opaqueChildren != enable) { + foreach (QWidget *w, children) + w->setAttribute(Qt::WA_OpaquePaintEvent, enable); + opaqueChildren = enable; + processEvents(); + } + } void paintEvent(QPaintEvent *) { @@ -93,75 +106,86 @@ public: QRegion updateRegion; QList children; + int rowCount; + int columnCount; + bool opaqueChildren; }; -void tst_QWidget::update_data() +class tst_QWidget : public QObject { - QTest::addColumn("rows"); - QTest::addColumn("columns"); - QTest::addColumn("numUpdates"); - - QTest::newRow("10x10x1") << 10 << 10 << 1; - QTest::newRow("10x10x10") << 10 << 10 << 10; - QTest::newRow("25x25x1") << 25 << 25 << 1; - QTest::newRow("25x25x10") << 25 << 25 << 10; - QTest::newRow("25x25x100") << 25 << 25 << 100; -} + Q_OBJECT -void tst_QWidget::updateOpaque_data() -{ - update_data(); -} +public slots: + void initTestCase(); + void init(); -void tst_QWidget::updateOpaque() -{ - QFETCH(int, rows); - QFETCH(int, columns); - QFETCH(int, numUpdates); +private slots: + void update_data(); + void update(); + void updatePartial_data(); + void updatePartial(); + void updateComplex_data(); + void updateComplex(); - UpdateWidget widget(rows, columns); - foreach (QWidget *w, widget.children) { - w->setAttribute(Qt::WA_OpaquePaintEvent); - } +private: + UpdateWidget widget; +}; +void tst_QWidget::initTestCase() +{ widget.show(); - QApplication::processEvents(); + QTest::qWaitForWindowShown(&widget); + QTest::qWait(300); + processEvents(); +} - int i = 0; - const int n = widget.children.size(); - QBENCHMARK { - for (int j = 0; j < numUpdates; ++j) { - widget.children[i]->update(); - QApplication::processEvents(); - i = (i + 1) % n; - } - } +void tst_QWidget::init() +{ + QVERIFY(widget.isVisible()); + for (int i = 0; i < 3; ++i) + processEvents(); } -void tst_QWidget::updateTransparent_data() +void tst_QWidget::update_data() { - update_data(); + QTest::addColumn("rows"); + QTest::addColumn("columns"); + QTest::addColumn("numUpdates"); + QTest::addColumn("opaque"); + + QTest::newRow("10x10x1 transparent") << 10 << 10 << 1 << false; + QTest::newRow("10x10x10 transparent") << 10 << 10 << 10 << false; + QTest::newRow("10x10x100 transparent") << 10 << 10 << 100 << false; + QTest::newRow("10x10x1 opaque") << 10 << 10 << 1 << true; + QTest::newRow("10x10x10 opaque") << 10 << 10 << 10 << true; + QTest::newRow("10x10x100 opaque") << 10 << 10 << 100 << true; + QTest::newRow("25x25x1 transparent ") << 25 << 25 << 1 << false; + QTest::newRow("25x25x10 transparent") << 25 << 25 << 10 << false; + QTest::newRow("25x25x100 transparent") << 25 << 25 << 100 << false; + QTest::newRow("25x25x1 opaque") << 25 << 25 << 1 << true; + QTest::newRow("25x25x10 opaque") << 25 << 25 << 10 << true; + QTest::newRow("25x25x100 opaque") << 25 << 25 << 100 << true; } -void tst_QWidget::updateTransparent() +void tst_QWidget::update() { QFETCH(int, rows); QFETCH(int, columns); QFETCH(int, numUpdates); + QFETCH(bool, opaque); - UpdateWidget widget(rows, columns); - widget.show(); - QApplication::processEvents(); + widget.fill(rows, columns); + widget.setOpaqueChildren(opaque); - int i = 0; - const int n = widget.children.size(); QBENCHMARK { - for (int j = 0; j < numUpdates; ++j) { - widget.children[i]->update(); + for (int i = 0; i < widget.children.size(); ++i) { + for (int j = 0; j < numUpdates; ++j) + widget.children.at(i)->update(); QApplication::processEvents(); - i = (i + 1) % n; } } + + QApplication::flush(); } void tst_QWidget::updatePartial_data() @@ -174,24 +198,23 @@ void tst_QWidget::updatePartial() QFETCH(int, rows); QFETCH(int, columns); QFETCH(int, numUpdates); + QFETCH(bool, opaque); - UpdateWidget widget(rows, columns); - widget.show(); - QApplication::processEvents(); + widget.fill(rows, columns); + widget.setOpaqueChildren(opaque); - int i = 0; - const int n = widget.children.size(); QBENCHMARK { - for (int j = 0; j < numUpdates; ++j) { + for (int i = 0; i < widget.children.size(); ++i) { QWidget *w = widget.children[i]; const int x = w->width() / 2; const int y = w->height() / 2; - w->update(0, 0, x, y); - w->update(x, 0, x, y); - w->update(0, y, x, y); - w->update(x, y, x, y); + for (int j = 0; j < numUpdates; ++j) { + w->update(0, 0, x, y); + w->update(x, 0, x, y); + w->update(0, y, x, y); + w->update(x, y, x, y); + } QApplication::processEvents(); - i = (i + 1) % n; } } } @@ -206,127 +229,27 @@ void tst_QWidget::updateComplex() QFETCH(int, rows); QFETCH(int, columns); QFETCH(int, numUpdates); + QFETCH(bool, opaque); - UpdateWidget widget(rows, columns); - widget.show(); - QApplication::processEvents(); + widget.fill(rows, columns); + widget.setOpaqueChildren(opaque); - int i = 0; - const int n = widget.children.size(); QBENCHMARK { - for (int j = 0; j < numUpdates; ++j) { + for (int i = 0; i < widget.children.size(); ++i) { QWidget *w = widget.children[i]; const int x = w->width() / 2; const int y = w->height() / 2; - w->update(QRegion(0, 0, x, y, QRegion::Ellipse)); - w->update(QRegion(x, y, x, y, QRegion::Ellipse)); + QRegion r1(0, 0, x, y, QRegion::Ellipse); + QRegion r2(x, y, x, y, QRegion::Ellipse); + for (int j = 0; j < numUpdates; ++j) { + w->update(r1); + w->update(r2); + } QApplication::processEvents(); - i = (i + 1) % n; } } } -class ResizeWidget : public QWidget -{ -public: - ResizeWidget(); -}; - -ResizeWidget::ResizeWidget() : QWidget(0) -{ - QBoxLayout *topLayout = new QVBoxLayout; - - QMenuBar *menubar = new QMenuBar; - QMenu* popup = menubar->addMenu("&File"); - popup->addAction("&Quit", qApp, SLOT(quit())); - topLayout->setMenuBar(menubar); - - QBoxLayout *buttons = new QHBoxLayout; - buttons->setMargin(5); - buttons->addStretch(10); - for (int i = 1; i <= 4; i++ ) { - QPushButton* button = new QPushButton; - button->setText(QString("Button %1").arg(i)); - buttons->addWidget(button); - } - topLayout->addLayout(buttons); - - buttons = new QHBoxLayout; - buttons->addStretch(10); - for (int i = 11; i <= 16; i++) { - QPushButton* button = new QPushButton; - button->setText(QString("Button %1").arg(i)); - buttons->addWidget(button); - } - topLayout->addLayout(buttons); - - QBoxLayout *buttons2 = new QHBoxLayout; - buttons2->addStretch(10); - topLayout->addLayout(buttons2); - - QPushButton *button = new QPushButton; - button->setText("Button five"); - buttons2->addWidget(button); - - button = new QPushButton; - button->setText("Button 6"); - buttons2->addWidget(button); - - QTextEdit *bigWidget = new QTextEdit; - bigWidget->setText("This widget will get all the remaining space"); - bigWidget->setFrameStyle(QFrame::Panel | QFrame::Plain); - topLayout->addWidget(bigWidget); - - const int numRows = 6; - const int labelCol = 0; - const int linedCol = 1; - const int multiCol = 2; - - QGridLayout *grid = new QGridLayout; - for (int row = 0; row < numRows; row++) { - QLineEdit *lineEdit = new QLineEdit; - grid->addWidget(lineEdit, row, linedCol); - QLabel *label = new QLabel(QString("Line &%1").arg(row + 1)); - grid->addWidget(label, row, labelCol); - } - topLayout->addLayout(grid); - - QTextEdit *multiLineEdit = new QTextEdit; - grid->addWidget(multiLineEdit, 0, labelCol + 1, multiCol, multiCol); - - grid->setColumnStretch(linedCol, 10); - grid->setColumnStretch(multiCol, 20); - - QLabel* statusBar = new QLabel; - statusBar->setText("Let's pretend this is a status bar"); - statusBar->setFrameStyle(QFrame::Panel | QFrame::Sunken); - statusBar->setFixedHeight(statusBar->sizeHint().height()); - statusBar->setAlignment(Qt::AlignVCenter | Qt::AlignLeft); - topLayout->addWidget(statusBar); - - topLayout->activate(); - setLayout(topLayout); -} - -void tst_QWidget::complexToplevelResize() -{ - ResizeWidget w; - w.show(); - - QApplication::processEvents(); - - const int minSize = 100; - const int maxSize = 800; - int size = minSize; - - QBENCHMARK { - w.resize(size, size); - size = qMax(minSize, (size + 10) % maxSize); - QApplication::processEvents(); - QApplication::processEvents(); - } -} - QTEST_MAIN(tst_QWidget) #include "tst_qwidget.moc" -- cgit v0.12 From 976a2b6ad1f95175d8d0be2d1eb7603cf4e4026a Mon Sep 17 00:00:00 2001 From: Carlos Manuel Duclos Vergara Date: Mon, 22 Feb 2010 14:58:41 +0100 Subject: QFontDialog::exec() never returns on OSX The problem is the fact that this dialog is never meant to be used this way. Instead it should be called through the static function ::getFont(...). I reimplemented this code path and made sure that this works. Task-number: QTBUG-7769 Reviewed-by: Richard Moe Gustavsen --- src/gui/dialogs/qfontdialog.cpp | 58 ++++++++------- src/gui/dialogs/qfontdialog.h | 3 + src/gui/dialogs/qfontdialog_mac.mm | 148 ++++++++++++++++++++++++++++++++++++- src/gui/dialogs/qfontdialog_p.h | 6 ++ 4 files changed, 188 insertions(+), 27 deletions(-) diff --git a/src/gui/dialogs/qfontdialog.cpp b/src/gui/dialogs/qfontdialog.cpp index 56580a9..4358313 100644 --- a/src/gui/dialogs/qfontdialog.cpp +++ b/src/gui/dialogs/qfontdialog.cpp @@ -989,33 +989,23 @@ void QFontDialog::open(QObject *receiver, const char *member) void QFontDialog::setVisible(bool visible) { Q_D(QFontDialog); - if (visible) - d->selectedFont = QFont(); - -#if defined(Q_WS_MAC) - bool isCurrentlyVisible = (isVisible() || d->delegate); - - if (!visible == !isCurrentlyVisible) - return; - if (visible) { - if (!(d->opts & DontUseNativeDialog) && QFontDialogPrivate::sharedFontPanelAvailable) { - d->delegate = QFontDialogPrivate::openCocoaFontPanel( - currentFont(), parentWidget(), windowTitle(), options(), d); - QFontDialogPrivate::sharedFontPanelAvailable = false; + if (testAttribute(Qt::WA_WState_ExplicitShowHide) && !testAttribute(Qt::WA_WState_Hidden)) return; - } + } else if (testAttribute(Qt::WA_WState_ExplicitShowHide) && testAttribute(Qt::WA_WState_Hidden)) + return; - setWindowFlags(windowModality() == Qt::WindowModal ? Qt::Sheet : DefaultWindowFlags); - } else { - if (d->delegate) { - QFontDialogPrivate::closeCocoaFontPanel(d->delegate); - d->delegate = 0; - QFontDialogPrivate::sharedFontPanelAvailable = true; - return; + if (d->canBeNativeDialog()){ + if (d->setVisible_sys(visible)){ + d->nativeDialogInUse = true; + // Set WA_DontShowOnScreen so that QDialog::setVisible(visible) below + // updates the state correctly, but skips showing the non-native version: + setAttribute(Qt::WA_DontShowOnScreen, true); + } else { + d->nativeDialogInUse = false; + setAttribute(Qt::WA_DontShowOnScreen, false); } } -#endif QDialog::setVisible(visible); } @@ -1032,11 +1022,14 @@ void QFontDialog::done(int result) Q_D(QFontDialog); QDialog::done(result); if (result == Accepted) { - d->selectedFont = currentFont(); + // We check if this is the same font we had before, if so we emit currentFontChanged + QFont selectedFont = currentFont(); + if(selectedFont != d->selectedFont) + emit(currentFontChanged(selectedFont)); + d->selectedFont = selectedFont; emit fontSelected(d->selectedFont); - } else { + } else d->selectedFont = QFont(); - } if (d->receiverToDisconnectOnClose) { disconnect(this, SIGNAL(fontSelected(QFont)), d->receiverToDisconnectOnClose, d->memberToDisconnectOnClose); @@ -1045,6 +1038,21 @@ void QFontDialog::done(int result) d->memberToDisconnectOnClose.clear(); } +bool QFontDialogPrivate::canBeNativeDialog() +{ + Q_Q(QFontDialog); + if (nativeDialogInUse) + return true; + if (q->testAttribute(Qt::WA_DontShowOnScreen)) + return false; + if (opts & QFontDialog::DontUseNativeDialog) + return false; + + QLatin1String staticName(QFontDialog::staticMetaObject.className()); + QLatin1String dynamicName(q->metaObject()->className()); + return (staticName == dynamicName); +} + /*! \fn QFont QFontDialog::getFont(bool *ok, const QFont &initial, QWidget* parent, const char* name) \since 4.5 diff --git a/src/gui/dialogs/qfontdialog.h b/src/gui/dialogs/qfontdialog.h index e6f209e..6035a3a 100644 --- a/src/gui/dialogs/qfontdialog.h +++ b/src/gui/dialogs/qfontdialog.h @@ -131,6 +131,9 @@ private: Q_PRIVATE_SLOT(d_func(), void _q_styleHighlighted(int)) Q_PRIVATE_SLOT(d_func(), void _q_sizeHighlighted(int)) Q_PRIVATE_SLOT(d_func(), void _q_updateSample()) +#if defined(Q_WS_MAC) + Q_PRIVATE_SLOT(d_func(), void _q_macRunNativeAppModalPanel()) +#endif }; Q_DECLARE_OPERATORS_FOR_FLAGS(QFontDialog::FontDialogOptions) diff --git a/src/gui/dialogs/qfontdialog_mac.mm b/src/gui/dialogs/qfontdialog_mac.mm index 68f5f00..67d32b8 100644 --- a/src/gui/dialogs/qfontdialog_mac.mm +++ b/src/gui/dialogs/qfontdialog_mac.mm @@ -49,6 +49,7 @@ #include #include #include +#include #include #import #import @@ -372,7 +373,12 @@ static QFont qfontForCocoaFont(NSFont *cocoaFont, const QFont &resolveFont) [NSApp endModalSession:mModalSession]; mModalSession = 0; } - + // Hack alert! + // Since this code path was never intended to be followed when starting from exec + // we need to force the dialog to communicate the new font, otherwise the signal + // won't get emitted. + if(code == NSOKButton) + mPriv->sampleEdit->setFont([self qtFont]); mPriv->done((code == NSOKButton) ? QDialog::Accepted : QDialog::Rejected); } else { [NSApp stopModalWithCode:code]; @@ -567,7 +573,6 @@ void *QFontDialogPrivate::openCocoaFontPanel(const QFont &initial, [ourPanel makeKeyAndOrderFront:ourPanel]; } } - return delegate; } @@ -640,6 +645,145 @@ void QFontDialogPrivate::setFont(void *delegate, const QFont &font) [static_cast(delegate) setQtFont:font]; } +void *QFontDialogPrivate::_q_constructNativePanel() +{ + QMacCocoaAutoReleasePool pool; + + bool sharedFontPanelExisted = [NSFontPanel sharedFontPanelExists]; + NSFontPanel *sharedFontPanel = [NSFontPanel sharedFontPanel]; + [sharedFontPanel setHidesOnDeactivate:false]; + + // hack to ensure that QCocoaApplication's validModesForFontPanel: + // implementation is honored + if (!sharedFontPanelExisted) { + [sharedFontPanel makeKeyAndOrderFront:sharedFontPanel]; + [sharedFontPanel close]; + } + + NSPanel *ourPanel = 0; + NSView *stolenContentView = 0; + NSButton *okButton = 0; + NSButton *cancelButton = 0; + + CGFloat dialogExtraWidth = 0.0; + CGFloat dialogExtraHeight = 0.0; + + // compute dialogExtra{Width,Height} + dialogExtraWidth = 2.0 * DialogSideMargin; + dialogExtraHeight = DialogTopMargin + ButtonTopMargin + ButtonMinHeight + + ButtonBottomMargin; + + // compute initial contents rectangle + NSRect contentRect = [sharedFontPanel contentRectForFrameRect:[sharedFontPanel frame]]; + contentRect.size.width += dialogExtraWidth; + contentRect.size.height += dialogExtraHeight; + + // create the new panel + ourPanel = [[NSPanel alloc] initWithContentRect:contentRect + styleMask:StyleMask + backing:NSBackingStoreBuffered + defer:YES]; + [ourPanel setReleasedWhenClosed:YES]; + + stolenContentView = [sharedFontPanel contentView]; + + // steal the font panel's contents view + [stolenContentView retain]; + [sharedFontPanel setContentView:0]; + + { + // create a new content view and add the stolen one as a subview + NSRect frameRect = { { 0.0, 0.0 }, { 0.0, 0.0 } }; + NSView *ourContentView = [[NSView alloc] initWithFrame:frameRect]; + [ourContentView addSubview:stolenContentView]; + + // create OK and Cancel buttons and add these as subviews + okButton = macCreateButton("&OK", ourContentView); + cancelButton = macCreateButton("Cancel", ourContentView); + + [ourPanel setContentView:ourContentView]; + [ourPanel setDefaultButtonCell:[okButton cell]]; + } + // create a delegate and set it + QCocoaFontPanelDelegate *delegate = + [[QCocoaFontPanelDelegate alloc] initWithFontPanel:sharedFontPanel + stolenContentView:stolenContentView + okButton:okButton + cancelButton:cancelButton + priv:this + extraWidth:dialogExtraWidth + extraHeight:dialogExtraHeight]; + [ourPanel setDelegate:delegate]; + [[NSFontManager sharedFontManager] setDelegate:delegate]; +#ifdef QT_MAC_USE_COCOA + [[NSFontManager sharedFontManager] setTarget:delegate]; +#endif + setFont(delegate, QApplication::font()); + + { + // hack to get correct initial layout + NSRect frameRect = [ourPanel frame]; + frameRect.size.width += 1.0; + [ourPanel setFrame:frameRect display:NO]; + frameRect.size.width -= 1.0; + frameRect.size = [delegate windowWillResize:ourPanel toSize:frameRect.size]; + [ourPanel setFrame:frameRect display:NO]; + [ourPanel center]; + } + NSString *title = @"Select font"; + [ourPanel setTitle:title]; + + [delegate setModalSession:[NSApp beginModalSessionForWindow:ourPanel]]; + return delegate; +} + +void QFontDialogPrivate::mac_nativeDialogModalHelp() +{ + // Copied from QFileDialogPrivate + // Do a queued meta-call to open the native modal dialog so it opens after the new + // event loop has started to execute (in QDialog::exec). Using a timer rather than + // a queued meta call is intentional to ensure that the call is only delivered when + // [NSApp run] runs (timers are handeled special in cocoa). If NSApp is not + // running (which is the case if e.g a top-most QEventLoop has been + // interrupted, and the second-most event loop has not yet been reactivated (regardless + // if [NSApp run] is still on the stack)), showing a native modal dialog will fail. + if (nativeDialogInUse) { + Q_Q(QFontDialog); + QTimer::singleShot(1, q, SLOT(_q_macRunNativeAppModalPanel())); + } +} + +// The problem with the native font dialog is that OS X does not +// offer a proper dialog, but a panel (i.e. without Ok and Cancel buttons). +// This means we need to "construct" a native dialog by taking the panel +// and "adding" the buttons. +void QFontDialogPrivate::_q_macRunNativeAppModalPanel() +{ + QBoolBlocker nativeDialogOnTop(QApplicationPrivate::native_modal_dialog_active); + Q_Q(QFontDialog); + QCocoaFontPanelDelegate *delegate = (QCocoaFontPanelDelegate *)_q_constructNativePanel(); + NSWindow *ourPanel = [delegate actualPanel]; + [ourPanel retain]; + int rval = [NSApp runModalForWindow:ourPanel]; + QAbstractEventDispatcher::instance()->interrupt(); + [ourPanel release]; + [delegate cleanUpAfterMyself]; + [delegate release]; + bool isOk = (rval == NSOKButton); + if(isOk) + rescode = QDialog::Accepted; + else + rescode = QDialog::Rejected; +} + +bool QFontDialogPrivate::setVisible_sys(bool visible) +{ + Q_Q(QFontDialog); + if (!visible == q->isHidden()) + return false; + return visible; +} + QT_END_NAMESPACE #endif diff --git a/src/gui/dialogs/qfontdialog_p.h b/src/gui/dialogs/qfontdialog_p.h index ca2b10b..7654a80 100644 --- a/src/gui/dialogs/qfontdialog_p.h +++ b/src/gui/dialogs/qfontdialog_p.h @@ -152,6 +152,12 @@ public: inline QFontDialog *fontDialog() { return q_func(); } void *delegate; + bool nativeDialogInUse; + bool canBeNativeDialog(); + bool setVisible_sys(bool visible); + void *_q_constructNativePanel(); + void _q_macRunNativeAppModalPanel(); + void mac_nativeDialogModalHelp(); static bool sharedFontPanelAvailable; #endif -- cgit v0.12 From 0094e35f2303f5cf43d8fb97330efce916250bf9 Mon Sep 17 00:00:00 2001 From: Markus Goetz Date: Mon, 22 Feb 2010 13:40:17 +0100 Subject: QAbstractSocket: Clarify documentation Reviewed-by: Thiago --- src/network/socket/qabstractsocket.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/network/socket/qabstractsocket.cpp b/src/network/socket/qabstractsocket.cpp index 829df89..275c436 100644 --- a/src/network/socket/qabstractsocket.cpp +++ b/src/network/socket/qabstractsocket.cpp @@ -155,6 +155,9 @@ See the \l network/fortuneclient and \l network/blockingfortuneclient examples for an overview of both approaches. + \note We discourage the use of the blocking functions together + with signals. One of the two possibilities should be used. + QAbstractSocket can be used with QTextStream and QDataStream's stream operators (operator<<() and operator>>()). There is one issue to be aware of, though: You must make sure that enough data @@ -1682,9 +1685,12 @@ static int qt_timeout_value(int msecs, int elapsed) If msecs is -1, this function will not time out. - Note: This function may wait slightly longer than \a msecs, + \note This function may wait slightly longer than \a msecs, depending on the time it takes to complete the host lookup. + \note Multiple calls to this functions do not accumulate the time. + If the function times out, the connecting process will be aborted. + \sa connectToHost(), connected() */ bool QAbstractSocket::waitForConnected(int msecs) @@ -1722,7 +1728,7 @@ bool QAbstractSocket::waitForConnected(int msecs) d->_q_startConnecting(QHostInfo::fromName(d->hostName)); } if (state() == UnconnectedState) - return false; + return false; // connect not im progress anymore! bool timedOut = true; #if defined (QABSTRACTSOCKET_DEBUG) -- cgit v0.12 From 7a328e4f69f10f4fea6d48746ff214030794328d Mon Sep 17 00:00:00 2001 From: Carlos Manuel Duclos Vergara Date: Mon, 22 Feb 2010 16:19:44 +0100 Subject: Build fix for 976a2b6ad1f95175d8d0be2d1eb7603cf4e4026a. Forgot to add some #ifdef's. Reviewed-by: Richard Moe Gustavsen --- src/gui/dialogs/qfontdialog.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/gui/dialogs/qfontdialog.cpp b/src/gui/dialogs/qfontdialog.cpp index 4358313..a4bf15d 100644 --- a/src/gui/dialogs/qfontdialog.cpp +++ b/src/gui/dialogs/qfontdialog.cpp @@ -994,7 +994,7 @@ void QFontDialog::setVisible(bool visible) return; } else if (testAttribute(Qt::WA_WState_ExplicitShowHide) && testAttribute(Qt::WA_WState_Hidden)) return; - +#ifdef Q_WS_MAC if (d->canBeNativeDialog()){ if (d->setVisible_sys(visible)){ d->nativeDialogInUse = true; @@ -1006,7 +1006,7 @@ void QFontDialog::setVisible(bool visible) setAttribute(Qt::WA_DontShowOnScreen, false); } } - +#endif // Q_WS_MAC QDialog::setVisible(visible); } @@ -1038,6 +1038,7 @@ void QFontDialog::done(int result) d->memberToDisconnectOnClose.clear(); } +#ifdef Q_WS_MAC bool QFontDialogPrivate::canBeNativeDialog() { Q_Q(QFontDialog); @@ -1052,6 +1053,7 @@ bool QFontDialogPrivate::canBeNativeDialog() QLatin1String dynamicName(q->metaObject()->className()); return (staticName == dynamicName); } +#endif // Q_WS_MAC /*! \fn QFont QFontDialog::getFont(bool *ok, const QFont &initial, QWidget* parent, const char* name) -- cgit v0.12 From bab4c3056c11ba3607acce3314ecfe172d00cf96 Mon Sep 17 00:00:00 2001 From: Kent Hansen Date: Mon, 22 Feb 2010 17:59:59 +0100 Subject: Fix memory leak when lazily binding QScriptValue to an engine Avoid the engine's list of free script values from growing without bounds. When a QScriptValue is initially not bound, its private will be allocated from the normal heap (and not from the engine's pool of privates, because there is no engine at this point). But when a value is later bound (e.g. by setting it as a property of an object, or by passing it as argument to QScriptValue::call()) and is subsequently destroyed, its private will be handed to the engine, which will add it to its free-list (hence the memory is not freed). This allocation/deallocation asymmetry causes this list go keep growing. The solution is to limit the size of the free-list, and free the memory of the private immediately when the list has reached a certain size. Task-number: QTBUG-8400 Reviewed-by: Olivier Goffart --- src/script/api/qscriptengine.cpp | 2 +- src/script/api/qscriptengine_p.h | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/script/api/qscriptengine.cpp b/src/script/api/qscriptengine.cpp index 1bd7377..1199263 100644 --- a/src/script/api/qscriptengine.cpp +++ b/src/script/api/qscriptengine.cpp @@ -768,7 +768,7 @@ static QScriptValue __setupPackage__(QScriptContext *ctx, QScriptEngine *eng) } // namespace QScript QScriptEnginePrivate::QScriptEnginePrivate() - : registeredScriptValues(0), freeScriptValues(0), + : registeredScriptValues(0), freeScriptValues(0), freeScriptValuesCount(0), registeredScriptStrings(0), inEval(false) { qMetaTypeId(); diff --git a/src/script/api/qscriptengine_p.h b/src/script/api/qscriptengine_p.h index 6780b2c..401d6d2 100644 --- a/src/script/api/qscriptengine_p.h +++ b/src/script/api/qscriptengine_p.h @@ -255,6 +255,8 @@ public: int agentLineNumber; QScriptValuePrivate *registeredScriptValues; QScriptValuePrivate *freeScriptValues; + static const int maxFreeScriptValues = 256; + int freeScriptValuesCount; QScriptStringPrivate *registeredScriptStrings; QHash m_typeInfos; int processEventsInterval; @@ -377,6 +379,7 @@ inline QScriptValuePrivate *QScriptEnginePrivate::allocateScriptValuePrivate(siz if (freeScriptValues) { QScriptValuePrivate *p = freeScriptValues; freeScriptValues = p->next; + --freeScriptValuesCount; return p; } return reinterpret_cast(qMalloc(size)); @@ -384,8 +387,13 @@ inline QScriptValuePrivate *QScriptEnginePrivate::allocateScriptValuePrivate(siz inline void QScriptEnginePrivate::freeScriptValuePrivate(QScriptValuePrivate *p) { - p->next = freeScriptValues; - freeScriptValues = p; + if (freeScriptValuesCount < maxFreeScriptValues) { + p->next = freeScriptValues; + freeScriptValues = p; + ++freeScriptValuesCount; + } else { + qFree(p); + } } inline void QScriptEnginePrivate::registerScriptValue(QScriptValuePrivate *value) -- cgit v0.12 From 8597e03495f54614e53c6063f1f13077a08109fd Mon Sep 17 00:00:00 2001 From: Rhys Weatherley Date: Tue, 23 Feb 2010 08:46:27 +1000 Subject: Improve performance of VGPath creation by reusing the same path The vgClearPath() function can be used to clear a path for reuse more efficiently than destroying the path and creating a new one. Task-number: QT-2974 Reviewed-by: Daniel Pope --- src/openvg/qpaintengine_vg.cpp | 124 ++++++++++++++++++++++------------------- 1 file changed, 67 insertions(+), 57 deletions(-) diff --git a/src/openvg/qpaintengine_vg.cpp b/src/openvg/qpaintengine_vg.cpp index da47f06..4192dbb 100644 --- a/src/openvg/qpaintengine_vg.cpp +++ b/src/openvg/qpaintengine_vg.cpp @@ -131,8 +131,9 @@ public: void draw(VGPath path, const QPen& pen, const QBrush& brush, VGint rule = VG_EVEN_ODD); void stroke(VGPath path, const QPen& pen); void fill(VGPath path, const QBrush& brush, VGint rule = VG_EVEN_ODD); - VGPath vectorPathToVGPath(const QVectorPath& path); - VGPath painterPathToVGPath(const QPainterPath& path); + inline void releasePath(VGPath path); + VGPath vectorPathToVGPath(const QVectorPath& path, bool forceNewPath = false); + VGPath painterPathToVGPath(const QPainterPath& path, bool forceNewPath = false); VGPath roundedRectPath(const QRectF &rect, qreal xRadius, qreal yRadius, Qt::SizeMode mode); VGPaintType setBrush (VGPaint paint, const QBrush& brush, VGMatrixMode mode, @@ -178,6 +179,8 @@ public: VGPath roundRectPath; // Cached path for quick drawing of rounded rects. #endif + VGPath reusablePath; // Reusable path for vectorPathToVGPath(), etc. + QTransform transform; // Currently active transform. bool simpleTransform; // True if the transform is simple (non-projective). qreal penScale; // Pen scaling factor from "transform". @@ -350,6 +353,8 @@ void QVGPaintEnginePrivate::init() roundRectPath = 0; #endif + reusablePath = 0; + simpleTransform = true; pathTransformSet = false; penScale = 1.0; @@ -446,6 +451,15 @@ void QVGPaintEnginePrivate::initObjects() VG_PATH_CAPABILITY_ALL); vgAppendPathData(linePath, 2, segments, coords); #endif + + // This path can be reused over and over by calling vgClearPath(). + reusablePath = vgCreatePath(VG_PATH_FORMAT_STANDARD, + VG_PATH_DATATYPE_F, + 1.0f, // scale + 0.0f, // bias + 32 + 1, // segmentCapacityHint + 32 * 2, // coordCapacityHint + VG_PATH_CAPABILITY_ALL); } void QVGPaintEnginePrivate::destroy() @@ -465,6 +479,8 @@ void QVGPaintEnginePrivate::destroy() if (roundRectPath) vgDestroyPath(roundRectPath); #endif + if (reusablePath) + vgDestroyPath(reusablePath); #if !defined(QVG_NO_DRAW_GLYPHS) QVGFontCache::Iterator it; @@ -541,19 +557,32 @@ void QVGPaintEnginePrivate::updateTransform(QPaintDevice *pdev) qt_scaleForTransform(transform, &penScale); } -VGPath QVGPaintEnginePrivate::vectorPathToVGPath(const QVectorPath& path) +inline void QVGPaintEnginePrivate::releasePath(VGPath path) +{ + if (path == reusablePath) + vgClearPath(path, VG_PATH_CAPABILITY_ALL); + else + vgDestroyPath(path); +} + +VGPath QVGPaintEnginePrivate::vectorPathToVGPath(const QVectorPath& path, bool forceNewPath) { int count = path.elementCount(); const qreal *points = path.points(); const QPainterPath::ElementType *elements = path.elements(); - VGPath vgpath = vgCreatePath(VG_PATH_FORMAT_STANDARD, - VG_PATH_DATATYPE_F, - 1.0f, // scale - 0.0f, // bias - count + 1, // segmentCapacityHint - count * 2, // coordCapacityHint - VG_PATH_CAPABILITY_ALL); + VGPath vgpath; + if (forceNewPath) { + vgpath = vgCreatePath(VG_PATH_FORMAT_STANDARD, + VG_PATH_DATATYPE_F, + 1.0f, // scale + 0.0f, // bias + count + 1, // segmentCapacityHint + count * 2, // coordCapacityHint + VG_PATH_CAPABILITY_ALL); + } else { + vgpath = reusablePath; + } // Size is sufficient segments for drawRoundedRect() paths. QVarLengthArray segments; @@ -725,17 +754,22 @@ VGPath QVGPaintEnginePrivate::vectorPathToVGPath(const QVectorPath& path) return vgpath; } -VGPath QVGPaintEnginePrivate::painterPathToVGPath(const QPainterPath& path) +VGPath QVGPaintEnginePrivate::painterPathToVGPath(const QPainterPath& path, bool forceNewPath) { int count = path.elementCount(); - VGPath vgpath = vgCreatePath(VG_PATH_FORMAT_STANDARD, - VG_PATH_DATATYPE_F, - 1.0f, // scale - 0.0f, // bias - count + 1, // segmentCapacityHint - count * 2, // coordCapacityHint - VG_PATH_CAPABILITY_ALL); + VGPath vgpath; + if (forceNewPath) { + vgpath = vgCreatePath(VG_PATH_FORMAT_STANDARD, + VG_PATH_DATATYPE_F, + 1.0f, // scale + 0.0f, // bias + count + 1, // segmentCapacityHint + count * 2, // coordCapacityHint + VG_PATH_CAPABILITY_ALL); + } else { + vgpath = reusablePath; + } if (count == 0) return vgpath; @@ -954,13 +988,7 @@ VGPath QVGPaintEnginePrivate::roundedRectPath(const QRectF &rect, qreal xRadius, vgModifyPathCoords(vgpath, 0, 9, pts); } #else - VGPath vgpath = vgCreatePath(VG_PATH_FORMAT_STANDARD, - VG_PATH_DATATYPE_F, - 1.0f, // scale - 0.0f, // bias - 10, // segmentCapacityHint - 17 * 2, // coordCapacityHint - VG_PATH_CAPABILITY_ALL); + VGPath vgpath = reusablePath; vgAppendPathData(vgpath, 10, roundedrect_types, pts); #endif @@ -1516,7 +1544,7 @@ void QVGPaintEngine::draw(const QVectorPath &path) d->draw(vgpath, s->pen, s->brush, VG_EVEN_ODD); else d->draw(vgpath, s->pen, s->brush, VG_NON_ZERO); - vgDestroyPath(vgpath); + d->releasePath(vgpath); } void QVGPaintEngine::fill(const QVectorPath &path, const QBrush &brush) @@ -1527,7 +1555,7 @@ void QVGPaintEngine::fill(const QVectorPath &path, const QBrush &brush) d->fill(vgpath, brush, VG_EVEN_ODD); else d->fill(vgpath, brush, VG_NON_ZERO); - vgDestroyPath(vgpath); + d->releasePath(vgpath); } void QVGPaintEngine::stroke(const QVectorPath &path, const QPen &pen) @@ -1535,7 +1563,7 @@ void QVGPaintEngine::stroke(const QVectorPath &path, const QPen &pen) Q_D(QVGPaintEngine); VGPath vgpath = d->vectorPathToVGPath(path); d->stroke(vgpath, pen); - vgDestroyPath(vgpath); + d->releasePath(vgpath); } // Determine if a co-ordinate transform is simple enough to allow @@ -1731,7 +1759,7 @@ void QVGPaintEngine::clip(const QVectorPath &path, Qt::ClipOperation op) default: break; } - vgDestroyPath(vgpath); + d->releasePath(vgpath); vgSeti(VG_MASKING, VG_TRUE); d->maskValid = true; @@ -2048,7 +2076,7 @@ void QVGPaintEngine::clip(const QPainterPath &path, Qt::ClipOperation op) default: break; } - vgDestroyPath(vgpath); + d->releasePath(vgpath); vgSeti(VG_MASKING, VG_TRUE); d->maskValid = true; @@ -2487,7 +2515,7 @@ void QVGPaintEngine::drawRoundedRect(const QRectF &rect, qreal xrad, qreal yrad, VGPath vgpath = d->roundedRectPath(rect, xrad, yrad, mode); d->draw(vgpath, s->pen, s->brush); #if defined(QVG_NO_MODIFY_PATH) - vgDestroyPath(vgpath); + d->releasePath(vgpath); #endif } else { QPaintEngineEx::drawRoundedRect(rect, xrad, yrad, mode); @@ -2636,13 +2664,7 @@ void QVGPaintEngine::drawEllipse(const QRectF &r) Q_D(QVGPaintEngine); if (d->simpleTransform) { QVGPainterState *s = state(); - VGPath path = vgCreatePath(VG_PATH_FORMAT_STANDARD, - VG_PATH_DATATYPE_F, - 1.0f, // scale - 0.0f, // bias - 4, // segmentCapacityHint - 12, // coordCapacityHint - VG_PATH_CAPABILITY_ALL); + VGPath path = d->reusablePath; static VGubyte segments[4] = { VG_MOVE_TO_ABS, VG_SCCWARC_TO_REL, @@ -2666,7 +2688,7 @@ void QVGPaintEngine::drawEllipse(const QRectF &r) coords[11] = 0.0f; vgAppendPathData(path, 4, segments, coords); d->draw(path, s->pen, s->brush); - vgDestroyPath(path); + d->releasePath(path); } else { // The projective transform version of an ellipse is difficult. // Generate a QVectorPath containing cubic curves and transform that. @@ -2690,7 +2712,7 @@ void QVGPaintEngine::drawPath(const QPainterPath &path) d->draw(vgpath, s->pen, s->brush, VG_EVEN_ODD); else d->draw(vgpath, s->pen, s->brush, VG_NON_ZERO); - vgDestroyPath(vgpath); + d->releasePath(vgpath); } void QVGPaintEngine::drawPoints(const QPointF *points, int pointCount) @@ -2765,13 +2787,7 @@ void QVGPaintEngine::drawPolygon(const QPointF *points, int pointCount, PolygonD { Q_D(QVGPaintEngine); QVGPainterState *s = state(); - VGPath path = vgCreatePath(VG_PATH_FORMAT_STANDARD, - VG_PATH_DATATYPE_F, - 1.0f, // scale - 0.0f, // bias - pointCount + 1, // segmentCapacityHint - pointCount * 2, // coordCapacityHint - VG_PATH_CAPABILITY_ALL); + VGPath path = d->reusablePath; QVarLengthArray coords; QVarLengthArray segments; for (int i = 0; i < pointCount; ++i, ++points) { @@ -2805,20 +2821,14 @@ void QVGPaintEngine::drawPolygon(const QPointF *points, int pointCount, PolygonD d->draw(path, s->pen, s->brush, VG_EVEN_ODD); break; } - vgDestroyPath(path); + d->releasePath(path); } void QVGPaintEngine::drawPolygon(const QPoint *points, int pointCount, PolygonDrawMode mode) { Q_D(QVGPaintEngine); QVGPainterState *s = state(); - VGPath path = vgCreatePath(VG_PATH_FORMAT_STANDARD, - VG_PATH_DATATYPE_F, - 1.0f, // scale - 0.0f, // bias - pointCount + 1, // segmentCapacityHint - pointCount * 2, // coordCapacityHint - VG_PATH_CAPABILITY_ALL); + VGPath path = d->reusablePath; QVarLengthArray coords; QVarLengthArray segments; for (int i = 0; i < pointCount; ++i, ++points) { @@ -2852,7 +2862,7 @@ void QVGPaintEngine::drawPolygon(const QPoint *points, int pointCount, PolygonDr d->draw(path, s->pen, s->brush, VG_EVEN_ODD); break; } - vgDestroyPath(path); + d->releasePath(path); } void QVGPaintEnginePrivate::setImageOptions() @@ -3251,7 +3261,7 @@ void QVGFontGlyphCache::cacheGlyphs ti.fontEngine->getUnscaledGlyph(glyph, &path, &metrics); VGPath vgPath; if (!path.isEmpty()) { - vgPath = d->painterPathToVGPath(path); + vgPath = d->painterPathToVGPath(path, true); } else { // Probably a "space" character with no visible outline. vgPath = VG_INVALID_HANDLE; -- cgit v0.12