forked from len0rd/rockbox
rbutil: Merge rbutil with utils folder.
rbutil uses several components from the utils folder, and can be considered part of utils too. Having it in a separate folder is an arbitrary split that doesn't help anymore these days, so merge them. This also allows other utils to easily use libtools.make without the need to navigate to a different folder. Change-Id: I3fc2f4de19e3e776553efb5dea5f779dfec0dc21
This commit is contained in:
parent
6c6f0757d7
commit
c876d3bbef
494 changed files with 13 additions and 13 deletions
11
utils/rbutilqt/test/stubs/Logger.h
Normal file
11
utils/rbutilqt/test/stubs/Logger.h
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
#ifndef LOGGER_H
|
||||
#define LOGGER_H
|
||||
|
||||
#include <QtDebug>
|
||||
|
||||
#define LOG_INFO qDebug
|
||||
#define LOG_WARNING qWarning
|
||||
#define LOG_ERROR qCritical
|
||||
|
||||
#endif
|
||||
|
||||
31
utils/rbutilqt/test/stubs/stubs-compareversion.cpp
Normal file
31
utils/rbutilqt/test/stubs/stubs-compareversion.cpp
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
|
||||
#include "playerbuildinfo.h"
|
||||
#include "rbsettings.h"
|
||||
#include "rockboxinfo.h"
|
||||
|
||||
// not used by the test, just to make things compile.
|
||||
QVariant RbSettings::value(RbSettings::UserSettings setting)
|
||||
{
|
||||
(void)setting;
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
|
||||
// not used in the test. If used the test will crash!
|
||||
PlayerBuildInfo* PlayerBuildInfo::instance()
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
QVariant PlayerBuildInfo::value(PlayerBuildInfo::DeviceInfo item, QString target)
|
||||
{
|
||||
(void)item;
|
||||
(void)target;
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
RockboxInfo::RockboxInfo(QString, QString)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
36
utils/rbutilqt/test/stubs/stubs-playerbuildinfo.cpp
Normal file
36
utils/rbutilqt/test/stubs/stubs-playerbuildinfo.cpp
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
/***************************************************************************
|
||||
* __________ __ ___.
|
||||
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
||||
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
||||
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
||||
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
||||
* \/ \/ \/ \/ \/
|
||||
*
|
||||
* Copyright (C) 2020 Dominik Riebeling
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
* KIND, either express or implied.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
// Stubs for PlayerBuildInfo unit test.
|
||||
|
||||
#include "rbsettings.h"
|
||||
|
||||
static QMap<RbSettings::UserSettings, QVariant> stubUserSettings;
|
||||
|
||||
void RbSettings::setValue(UserSettings setting, QVariant value)
|
||||
{
|
||||
stubUserSettings[setting] = value;
|
||||
}
|
||||
|
||||
QVariant RbSettings::value(UserSettings setting)
|
||||
{
|
||||
return stubUserSettings[setting];
|
||||
}
|
||||
|
||||
145
utils/rbutilqt/test/test-compareversion.cpp
Normal file
145
utils/rbutilqt/test/test-compareversion.cpp
Normal file
|
|
@ -0,0 +1,145 @@
|
|||
/***************************************************************************
|
||||
* __________ __ ___.
|
||||
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
||||
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
||||
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
||||
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
||||
* \/ \/ \/ \/ \/
|
||||
*
|
||||
* Copyright (C) 2010 Dominik Riebeling
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
* KIND, either express or implied.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#include <QtTest/QtTest>
|
||||
#include <QObject>
|
||||
#include "utils.h"
|
||||
|
||||
|
||||
class TestVersionCompare : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
private slots:
|
||||
void testCompare();
|
||||
void testCompare_data();
|
||||
void testTrim();
|
||||
void testTrim_data();
|
||||
};
|
||||
|
||||
|
||||
struct {
|
||||
const char* first;
|
||||
const char* second;
|
||||
const int expected;
|
||||
} const compdata[] =
|
||||
{
|
||||
{ "1.2.3", "1.2.3 ", 0 },
|
||||
{ "1.2.3", " 1.2.3", 0 },
|
||||
{ "1.2.3", "1.2.4", 1 },
|
||||
{ "1.2.3", "1.3.0", 1 },
|
||||
{ "1.2.3", "2.0.0", 1 },
|
||||
{ "10.22.33", "10.22.33", 0 },
|
||||
{ "10.22.33", "10.23.0", 1 },
|
||||
{ "10.22.33", "11.0.0", 1 },
|
||||
{ "1.2.3", "1.2.3.1", 1 },
|
||||
{ "1.2.3", "1.2.3-1", 1 },
|
||||
{ "1.2.3-1", "1.2.3.1", 1 },
|
||||
{ "1.2.3-10", "1.2.3.0", 1 },
|
||||
{ "1.2.3-1", "1.2.3.10", 1 },
|
||||
{ "1.2.3-1", "1.2.3a", 1 },
|
||||
{ "1.2.3", "1.2.3a", 1 },
|
||||
{ "1.2.3a", "1.2.3b", 1 },
|
||||
{ "1.2.3", "1.2.3b", 1 },
|
||||
{ "1.2.3.0", "2.0.0", 1 },
|
||||
{ "1.2.3b", "2.0.0", 1 },
|
||||
{ "1.2.3", "2.0.0.1", 1 },
|
||||
{ "test-1.2.3", "test-1.2.3.tar.gz", 0 },
|
||||
{ "1.2.3", "test-1.2.3.tar.bz2", 0 },
|
||||
{ "test-1.2.3.tar.gz", "test-1.2.3.tar.bz2", 0 },
|
||||
{ "test-1.2.3.tar.gz", "program-1.2.3.1.tar.bz2", 1 },
|
||||
{ "program-1.2.3.zip", "program-1.2.3a.zip", 1 },
|
||||
{ "program-1.2.3.tar.bz2", "2.0.0", 1 },
|
||||
{ "prog-1.2-64bit.tar.bz2", "prog-1.2.3.tar.bz2", 1 },
|
||||
{ "prog-1.2-64bit.tar.bz2", "prog-1.2-64bit.tar.bz2", 0 },
|
||||
{ "prog-1.2-64bit.tar.bz2", "prog-1.2.3-64bit.tar.bz2", 1 },
|
||||
{ "prog-1.2a-64bit.tar.bz2","prog-1.2b-64bit.tar.bz2", 1 },
|
||||
{ "prog-1.2-64bit.tar.bz2", "prog-1.2.3a-64bit.tar.bz2", 1 },
|
||||
{ "prog-1.2a-64bit.tar.bz2","prog-1.2.3-64bit.tar.bz2", 1 },
|
||||
};
|
||||
|
||||
struct {
|
||||
const char* input;
|
||||
const QString expected;
|
||||
} const trimdata[] =
|
||||
{
|
||||
{ "prog-1.2-64bit.tar.bz2", "1.2" },
|
||||
{ "prog-1.2.tar.bz2", "1.2" },
|
||||
{ "1.2.3", "1.2.3" },
|
||||
{ " 1.2.3", "1.2.3" },
|
||||
{ "1.2.3 ", "1.2.3" },
|
||||
{ "10.22.33", "10.22.33" },
|
||||
{ "test-1.2.3", "1.2.3" },
|
||||
{ "1.2.3", "1.2.3" },
|
||||
{ "test-1.2.3.tar.gz", "1.2.3" },
|
||||
{ "prog-1.2-64bit.tar.bz2", "1.2" },
|
||||
{ "prog-1.2a.tar.bz2", "1.2a" },
|
||||
{ "prog-1.2a-64bit.tar.bz2","1.2a" },
|
||||
};
|
||||
|
||||
|
||||
void TestVersionCompare::testCompare_data()
|
||||
{
|
||||
QTest::addColumn<QString>("first");
|
||||
QTest::addColumn<QString>("second");
|
||||
QTest::addColumn<int>("expected");
|
||||
for(size_t i = 0; i < sizeof(compdata) / sizeof(compdata[0]); i++) {
|
||||
QTest::newRow("") << compdata[i].first << compdata[i].second << compdata[i].expected;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void TestVersionCompare::testCompare()
|
||||
{
|
||||
QFETCH(QString, first);
|
||||
QFETCH(QString, second);
|
||||
QFETCH(int, expected);
|
||||
|
||||
QCOMPARE(Utils::compareVersionStrings(first, second), expected);
|
||||
if(expected != 0) {
|
||||
QCOMPARE(Utils::compareVersionStrings(second, first), -expected);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void TestVersionCompare::testTrim_data()
|
||||
{
|
||||
QTest::addColumn<QString>("input");
|
||||
QTest::addColumn<QString>("expected");
|
||||
for(size_t i = 0; i < sizeof(trimdata) / sizeof(trimdata[0]); i++) {
|
||||
QTest::newRow("") << trimdata[i].input << trimdata[i].expected;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void TestVersionCompare::testTrim()
|
||||
{
|
||||
QFETCH(QString, input);
|
||||
QFETCH(QString, expected);
|
||||
|
||||
QCOMPARE(Utils::trimVersionString(input), expected);
|
||||
}
|
||||
|
||||
|
||||
QTEST_MAIN(TestVersionCompare)
|
||||
|
||||
// this include is needed because we don't use a separate header file for the
|
||||
// test class. It also needs to be at the end.
|
||||
#include "test-compareversion.moc"
|
||||
|
||||
37
utils/rbutilqt/test/test-compareversion.pro
Normal file
37
utils/rbutilqt/test/test-compareversion.pro
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
#
|
||||
# __________ __ ___.
|
||||
# Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
||||
# Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
||||
# Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
||||
# Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
||||
# \/ \/ \/ \/ \/
|
||||
# $Id$
|
||||
#
|
||||
# All files in this archive are subject to the GNU General Public License.
|
||||
# See the file COPYING in the source tree root for full license agreement.
|
||||
#
|
||||
# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
# KIND, either express or implied.
|
||||
#
|
||||
|
||||
# Test: Utils::compareVersionStrings().
|
||||
#
|
||||
|
||||
QT += testlib
|
||||
|
||||
TEMPLATE = app
|
||||
TARGET = test-compareversion
|
||||
INCLUDEPATH += . ../base stubs
|
||||
|
||||
# Input
|
||||
SOURCES += \
|
||||
test-compareversion.cpp \
|
||||
stubs/stubs-compareversion.cpp \
|
||||
../base/utils.cpp
|
||||
|
||||
HEADERS += \
|
||||
../base/rbsettings.h \
|
||||
../base/playerbuildinfo.h \
|
||||
../base/rockboxinfo.h \
|
||||
../base/utils.h
|
||||
|
||||
547
utils/rbutilqt/test/test-httpget.cpp
Normal file
547
utils/rbutilqt/test/test-httpget.cpp
Normal file
|
|
@ -0,0 +1,547 @@
|
|||
/***************************************************************************
|
||||
* __________ __ ___.
|
||||
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
||||
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
||||
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
||||
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
||||
* \/ \/ \/ \/ \/
|
||||
*
|
||||
* Copyright (C) 2013 Dominik Riebeling
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
* KIND, either express or implied.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#include <QtTest/QtTest>
|
||||
#include <QtCore/QObject>
|
||||
#include "httpget.h"
|
||||
|
||||
#define TEST_USER_AGENT "TestAgent/2.3"
|
||||
#define TEST_HTTP_TIMEOUT 1000
|
||||
#define TEST_BINARY_BLOB "\x01\x10\x20\x30\x40\x50\x60\x70" \
|
||||
"\x80\x90\xff\xee\xdd\xcc\xbb\xaa"
|
||||
|
||||
// HttpDaemon is the the class that implements the simple HTTP server.
|
||||
class HttpDaemon : public QTcpServer
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
HttpDaemon(quint16 port = 0, QObject* parent = 0) : QTcpServer(parent)
|
||||
{
|
||||
listen(QHostAddress::Any, port);
|
||||
}
|
||||
|
||||
quint16 port(void) { return this->serverPort(); }
|
||||
|
||||
#if QT_VERSION < 0x050000
|
||||
void incomingConnection(int socket)
|
||||
#else
|
||||
// Qt 5 uses a different prototype for this function!
|
||||
void incomingConnection(qintptr socket)
|
||||
#endif
|
||||
{
|
||||
// When a new client connects, the server constructs a QTcpSocket and all
|
||||
// communication with the client is done over this QTcpSocket. QTcpSocket
|
||||
// works asynchronously, this means that all the communication is done
|
||||
// in the two slots readClient() and discardClient().
|
||||
QTcpSocket* s = new QTcpSocket(this);
|
||||
connect(s, SIGNAL(readyRead()), this, SLOT(readClient()));
|
||||
connect(s, SIGNAL(disconnected()), this, SLOT(discardClient()));
|
||||
s->setSocketDescriptor(socket);
|
||||
}
|
||||
QList<QString> lastRequestData(void)
|
||||
{
|
||||
return m_lastRequestData;
|
||||
}
|
||||
void setResponsesToSend(QList<QByteArray> response)
|
||||
{
|
||||
m_requestNumber = 0;
|
||||
m_responsesToSend = response;
|
||||
}
|
||||
void reset(void)
|
||||
{
|
||||
m_requestNumber = 0;
|
||||
m_lastRequestData.clear();
|
||||
QString now =
|
||||
QDateTime::currentDateTime().toString("ddd, d MMM yyyy hh:mm:ss");
|
||||
m_defaultResponse = QByteArray(
|
||||
"HTTP/1.1 404 Not Found\r\n"
|
||||
"Date: " + now.toLatin1() + "\r\n"
|
||||
"Last-Modified: " + now.toLatin1() + "\r\n"
|
||||
"Connection: close\r\n"
|
||||
"\r\n");
|
||||
}
|
||||
|
||||
private slots:
|
||||
void readClient()
|
||||
{
|
||||
// This slot is called when the client sent data to the server.
|
||||
QTcpSocket* socket = (QTcpSocket*)sender();
|
||||
// read whole request
|
||||
QString request;
|
||||
while(socket->canReadLine()) {
|
||||
QString line = socket->readLine();
|
||||
request.append(line);
|
||||
if(request.endsWith("\r\n\r\n")) {
|
||||
m_lastRequestData.append(request);
|
||||
|
||||
if(m_requestNumber < m_responsesToSend.size())
|
||||
socket->write(m_responsesToSend.at(m_requestNumber));
|
||||
else
|
||||
socket->write(m_defaultResponse);
|
||||
socket->close();
|
||||
m_requestNumber++;
|
||||
}
|
||||
if (socket->state() == QTcpSocket::UnconnectedState)
|
||||
delete socket;
|
||||
}
|
||||
}
|
||||
void discardClient()
|
||||
{
|
||||
QTcpSocket* socket = (QTcpSocket*)sender();
|
||||
socket->deleteLater();
|
||||
}
|
||||
|
||||
private:
|
||||
int m_requestNumber;
|
||||
QList<QByteArray> m_responsesToSend;
|
||||
QList<QString> m_lastRequestData;
|
||||
QByteArray m_defaultResponse;
|
||||
};
|
||||
|
||||
|
||||
class TestHttpGet : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
private slots:
|
||||
void testFileUrlRequest(void);
|
||||
void testCachedRequest(void);
|
||||
void testUncachedRepeatedRequest(void);
|
||||
void testUncachedMovedRequest(void);
|
||||
void testUserAgent(void);
|
||||
void testResponseCode(void);
|
||||
void testContentToBuffer(void);
|
||||
void testContentToFile(void);
|
||||
void testNoServer(void);
|
||||
void testServerTimestamp(void);
|
||||
void testMovedQuery(void);
|
||||
void init(void);
|
||||
void cleanup(void);
|
||||
|
||||
public slots:
|
||||
void waitTimeout(void)
|
||||
{
|
||||
m_waitTimeoutOccured = true;
|
||||
}
|
||||
QDir temporaryFolder(void)
|
||||
{
|
||||
// Qt unfortunately doesn't support creating temporary folders so
|
||||
// we need to do that ourselves.
|
||||
QString tempdir;
|
||||
for(int i = 0; i < 100000; i++) {
|
||||
tempdir = QDir::tempPath() + QString("/qttest-temp-%1").arg(i);
|
||||
if(!QFileInfo(tempdir).exists()) break;
|
||||
}
|
||||
QDir().mkpath(tempdir);
|
||||
return QDir(tempdir);
|
||||
}
|
||||
void rmTree(QString folder)
|
||||
{
|
||||
// no function in Qt to recursively delete a folder :(
|
||||
QDir dir(folder);
|
||||
Q_FOREACH(QFileInfo info, dir.entryInfoList(QDir::NoDotAndDotDot
|
||||
| QDir::System | QDir::Hidden | QDir::AllDirs
|
||||
| QDir::Files, QDir::DirsFirst)) {
|
||||
if(info.isDir()) rmTree(info.absoluteFilePath());
|
||||
else QFile::remove(info.absoluteFilePath());
|
||||
}
|
||||
dir.rmdir(folder);
|
||||
}
|
||||
private:
|
||||
HttpDaemon *m_daemon;
|
||||
QByteArray m_port;
|
||||
bool m_waitTimeoutOccured;
|
||||
QString m_now;
|
||||
QDir m_cachedir;
|
||||
HttpGet *m_getter;
|
||||
QSignalSpy *m_doneSpy;
|
||||
QSignalSpy *m_progressSpy;
|
||||
};
|
||||
|
||||
|
||||
void TestHttpGet::init(void)
|
||||
{
|
||||
m_now = QDateTime::currentDateTime().toString("ddd, d MMM yyyy hh:mm:ss");
|
||||
m_daemon = new HttpDaemon(0, this); // use port 0 to auto-pick
|
||||
m_daemon->reset();
|
||||
m_port = QString("%1").arg(m_daemon->port()).toLatin1();
|
||||
m_cachedir = temporaryFolder();
|
||||
m_getter = new HttpGet(this);
|
||||
m_doneSpy = new QSignalSpy(m_getter, SIGNAL(done(bool)));
|
||||
m_progressSpy = new QSignalSpy(m_getter, SIGNAL(dataReadProgress(int, int)));
|
||||
m_waitTimeoutOccured = false;
|
||||
}
|
||||
|
||||
void TestHttpGet::cleanup(void)
|
||||
{
|
||||
rmTree(m_cachedir.absolutePath());
|
||||
if(m_getter) {
|
||||
m_getter->abort(); delete m_getter; m_getter = NULL;
|
||||
}
|
||||
if(m_daemon) { delete m_daemon; m_daemon = NULL; }
|
||||
if(m_doneSpy) { delete m_doneSpy; m_doneSpy = NULL; }
|
||||
if(m_progressSpy) { delete m_progressSpy; m_progressSpy = NULL; }
|
||||
}
|
||||
|
||||
void TestHttpGet::testFileUrlRequest(void)
|
||||
{
|
||||
QTimer::singleShot(TEST_HTTP_TIMEOUT, this, SLOT(waitTimeout(void)));
|
||||
|
||||
QString teststring = "The quick brown fox jumps over the lazy dog.";
|
||||
QTemporaryFile datafile;
|
||||
datafile.open();
|
||||
datafile.write(teststring.toLatin1());
|
||||
m_getter->getFile(QUrl::fromLocalFile(datafile.fileName()));
|
||||
datafile.close();
|
||||
while(m_doneSpy->count() == 0 && m_waitTimeoutOccured == false)
|
||||
QCoreApplication::processEvents();
|
||||
|
||||
QCOMPARE(m_doneSpy->count(), 1);
|
||||
QCOMPARE(m_waitTimeoutOccured, false);
|
||||
QCOMPARE(m_daemon->lastRequestData().size(), 0);
|
||||
QCOMPARE(m_getter->readAll(), teststring.toLatin1());
|
||||
QCOMPARE(m_getter->httpResponse(), 200);
|
||||
QCOMPARE(m_progressSpy->at(0).at(0).toInt(), 0);
|
||||
}
|
||||
|
||||
|
||||
/* On uncached requests, HttpGet is supposed to sent a GET request only.
|
||||
*/
|
||||
void TestHttpGet::testUncachedRepeatedRequest(void)
|
||||
{
|
||||
QList<QByteArray> responses;
|
||||
responses << QByteArray(
|
||||
"HTTP/1.1 200 OK\r\n"
|
||||
"Date: " + m_now.toLatin1() + "\r\n"
|
||||
"Last-Modified: " + m_now.toLatin1() + "\r\n"
|
||||
"\r\n\r\n");
|
||||
responses << QByteArray(
|
||||
"HTTP/1.1 200 OK\r\n"
|
||||
"Last-Modified: " + m_now.toLatin1() + "\r\n"
|
||||
"Date: " + m_now.toLatin1() + "\r\n"
|
||||
"\r\n"
|
||||
"<html></html>\r\n\r\n");
|
||||
m_daemon->setResponsesToSend(responses);
|
||||
|
||||
QTimer::singleShot(TEST_HTTP_TIMEOUT, this, SLOT(waitTimeout(void)));
|
||||
|
||||
m_getter->getFile(QUrl("http://localhost:" + m_port + "/test1.txt"));
|
||||
while(m_doneSpy->count() == 0 && m_waitTimeoutOccured == false)
|
||||
QCoreApplication::processEvents();
|
||||
|
||||
QCOMPARE(m_doneSpy->count(), 1);
|
||||
QCOMPARE(m_waitTimeoutOccured, false);
|
||||
QCOMPARE(m_daemon->lastRequestData().size(), 1);
|
||||
QCOMPARE(m_daemon->lastRequestData().at(0).startsWith("GET"), true);
|
||||
|
||||
// request second time
|
||||
m_getter->getFile(QUrl("http://localhost:" + m_port + "/test1.txt"));
|
||||
while(m_doneSpy->count() < 2 && m_waitTimeoutOccured == false)
|
||||
QCoreApplication::processEvents();
|
||||
QCOMPARE(m_doneSpy->count(), 2);
|
||||
QCOMPARE(m_waitTimeoutOccured, false);
|
||||
QCOMPARE(m_daemon->lastRequestData().size(), 2);
|
||||
QCOMPARE(m_daemon->lastRequestData().at(1).startsWith("GET"), true);
|
||||
QCOMPARE(m_getter->httpResponse(), 200);
|
||||
}
|
||||
|
||||
/* With enabled cache HttpGet is supposed to check the server file using a HEAD
|
||||
* request first, then request the file using GET if the server file is newer
|
||||
* than the cached one (or the file does not exist in the cache)
|
||||
*/
|
||||
void TestHttpGet::testCachedRequest(void)
|
||||
{
|
||||
QList<QByteArray> responses;
|
||||
responses << QByteArray(
|
||||
"HTTP/1.1 302 Found\r\n"
|
||||
"Location: http://localhost:" + m_port + "/test2.txt\r\n"
|
||||
"Date: " + m_now.toLatin1() + "\r\n"
|
||||
"Last-Modified: " + m_now.toLatin1() + "\r\n"
|
||||
"\r\n");
|
||||
responses << QByteArray(
|
||||
"HTTP/1.1 200 OK\r\n"
|
||||
"Last-Modified: " + m_now.toLatin1() + "\r\n"
|
||||
"Date: " + m_now.toLatin1() + "\r\n"
|
||||
"\r\n"
|
||||
"<html></html>\r\n\r\n");
|
||||
responses << QByteArray(
|
||||
"HTTP/1.1 200 OK\r\n"
|
||||
"Last-Modified: 1 Jan 2000 00:00:00\r\n"
|
||||
"Date: " + m_now.toLatin1() + "\r\n"
|
||||
"\r\n");
|
||||
m_daemon->setResponsesToSend(responses);
|
||||
|
||||
QTimer::singleShot(TEST_HTTP_TIMEOUT, this, SLOT(waitTimeout(void)));
|
||||
|
||||
m_getter->setCache(m_cachedir);
|
||||
m_getter->getFile(QUrl("http://localhost:" + m_port + "/test1.txt"));
|
||||
while(m_doneSpy->count() == 0 && m_waitTimeoutOccured == false)
|
||||
QCoreApplication::processEvents();
|
||||
|
||||
QList<QString> requests = m_daemon->lastRequestData();
|
||||
QCOMPARE(m_doneSpy->count(), 1);
|
||||
QCOMPARE(m_doneSpy->at(0).at(0).toBool(), false);
|
||||
QCOMPARE(m_waitTimeoutOccured, false);
|
||||
QCOMPARE(requests.size(), 2);
|
||||
QCOMPARE(requests.at(0).startsWith("GET"), true);
|
||||
QCOMPARE(requests.at(1).startsWith("GET"), true);
|
||||
QCOMPARE(m_getter->httpResponse(), 200);
|
||||
|
||||
// request real file, this time the response should come from cache.
|
||||
m_getter->getFile(QUrl("http://localhost:" + m_port + "/test2.txt"));
|
||||
while(m_doneSpy->count() < 2 && m_waitTimeoutOccured == false)
|
||||
QCoreApplication::processEvents();
|
||||
QCOMPARE(m_doneSpy->count(), 2); // 2 requests, 2 times done()
|
||||
QCOMPARE(m_doneSpy->at(1).at(0).toBool(), false);
|
||||
QCOMPARE(m_waitTimeoutOccured, false);
|
||||
QCOMPARE(m_daemon->lastRequestData().size(), 3);
|
||||
// redirect will not cache as the redirection target file.
|
||||
QCOMPARE(m_daemon->lastRequestData().at(2).startsWith("GET"), true);
|
||||
QCOMPARE(m_getter->httpResponse(), 200);
|
||||
}
|
||||
|
||||
/* When a custom user agent is set all requests are supposed to contain it.
|
||||
* Enable cache to make HttpGet performs a HEAD request. Answer with 302, so
|
||||
* HttpGet follows and sends another HEAD request before finally doing a GET.
|
||||
*/
|
||||
void TestHttpGet::testUserAgent(void)
|
||||
{
|
||||
QList<QByteArray> responses;
|
||||
responses << QByteArray(
|
||||
"HTTP/1.1 200 OK\r\n"
|
||||
"Date: " + m_now.toLatin1() + "\r\n"
|
||||
"Last-Modified: " + m_now.toLatin1() + "\r\n"
|
||||
"\r\n\r\n");
|
||||
responses << QByteArray(
|
||||
"HTTP/1.1 200 OK\r\n"
|
||||
"Last-Modified: " + m_now.toLatin1() + "\r\n"
|
||||
"Date: " + m_now.toLatin1() + "\r\n"
|
||||
"\r\n"
|
||||
"<html></html>\r\n\r\n");
|
||||
m_daemon->setResponsesToSend(responses);
|
||||
|
||||
QTimer::singleShot(TEST_HTTP_TIMEOUT, this, SLOT(waitTimeout(void)));
|
||||
|
||||
m_getter->setGlobalUserAgent(TEST_USER_AGENT);
|
||||
m_getter->setCache(m_cachedir);
|
||||
m_getter->getFile(QUrl("http://localhost:" + m_port + "/test1.txt"));
|
||||
while(m_doneSpy->count() == 0 && m_waitTimeoutOccured == false)
|
||||
QCoreApplication::processEvents();
|
||||
|
||||
QList<QString> requests = m_daemon->lastRequestData();
|
||||
QCOMPARE(m_doneSpy->count(), 1);
|
||||
QCOMPARE(m_waitTimeoutOccured, false);
|
||||
QCOMPARE(requests.size(), 1);
|
||||
QCOMPARE(requests.at(0).startsWith("GET"), true);
|
||||
|
||||
for(int i = 0; i < requests.size(); ++i) {
|
||||
QRegExp rx("User-Agent:[\t ]+([a-zA-Z0-9\\./]+)");
|
||||
bool userAgentFound = rx.indexIn(requests.at(i)) > 0 ? true : false;
|
||||
QCOMPARE(userAgentFound, true);
|
||||
QString userAgentString = rx.cap(1);
|
||||
QCOMPARE(userAgentString, QString(TEST_USER_AGENT));
|
||||
}
|
||||
}
|
||||
|
||||
void TestHttpGet::testUncachedMovedRequest(void)
|
||||
{
|
||||
QList<QByteArray> responses;
|
||||
responses << QByteArray(
|
||||
"HTTP/1.1 302 Found\r\n"
|
||||
"Location: http://localhost:" + m_port + "/test2.txt\r\n"
|
||||
"Date: " + m_now.toLatin1() + "\r\n"
|
||||
"Last-Modified: " + m_now.toLatin1() + "\r\n"
|
||||
"\r\n");
|
||||
responses << QByteArray(
|
||||
"HTTP/1.1 200 OK\r\n"
|
||||
"Last-Modified: " + m_now.toLatin1() + "\r\n"
|
||||
"Date: " + m_now.toLatin1() + "\r\n"
|
||||
"\r\n"
|
||||
"<html></html>\r\n\r\n");
|
||||
m_daemon->setResponsesToSend(responses);
|
||||
|
||||
QTimer::singleShot(TEST_HTTP_TIMEOUT, this, SLOT(waitTimeout(void)));
|
||||
|
||||
m_getter->getFile(QUrl("http://localhost:" + m_port + "/test1.php?var=1&b=foo"));
|
||||
while(m_doneSpy->count() == 0 && m_waitTimeoutOccured == false)
|
||||
QCoreApplication::processEvents();
|
||||
|
||||
QCOMPARE(m_doneSpy->count(), 1);
|
||||
QCOMPARE(m_waitTimeoutOccured, false);
|
||||
QCOMPARE(m_daemon->lastRequestData().size(), 2);
|
||||
QCOMPARE(m_daemon->lastRequestData().at(0).startsWith("GET"), true);
|
||||
QCOMPARE(m_daemon->lastRequestData().at(1).startsWith("GET"), true);
|
||||
}
|
||||
|
||||
void TestHttpGet::testResponseCode(void)
|
||||
{
|
||||
QTimer::singleShot(TEST_HTTP_TIMEOUT, this, SLOT(waitTimeout(void)));
|
||||
|
||||
m_getter->getFile(QUrl("http://localhost:" + m_port + "/test1.txt"));
|
||||
while(m_doneSpy->count() == 0 && m_waitTimeoutOccured == false)
|
||||
QCoreApplication::processEvents();
|
||||
|
||||
QCOMPARE(m_doneSpy->count(), 1);
|
||||
QCOMPARE(m_doneSpy->at(0).at(0).toBool(), true);
|
||||
QCOMPARE(m_waitTimeoutOccured, false);
|
||||
QCOMPARE(m_daemon->lastRequestData().size(), 1);
|
||||
QCOMPARE(m_daemon->lastRequestData().at(0).startsWith("GET"), true);
|
||||
QCOMPARE(m_getter->httpResponse(), 404);
|
||||
}
|
||||
|
||||
void TestHttpGet::testContentToBuffer(void)
|
||||
{
|
||||
QList<QByteArray> responses;
|
||||
responses << QByteArray(
|
||||
"HTTP/1.1 200 OK\r\n"
|
||||
"Last-Modified: " + m_now.toLatin1() + "\r\n"
|
||||
"Date: " + m_now.toLatin1() + "\r\n"
|
||||
"\r\n"
|
||||
TEST_BINARY_BLOB);
|
||||
m_daemon->setResponsesToSend(responses);
|
||||
|
||||
QTimer::singleShot(TEST_HTTP_TIMEOUT, this, SLOT(waitTimeout(void)));
|
||||
|
||||
m_getter->getFile(QUrl("http://localhost:" + m_port + "/test1.txt"));
|
||||
while(m_doneSpy->count() == 0 && m_waitTimeoutOccured == false)
|
||||
QCoreApplication::processEvents();
|
||||
|
||||
QCOMPARE(m_doneSpy->count(), 1);
|
||||
QCOMPARE(m_waitTimeoutOccured, false);
|
||||
QCOMPARE(m_getter->readAll(), QByteArray(TEST_BINARY_BLOB));
|
||||
// sizeof(TEST_BINARY_BLOB) will include an additional terminating NULL.
|
||||
QCOMPARE(m_getter->readAll().size(), (int)sizeof(TEST_BINARY_BLOB) - 1);
|
||||
QCOMPARE(m_progressSpy->at(m_progressSpy->count() - 1).at(0).toInt(), (int)sizeof(TEST_BINARY_BLOB) - 1);
|
||||
QCOMPARE(m_progressSpy->at(m_progressSpy->count() - 1).at(1).toInt(), (int)sizeof(TEST_BINARY_BLOB) - 1);
|
||||
}
|
||||
|
||||
void TestHttpGet::testContentToFile(void)
|
||||
{
|
||||
QTemporaryFile tf(this);
|
||||
QList<QByteArray> responses;
|
||||
responses << QByteArray(
|
||||
"HTTP/1.1 200 OK\r\n"
|
||||
"Last-Modified: " + m_now.toLatin1() + "\r\n"
|
||||
"Date: " + m_now.toLatin1() + "\r\n"
|
||||
"\r\n"
|
||||
TEST_BINARY_BLOB);
|
||||
m_daemon->setResponsesToSend(responses);
|
||||
|
||||
QTimer::singleShot(TEST_HTTP_TIMEOUT, this, SLOT(waitTimeout(void)));
|
||||
|
||||
m_getter->setFile(&tf);
|
||||
m_getter->getFile(QUrl("http://localhost:" + m_port + "/test1.txt"));
|
||||
while(m_doneSpy->count() == 0 && m_waitTimeoutOccured == false)
|
||||
QCoreApplication::processEvents();
|
||||
|
||||
QCOMPARE(m_doneSpy->count(), 1);
|
||||
QCOMPARE(m_waitTimeoutOccured, false);
|
||||
|
||||
tf.open();
|
||||
QByteArray data = tf.readAll();
|
||||
QCOMPARE(data, QByteArray(TEST_BINARY_BLOB));
|
||||
QCOMPARE((unsigned long)data.size(), sizeof(TEST_BINARY_BLOB) - 1);
|
||||
tf.close();
|
||||
}
|
||||
|
||||
void TestHttpGet::testNoServer(void)
|
||||
{
|
||||
QTimer::singleShot(TEST_HTTP_TIMEOUT, this, SLOT(waitTimeout(void)));
|
||||
m_getter->getFile(QUrl("http://localhost:53/test1.txt"));
|
||||
while(m_doneSpy->count() == 0 && m_waitTimeoutOccured == false)
|
||||
QCoreApplication::processEvents();
|
||||
|
||||
QCOMPARE(m_doneSpy->count(), 1);
|
||||
QCOMPARE(m_doneSpy->at(0).at(0).toBool(), true);
|
||||
QCOMPARE(m_waitTimeoutOccured, false);
|
||||
}
|
||||
|
||||
void TestHttpGet::testServerTimestamp(void)
|
||||
{
|
||||
QList<QByteArray> responses;
|
||||
responses << QByteArray(
|
||||
"HTTP/1.1 200 OK\r\n"
|
||||
"Last-Modified: Wed, 20 Jan 2010 10:20:30\r\n" // RFC 822
|
||||
"Date: Wed, 20 Jan 2010 10:20:30\r\n"
|
||||
"\r\n"
|
||||
"\r\n");
|
||||
responses << QByteArray(
|
||||
"HTTP/1.1 200 OK\r\n"
|
||||
"Last-Modified: Sat Feb 19 09:08:07 2011\r\n" // asctime
|
||||
"Date: Sat Feb 19 09:08:07 2011\r\n"
|
||||
"\r\n"
|
||||
"\r\n");
|
||||
|
||||
QList<QDateTime> times;
|
||||
times << QDateTime::fromString("2010-01-20T11:20:30", Qt::ISODate);
|
||||
times << QDateTime::fromString("2011-02-19T10:08:07", Qt::ISODate);
|
||||
|
||||
m_daemon->setResponsesToSend(responses);
|
||||
|
||||
QTimer::singleShot(TEST_HTTP_TIMEOUT, this, SLOT(waitTimeout(void)));
|
||||
|
||||
int count = m_doneSpy->count();
|
||||
for(int i = 0; i < responses.size(); ++i) {
|
||||
m_getter->getFile(QUrl("http://localhost:" + m_port + "/test1.txt"));
|
||||
while(m_doneSpy->count() == count && m_waitTimeoutOccured == false)
|
||||
QCoreApplication::processEvents();
|
||||
count = m_doneSpy->count();
|
||||
QCOMPARE(m_getter->timestamp(), times.at(i));
|
||||
}
|
||||
}
|
||||
|
||||
void TestHttpGet::testMovedQuery(void)
|
||||
{
|
||||
QList<QByteArray> responses;
|
||||
responses << QByteArray(
|
||||
"HTTP/1.1 302 Found\r\n"
|
||||
"Location: http://localhost:" + m_port + "/test2.php\r\n"
|
||||
"Date: " + m_now.toLatin1() + "\r\n"
|
||||
"Last-Modified: " + m_now.toLatin1() + "\r\n"
|
||||
"\r\n");
|
||||
responses << QByteArray(
|
||||
"HTTP/1.1 200 OK\r\n"
|
||||
"Last-Modified: " + m_now.toLatin1() + "\r\n"
|
||||
"Date: " + m_now.toLatin1() + "\r\n"
|
||||
"\r\n"
|
||||
"<html></html>\r\n\r\n");
|
||||
m_daemon->setResponsesToSend(responses);
|
||||
|
||||
QTimer::singleShot(TEST_HTTP_TIMEOUT, this, SLOT(waitTimeout(void)));
|
||||
|
||||
m_getter->getFile(QUrl("http://localhost:" + m_port + "/test1.php?var=1&b=foo"));
|
||||
while(m_doneSpy->count() == 0 && m_waitTimeoutOccured == false)
|
||||
QCoreApplication::processEvents();
|
||||
|
||||
QCOMPARE(m_doneSpy->count(), 1);
|
||||
QCOMPARE(m_waitTimeoutOccured, false);
|
||||
QCOMPARE(m_getter->httpResponse(), 200);
|
||||
QCOMPARE(m_daemon->lastRequestData().size(), 2);
|
||||
QCOMPARE(m_daemon->lastRequestData().at(0).startsWith("GET"), true);
|
||||
QCOMPARE(m_daemon->lastRequestData().at(1).startsWith("GET"), true);
|
||||
// current implementation keeps order of query items.
|
||||
QCOMPARE((bool)m_daemon->lastRequestData().at(1).contains("/test2.php?var=1&b=foo"), true);
|
||||
}
|
||||
|
||||
QTEST_MAIN(TestHttpGet)
|
||||
|
||||
// this include is needed because we don't use a separate header file for the
|
||||
// test class. It also needs to be at the end.
|
||||
#include "test-httpget.moc"
|
||||
|
||||
31
utils/rbutilqt/test/test-httpget.pro
Normal file
31
utils/rbutilqt/test/test-httpget.pro
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
#
|
||||
# __________ __ ___.
|
||||
# Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
||||
# Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
||||
# Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
||||
# Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
||||
# \/ \/ \/ \/ \/
|
||||
#
|
||||
# All files in this archive are subject to the GNU General Public License.
|
||||
# See the file COPYING in the source tree root for full license agreement.
|
||||
#
|
||||
# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
# KIND, either express or implied.
|
||||
#
|
||||
|
||||
#
|
||||
include(tests.pri)
|
||||
|
||||
TEMPLATE = app
|
||||
TARGET = test-httpget
|
||||
INCLUDEPATH += . ../base stubs
|
||||
QT += network
|
||||
|
||||
# Input
|
||||
SOURCES += \
|
||||
test-httpget.cpp
|
||||
|
||||
SOURCES += ../base/httpget.cpp
|
||||
|
||||
HEADERS += ../base/httpget.h
|
||||
|
||||
240
utils/rbutilqt/test/test-playerbuildinfo.cpp
Normal file
240
utils/rbutilqt/test/test-playerbuildinfo.cpp
Normal file
|
|
@ -0,0 +1,240 @@
|
|||
/***************************************************************************
|
||||
* __________ __ ___.
|
||||
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
||||
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
||||
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
||||
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
||||
* \/ \/ \/ \/ \/
|
||||
*
|
||||
* Copyright (C) 2020 Dominik Riebeling
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
* KIND, either express or implied.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#include <QtTest>
|
||||
#include <QObject>
|
||||
#include "playerbuildinfo.h"
|
||||
#include "rbsettings.h"
|
||||
|
||||
class TestPlayerBuildInfo : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void testBuildInfo();
|
||||
void testBuildInfo_data();
|
||||
void testPlayerInfo();
|
||||
void testPlayerInfo_data();
|
||||
};
|
||||
|
||||
const char* testinfo =
|
||||
"[release]\n"
|
||||
"build_url=https://buildurl/release/%VERSION%/rockbox-%TARGET%-%VERSION%.zip\n"
|
||||
"voice_url=https://buildurl/release/%VERSION%/voice-%TARGET%-%VERSION%.zip\n"
|
||||
"manual_url=https://buildurl/release/%VERSION%/manual-%TARGET%-%VERSION%.zip\n"
|
||||
"source_url=https://buildurl/release/%VERSION%/rockbox-%TARGET%-src-%VERSION%.zip\n"
|
||||
"font_url=https://buildurl/release/%VERSION%/fonts-%VERSION%.zip\n"
|
||||
"archosfmrecorder=3.11.2\n"
|
||||
"iaudiom3=3.11.2,http://dl.rockbox.org/release/3.11.2/rockbox-iaudiom5-3.11.2.zip\n"
|
||||
"sansae200 = 3.15\n"
|
||||
"iriverh100 = 3.11.2, http://dl.rockbox.org/release/3.11.2/rockbox-iriverh100-3.11.2.zip\n"
|
||||
"iriverh120 = 3.3\n"
|
||||
"iriverh300 = \n"
|
||||
"[release-candidate]\n"
|
||||
"build_url=https://buildurl/rc/%VERSION%/rockbox-%TARGET%-%VERSION%.zip\n"
|
||||
"gigabeatfx=f9dce96,http://dl.rockbox.org/rc/f9dce96/rockbox-gigabeatfx.zip\n"
|
||||
"archosfmrecorder=f9dce96\n"
|
||||
"archosrecorder = f9dce96\n"
|
||||
"iaudiox5=f9dce96,http://dl.rockbox.org/rc/f9dce96/rockbox-iaudiox5.zip\n"
|
||||
"[development]\n"
|
||||
"build_url=https://buildurl/dev/rockbox-%TARGET%.zip\n"
|
||||
"iriverh100 = be1be79\n"
|
||||
"iaudiox5 = be1be76\n"
|
||||
"[dailies]\n"
|
||||
"timestamp = 20201113\n"
|
||||
"rev = 362f7a3\n"
|
||||
"[daily]\n"
|
||||
"build_url=https://buildurl/daily/rockbox-%TARGET%-%VERSION%.zip\n"
|
||||
"iriverh100 = f9dce00\n"
|
||||
"[bleeding]\n"
|
||||
"timestamp = 20201114T105723Z\n"
|
||||
"rev = be1be79\n"
|
||||
"[status]\n"
|
||||
"archosfmrecorder=3\n"
|
||||
"iriverh100=2\n"
|
||||
"iriverh300=1\n"
|
||||
"iriverh10=0\n"
|
||||
"[voices]\n"
|
||||
"3.15=english,francais\n"
|
||||
"3.11.2=english\n"
|
||||
"daily=deutsch,english,francais\n"
|
||||
;
|
||||
|
||||
Q_DECLARE_METATYPE(PlayerBuildInfo::BuildInfo);
|
||||
Q_DECLARE_METATYPE(PlayerBuildInfo::BuildType);
|
||||
Q_DECLARE_METATYPE(PlayerBuildInfo::DeviceInfo);
|
||||
|
||||
struct {
|
||||
QString target;
|
||||
PlayerBuildInfo::BuildInfo item;
|
||||
PlayerBuildInfo::BuildType type;
|
||||
QString expected;
|
||||
} testdataBuild[] =
|
||||
{
|
||||
// release builds
|
||||
{ "iriverh100", PlayerBuildInfo::BuildVoiceLangs, PlayerBuildInfo::TypeRelease, "english" },
|
||||
{ "iriverh300", PlayerBuildInfo::BuildVersion, PlayerBuildInfo::TypeRelease, "" },
|
||||
{ "iriverh300", PlayerBuildInfo::BuildUrl, PlayerBuildInfo::TypeRelease, "" },
|
||||
{ "iriverh10", PlayerBuildInfo::BuildVersion, PlayerBuildInfo::TypeRelease, "" },
|
||||
{ "iriverh10", PlayerBuildInfo::BuildUrl, PlayerBuildInfo::TypeRelease, "" },
|
||||
{ "archosfmrecorder", PlayerBuildInfo::BuildVersion, PlayerBuildInfo::TypeRelease, "3.11.2" },
|
||||
{ "iaudiom3", PlayerBuildInfo::BuildVersion, PlayerBuildInfo::TypeRelease, "3.11.2" },
|
||||
{ "iaudiom3", PlayerBuildInfo::BuildUrl, PlayerBuildInfo::TypeRelease, "http://dl.rockbox.org/release/3.11.2/rockbox-iaudiom5-3.11.2.zip" },
|
||||
{ "sansae200", PlayerBuildInfo::BuildVersion, PlayerBuildInfo::TypeRelease, "3.15" },
|
||||
{ "sansae200", PlayerBuildInfo::BuildUrl, PlayerBuildInfo::TypeRelease, "https://buildurl/release/3.15/rockbox-sansae200-3.15.zip" },
|
||||
{ "iriverh100", PlayerBuildInfo::BuildVersion, PlayerBuildInfo::TypeRelease, "3.11.2" },
|
||||
{ "iriverh100", PlayerBuildInfo::BuildUrl, PlayerBuildInfo::TypeRelease, "http://dl.rockbox.org/release/3.11.2/rockbox-iriverh100-3.11.2.zip" },
|
||||
{ "iriverh100", PlayerBuildInfo::BuildVoiceUrl, PlayerBuildInfo::TypeRelease, "https://buildurl/release/3.11.2/voice-iriverh100-3.11.2.zip" },
|
||||
{ "iriverh100", PlayerBuildInfo::BuildManualUrl, PlayerBuildInfo::TypeRelease, "https://buildurl/release/3.11.2/manual-iriverh100-3.11.2.zip" },
|
||||
{ "iriverh100", PlayerBuildInfo::BuildSourceUrl, PlayerBuildInfo::TypeRelease, "https://buildurl/release/3.11.2/rockbox-iriverh100-src-3.11.2.zip" },
|
||||
// h120 uses the same manual as h100.
|
||||
{ "iriverh120", PlayerBuildInfo::BuildManualUrl, PlayerBuildInfo::TypeRelease, "https://buildurl/release/3.3/manual-iriverh100-3.3.zip" },
|
||||
{ "iriverh100", PlayerBuildInfo::BuildFontUrl, PlayerBuildInfo::TypeRelease, "https://buildurl/release/3.11.2/fonts-3.11.2.zip" },
|
||||
|
||||
// rc builds
|
||||
{ "gigabeatfx", PlayerBuildInfo::BuildVersion, PlayerBuildInfo::TypeCandidate, "f9dce96" },
|
||||
{ "gigabeatfx", PlayerBuildInfo::BuildUrl, PlayerBuildInfo::TypeCandidate, "http://dl.rockbox.org/rc/f9dce96/rockbox-gigabeatfx.zip" },
|
||||
{ "archosfmrecorder", PlayerBuildInfo::BuildVersion, PlayerBuildInfo::TypeCandidate, "f9dce96" },
|
||||
{ "archosfmrecorder", PlayerBuildInfo::BuildUrl, PlayerBuildInfo::TypeCandidate, "https://buildurl/rc/f9dce96/rockbox-archosfmrecorder-f9dce96.zip" },
|
||||
{ "archosrecorder", PlayerBuildInfo::BuildVersion, PlayerBuildInfo::TypeCandidate, "f9dce96" },
|
||||
{ "archosrecorder", PlayerBuildInfo::BuildUrl, PlayerBuildInfo::TypeCandidate, "https://buildurl/rc/f9dce96/rockbox-archosrecorder-f9dce96.zip" },
|
||||
{ "iaudiox5", PlayerBuildInfo::BuildVersion, PlayerBuildInfo::TypeCandidate, "f9dce96" },
|
||||
{ "iaudiox5", PlayerBuildInfo::BuildUrl, PlayerBuildInfo::TypeCandidate, "http://dl.rockbox.org/rc/f9dce96/rockbox-iaudiox5.zip" },
|
||||
{ "iaudiox5.v", PlayerBuildInfo::BuildVersion, PlayerBuildInfo::TypeCandidate, "f9dce96" },
|
||||
{ "iaudiox5.v", PlayerBuildInfo::BuildUrl, PlayerBuildInfo::TypeCandidate, "http://dl.rockbox.org/rc/f9dce96/rockbox-iaudiox5.zip" },
|
||||
|
||||
// devel builds
|
||||
{ "iriverh100", PlayerBuildInfo::BuildUrl, PlayerBuildInfo::TypeDevel, "https://buildurl/dev/rockbox-iriverh100.zip" },
|
||||
{ "iaudiox5.v", PlayerBuildInfo::BuildVersion, PlayerBuildInfo::TypeDevel, "be1be76" },
|
||||
{ "iaudiox5.v", PlayerBuildInfo::BuildUrl, PlayerBuildInfo::TypeDevel, "https://buildurl/dev/rockbox-iaudiox5.zip" },
|
||||
|
||||
// daily builds
|
||||
{ "iriverh100", PlayerBuildInfo::BuildVoiceLangs, PlayerBuildInfo::TypeDaily, "deutsch,english,francais" },
|
||||
{ "iriverh100", PlayerBuildInfo::BuildVersion, PlayerBuildInfo::TypeDaily, "f9dce00" },
|
||||
{ "iriverh100", PlayerBuildInfo::BuildUrl, PlayerBuildInfo::TypeDaily, "https://buildurl/daily/rockbox-iriverh100-f9dce00.zip" },
|
||||
};
|
||||
|
||||
struct {
|
||||
QString target;
|
||||
PlayerBuildInfo::DeviceInfo item;
|
||||
QString expected;
|
||||
} testdataPlayer[] =
|
||||
{
|
||||
{ "archosfmrecorder", PlayerBuildInfo::BuildStatus, "3" },
|
||||
{ "iriverh10", PlayerBuildInfo::BuildStatus, "0" },
|
||||
{ "iriverh100", PlayerBuildInfo::BuildStatus, "2" },
|
||||
{ "iriverh300", PlayerBuildInfo::BuildStatus, "1" },
|
||||
{ "archosfmrecorder", PlayerBuildInfo::BuildStatus, "3" },
|
||||
{ "archosfmrecorder", PlayerBuildInfo::DisplayName, "Jukebox Recorder FM"},
|
||||
{ "archosfmrecorder", PlayerBuildInfo::BootloaderMethod, "none" },
|
||||
{ "archosfmrecorder", PlayerBuildInfo::BootloaderName, "" },
|
||||
{ "archosfmrecorder", PlayerBuildInfo::BootloaderFile, "" },
|
||||
{ "archosfmrecorder", PlayerBuildInfo::BootloaderFilter, "" },
|
||||
{ "archosfmrecorder", PlayerBuildInfo::Encoder, "lame" },
|
||||
{ "archosfmrecorder", PlayerBuildInfo::Brand, "Archos" },
|
||||
{ "archosfmrecorder", PlayerBuildInfo::PlayerPicture, "archosfmrecorder"},
|
||||
{ "iriverh100", PlayerBuildInfo::BuildStatus, "2" },
|
||||
{ "iriverh100", PlayerBuildInfo::BootloaderMethod, "hex" },
|
||||
{ "iriverh100", PlayerBuildInfo::BootloaderFilter, "*.hex *.zip" },
|
||||
{ "ipodmini2g", PlayerBuildInfo::Encoder, "rbspeex" },
|
||||
{ "078174b1", PlayerBuildInfo::DisplayName, "Sansa View" },
|
||||
{ "de", PlayerBuildInfo::LanguageInfo, "deutsch,Deutsch" },
|
||||
{ "en_US", PlayerBuildInfo::LanguageInfo, "english-us,English (US)" },
|
||||
};
|
||||
|
||||
void TestPlayerBuildInfo::testBuildInfo_data()
|
||||
{
|
||||
QTest::addColumn<QString>("target");
|
||||
QTest::addColumn<PlayerBuildInfo::BuildInfo>("item");
|
||||
QTest::addColumn<PlayerBuildInfo::BuildType>("type");
|
||||
QTest::addColumn<QString>("expected");
|
||||
for (size_t i = 0; i < sizeof(testdataBuild) / sizeof(testdataBuild[0]); i++)
|
||||
QTest::newRow("") << testdataBuild[i].target << testdataBuild[i].item
|
||||
<< testdataBuild[i].type << testdataBuild[i].expected;
|
||||
}
|
||||
|
||||
|
||||
void TestPlayerBuildInfo::testBuildInfo()
|
||||
{
|
||||
// create a temporary file for test input. Do not use QSettings() to allow
|
||||
// creating different format variations.
|
||||
QTemporaryFile tf(this);
|
||||
tf.open();
|
||||
QString filename = tf.fileName();
|
||||
tf.write(testinfo);
|
||||
tf.close();
|
||||
|
||||
PlayerBuildInfo::instance()->setBuildInfo(filename);
|
||||
|
||||
QFETCH(QString, target);
|
||||
QFETCH(PlayerBuildInfo::BuildInfo, item);
|
||||
QFETCH(PlayerBuildInfo::BuildType, type);
|
||||
QFETCH(QString, expected);
|
||||
|
||||
RbSettings::setValue(RbSettings::CurrentPlatform, target);
|
||||
QVariant result = PlayerBuildInfo::instance()->value(item, type);
|
||||
if(result.canConvert(QMetaType::QString))
|
||||
QCOMPARE(result.toString(), QString(expected));
|
||||
else
|
||||
QCOMPARE(result.toStringList().join(","), QString(expected));
|
||||
}
|
||||
|
||||
|
||||
// NOTE: These tests rely on rbutil.ini
|
||||
void TestPlayerBuildInfo::testPlayerInfo_data()
|
||||
{
|
||||
QTest::addColumn<QString>("target");
|
||||
QTest::addColumn<PlayerBuildInfo::DeviceInfo>("item");
|
||||
QTest::addColumn<QString>("expected");
|
||||
for (size_t i = 0; i < sizeof(testdataPlayer) / sizeof(testdataPlayer[0]); i++)
|
||||
QTest::newRow("") << testdataPlayer[i].target << testdataPlayer[i].item
|
||||
<< testdataPlayer[i].expected;
|
||||
}
|
||||
|
||||
void TestPlayerBuildInfo::testPlayerInfo()
|
||||
{
|
||||
// create a temporary file for test input. Do not use QSettings() to allow
|
||||
// creating different format variations.
|
||||
QTemporaryFile tf(this);
|
||||
tf.open();
|
||||
QString filename = tf.fileName();
|
||||
tf.write(testinfo);
|
||||
tf.close();
|
||||
|
||||
PlayerBuildInfo::instance()->setBuildInfo(filename);
|
||||
|
||||
QFETCH(QString, target);
|
||||
QFETCH(PlayerBuildInfo::DeviceInfo, item);
|
||||
QFETCH(QString, expected);
|
||||
|
||||
QVariant result = PlayerBuildInfo::instance()->value(item, target);
|
||||
if(result.canConvert(QMetaType::QString))
|
||||
QCOMPARE(result.toString(), QString(expected));
|
||||
else
|
||||
QCOMPARE(result.toStringList().join(","), QString(expected));
|
||||
}
|
||||
|
||||
|
||||
QTEST_MAIN(TestPlayerBuildInfo)
|
||||
|
||||
// this include is needed because we don't use a separate header file for the
|
||||
// test class. It also needs to be at the end.
|
||||
#include "test-playerbuildinfo.moc"
|
||||
|
||||
35
utils/rbutilqt/test/test-playerbuildinfo.pro
Normal file
35
utils/rbutilqt/test/test-playerbuildinfo.pro
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
#
|
||||
# __________ __ ___.
|
||||
# Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
||||
# Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
||||
# Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
||||
# Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
||||
# \/ \/ \/ \/ \/
|
||||
#
|
||||
# All files in this archive are subject to the GNU General Public License.
|
||||
# See the file COPYING in the source tree root for full license agreement.
|
||||
#
|
||||
# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
# KIND, either express or implied.
|
||||
#
|
||||
|
||||
#
|
||||
|
||||
QT += testlib
|
||||
|
||||
TEMPLATE = app
|
||||
TARGET = test-playerbuildinfo
|
||||
INCLUDEPATH += . ../base stubs
|
||||
|
||||
# Input
|
||||
SOURCES += \
|
||||
test-playerbuildinfo.cpp \
|
||||
stubs/stubs-playerbuildinfo.cpp \
|
||||
../base/playerbuildinfo.cpp
|
||||
|
||||
HEADERS += \
|
||||
../base/rbsettings.h \
|
||||
../base/rockboxinfo.h \
|
||||
../base/systeminfo.h \
|
||||
|
||||
RESOURCES += ../rbutilqt.qrc
|
||||
187
utils/rbutilqt/test/test-rockboxinfo.cpp
Normal file
187
utils/rbutilqt/test/test-rockboxinfo.cpp
Normal file
|
|
@ -0,0 +1,187 @@
|
|||
/***************************************************************************
|
||||
* __________ __ ___.
|
||||
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
||||
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
||||
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
||||
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
||||
* \/ \/ \/ \/ \/
|
||||
*
|
||||
* Copyright (C) 2012 Dominik Riebeling
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
* KIND, either express or implied.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#include <QtTest/QtTest>
|
||||
#include <QObject>
|
||||
#include "rockboxinfo.h"
|
||||
|
||||
|
||||
class TestRockboxInfo : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
private slots:
|
||||
void testVersion();
|
||||
void testVersion_data();
|
||||
void testMemory();
|
||||
void testMemory_data();
|
||||
void testTarget();
|
||||
void testTarget_data();
|
||||
void testFeatures();
|
||||
void testFeatures_data();
|
||||
};
|
||||
|
||||
|
||||
void TestRockboxInfo::testVersion_data()
|
||||
{
|
||||
struct {
|
||||
const char* input;
|
||||
const char* revision;
|
||||
const char* version;
|
||||
const char* release;
|
||||
} const testdata[] =
|
||||
{
|
||||
/* Input string revision full version release version */
|
||||
{ "Version: r29629-110321", "29629", "r29629-110321", "" },
|
||||
{ "Version: r29629M-110321", "29629M", "r29629M-110321", "" },
|
||||
{ "Version: 3.10", "", "3.10", "3.10" },
|
||||
{ "Version:\t3.10", "", "3.10", "3.10" },
|
||||
{ "#Version: r29629-110321", "", "", "" },
|
||||
{ "Version: e5b1b0f-120218", "e5b1b0f", "e5b1b0f-120218", "" },
|
||||
{ "Version: e5b1b0fM-120218", "e5b1b0fM", "e5b1b0fM-120218", "" },
|
||||
{ "#Version: e5b1b0f-120218", "", "", "" },
|
||||
{ "Version: 3448f5b-120310", "3448f5b", "3448f5b-120310", "" },
|
||||
};
|
||||
|
||||
|
||||
QTest::addColumn<QString>("input");
|
||||
QTest::addColumn<QString>("revision");
|
||||
QTest::addColumn<QString>("version");
|
||||
QTest::addColumn<QString>("release");
|
||||
unsigned int i;
|
||||
for(i = 0; i < sizeof(testdata) / sizeof(testdata[0]); i++) {
|
||||
for (size_t i = 0; i < sizeof(testdata) / sizeof(testdata[0]); i++) {
|
||||
QTest::newRow(testdata[i].input)
|
||||
<< testdata[i].input << testdata[i].revision
|
||||
<< testdata[i].version << testdata[i].release;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void TestRockboxInfo::testVersion()
|
||||
{
|
||||
QFETCH(QString, input);
|
||||
QFETCH(QString, revision);
|
||||
QFETCH(QString, version);
|
||||
QFETCH(QString, release);
|
||||
QTemporaryFile tf(this);
|
||||
tf.open();
|
||||
QString filename = tf.fileName();
|
||||
tf.write(input.toLatin1());
|
||||
tf.write("\n");
|
||||
tf.close();
|
||||
|
||||
RockboxInfo info("", filename);
|
||||
QCOMPARE(info.version(), QString(version));
|
||||
QCOMPARE(info.revision(), QString(revision));
|
||||
QCOMPARE(info.release(), QString(release));
|
||||
}
|
||||
|
||||
void TestRockboxInfo::testTarget_data()
|
||||
{
|
||||
QTest::addColumn<QString>("target");
|
||||
QTest::newRow("sansae200") << "sansae200";
|
||||
QTest::newRow("gigabeats") << "gigabeats";
|
||||
QTest::newRow("iriverh100") << "iriverh100";
|
||||
QTest::newRow("unknown") << "unknown";
|
||||
}
|
||||
|
||||
void TestRockboxInfo::testTarget()
|
||||
{
|
||||
int j;
|
||||
QStringList prefix;
|
||||
prefix << "Target: "; // << "Target:\t" << "Target: ";
|
||||
for(j = 0; j < prefix.size(); ++j) {
|
||||
QFETCH(QString, target);
|
||||
QTemporaryFile tf(this);
|
||||
tf.open();
|
||||
QString filename = tf.fileName();
|
||||
tf.write(prefix.at(j).toLatin1());
|
||||
tf.write(target.toLatin1());
|
||||
tf.write("\n");
|
||||
tf.close();
|
||||
|
||||
RockboxInfo info("", filename);
|
||||
QCOMPARE(info.target(), target);
|
||||
}
|
||||
}
|
||||
|
||||
void TestRockboxInfo::testMemory_data()
|
||||
{
|
||||
QTest::addColumn<QString>("memory");
|
||||
QTest::newRow("8") << "8";
|
||||
QTest::newRow("16") << "16";
|
||||
QTest::newRow("32") << "32";
|
||||
QTest::newRow("64") << "64";
|
||||
}
|
||||
|
||||
void TestRockboxInfo::testMemory()
|
||||
{
|
||||
int j;
|
||||
QStringList prefix;
|
||||
prefix << "Memory: " << "Memory:\t" << "Memory: ";
|
||||
for(j = 0; j < prefix.size(); ++j) {
|
||||
QFETCH(QString, memory);
|
||||
QTemporaryFile tf(this);
|
||||
tf.open();
|
||||
QString filename = tf.fileName();
|
||||
tf.write(prefix.at(j).toLatin1());
|
||||
tf.write(memory.toLatin1());
|
||||
tf.write("\n");
|
||||
tf.close();
|
||||
|
||||
RockboxInfo info("", filename);
|
||||
QCOMPARE(info.ram(), memory.toInt());
|
||||
}
|
||||
}
|
||||
|
||||
void TestRockboxInfo::testFeatures_data()
|
||||
{
|
||||
QTest::addColumn<QString>("features");
|
||||
QTest::newRow("1") << "backlight_brightness:button_light:dircache:flash_storage";
|
||||
QTest::newRow("2") << "pitchscreen:multivolume:multidrive_usb:quickscreen";
|
||||
}
|
||||
|
||||
void TestRockboxInfo::testFeatures()
|
||||
{
|
||||
int j;
|
||||
QStringList prefix;
|
||||
prefix << "Features: " << "Features:\t" << "Features: ";
|
||||
for(j = 0; j < prefix.size(); ++j) {
|
||||
QFETCH(QString, features);
|
||||
QTemporaryFile tf(this);
|
||||
tf.open();
|
||||
QString filename = tf.fileName();
|
||||
tf.write(prefix.at(j).toLatin1());
|
||||
tf.write(features.toLatin1());
|
||||
tf.write("\n");
|
||||
tf.close();
|
||||
|
||||
RockboxInfo info("", filename);
|
||||
QCOMPARE(info.features(), features);
|
||||
}
|
||||
}
|
||||
|
||||
QTEST_MAIN(TestRockboxInfo)
|
||||
|
||||
// this include is needed because we don't use a separate header file for the
|
||||
// test class. It also needs to be at the end.
|
||||
#include "test-rockboxinfo.moc"
|
||||
|
||||
30
utils/rbutilqt/test/test-rockboxinfo.pro
Normal file
30
utils/rbutilqt/test/test-rockboxinfo.pro
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
#
|
||||
# __________ __ ___.
|
||||
# Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
||||
# Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
||||
# Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
||||
# Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
||||
# \/ \/ \/ \/ \/
|
||||
#
|
||||
# All files in this archive are subject to the GNU General Public License.
|
||||
# See the file COPYING in the source tree root for full license agreement.
|
||||
#
|
||||
# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
# KIND, either express or implied.
|
||||
#
|
||||
|
||||
#
|
||||
QT += testlib
|
||||
|
||||
TEMPLATE = app
|
||||
TARGET = test-rockboxinfo
|
||||
INCLUDEPATH += . ../base stubs
|
||||
|
||||
# Input
|
||||
SOURCES += \
|
||||
test-rockboxinfo.cpp \
|
||||
../base/rockboxinfo.cpp
|
||||
|
||||
HEADERS += \
|
||||
../base/rockboxinfo.h
|
||||
|
||||
24
utils/rbutilqt/test/tests.pri
Normal file
24
utils/rbutilqt/test/tests.pri
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
#
|
||||
# __________ __ ___.
|
||||
# Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
||||
# Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
||||
# Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
||||
# Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
||||
# \/ \/ \/ \/ \/
|
||||
#
|
||||
# All files in this archive are subject to the GNU General Public License.
|
||||
# See the file COPYING in the source tree root for full license agreement.
|
||||
#
|
||||
# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
# KIND, either express or implied.
|
||||
#
|
||||
|
||||
# common settings for tests.
|
||||
|
||||
CONFIG += qtestlib
|
||||
DEPENDPATH += .
|
||||
OBJECTS_DIR = build/$$TARGET
|
||||
UI_DIR = build/$$TARGET
|
||||
MOC_DIR = build/$$TARGET
|
||||
RCC_DIR = build/$$TARGET
|
||||
QT -= gui
|
||||
Loading…
Add table
Add a link
Reference in a new issue