diff options
Diffstat (limited to 'utils/rbutilqt/test')
-rw-r--r-- | utils/rbutilqt/test/stubs/Logger.h | 11 | ||||
-rw-r--r-- | utils/rbutilqt/test/stubs/stubs-compareversion.cpp | 31 | ||||
-rw-r--r-- | utils/rbutilqt/test/stubs/stubs-playerbuildinfo.cpp | 36 | ||||
-rw-r--r-- | utils/rbutilqt/test/test-compareversion.cpp | 145 | ||||
-rw-r--r-- | utils/rbutilqt/test/test-compareversion.pro | 37 | ||||
-rw-r--r-- | utils/rbutilqt/test/test-httpget.cpp | 547 | ||||
-rw-r--r-- | utils/rbutilqt/test/test-httpget.pro | 31 | ||||
-rw-r--r-- | utils/rbutilqt/test/test-playerbuildinfo.cpp | 240 | ||||
-rw-r--r-- | utils/rbutilqt/test/test-playerbuildinfo.pro | 35 | ||||
-rw-r--r-- | utils/rbutilqt/test/test-rockboxinfo.cpp | 187 | ||||
-rw-r--r-- | utils/rbutilqt/test/test-rockboxinfo.pro | 30 | ||||
-rw-r--r-- | utils/rbutilqt/test/tests.pri | 24 |
12 files changed, 1354 insertions, 0 deletions
diff --git a/utils/rbutilqt/test/stubs/Logger.h b/utils/rbutilqt/test/stubs/Logger.h new file mode 100644 index 0000000000..6640646b24 --- /dev/null +++ b/utils/rbutilqt/test/stubs/Logger.h | |||
@@ -0,0 +1,11 @@ | |||
1 | #ifndef LOGGER_H | ||
2 | #define LOGGER_H | ||
3 | |||
4 | #include <QtDebug> | ||
5 | |||
6 | #define LOG_INFO qDebug | ||
7 | #define LOG_WARNING qWarning | ||
8 | #define LOG_ERROR qCritical | ||
9 | |||
10 | #endif | ||
11 | |||
diff --git a/utils/rbutilqt/test/stubs/stubs-compareversion.cpp b/utils/rbutilqt/test/stubs/stubs-compareversion.cpp new file mode 100644 index 0000000000..07e2d18f19 --- /dev/null +++ b/utils/rbutilqt/test/stubs/stubs-compareversion.cpp | |||
@@ -0,0 +1,31 @@ | |||
1 | |||
2 | #include "playerbuildinfo.h" | ||
3 | #include "rbsettings.h" | ||
4 | #include "rockboxinfo.h" | ||
5 | |||
6 | // not used by the test, just to make things compile. | ||
7 | QVariant RbSettings::value(RbSettings::UserSettings setting) | ||
8 | { | ||
9 | (void)setting; | ||
10 | return QVariant(); | ||
11 | } | ||
12 | |||
13 | |||
14 | // not used in the test. If used the test will crash! | ||
15 | PlayerBuildInfo* PlayerBuildInfo::instance() | ||
16 | { | ||
17 | return nullptr; | ||
18 | } | ||
19 | |||
20 | QVariant PlayerBuildInfo::value(PlayerBuildInfo::DeviceInfo item, QString target) | ||
21 | { | ||
22 | (void)item; | ||
23 | (void)target; | ||
24 | return QVariant(); | ||
25 | } | ||
26 | |||
27 | RockboxInfo::RockboxInfo(QString, QString) | ||
28 | { | ||
29 | } | ||
30 | |||
31 | |||
diff --git a/utils/rbutilqt/test/stubs/stubs-playerbuildinfo.cpp b/utils/rbutilqt/test/stubs/stubs-playerbuildinfo.cpp new file mode 100644 index 0000000000..8856645e89 --- /dev/null +++ b/utils/rbutilqt/test/stubs/stubs-playerbuildinfo.cpp | |||
@@ -0,0 +1,36 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * | ||
9 | * Copyright (C) 2020 Dominik Riebeling | ||
10 | * | ||
11 | * This program is free software; you can redistribute it and/or | ||
12 | * modify it under the terms of the GNU General Public License | ||
13 | * as published by the Free Software Foundation; either version 2 | ||
14 | * of the License, or (at your option) any later version. | ||
15 | * | ||
16 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
17 | * KIND, either express or implied. | ||
18 | * | ||
19 | ****************************************************************************/ | ||
20 | |||
21 | // Stubs for PlayerBuildInfo unit test. | ||
22 | |||
23 | #include "rbsettings.h" | ||
24 | |||
25 | static QMap<RbSettings::UserSettings, QVariant> stubUserSettings; | ||
26 | |||
27 | void RbSettings::setValue(UserSettings setting, QVariant value) | ||
28 | { | ||
29 | stubUserSettings[setting] = value; | ||
30 | } | ||
31 | |||
32 | QVariant RbSettings::value(UserSettings setting) | ||
33 | { | ||
34 | return stubUserSettings[setting]; | ||
35 | } | ||
36 | |||
diff --git a/utils/rbutilqt/test/test-compareversion.cpp b/utils/rbutilqt/test/test-compareversion.cpp new file mode 100644 index 0000000000..94d7697646 --- /dev/null +++ b/utils/rbutilqt/test/test-compareversion.cpp | |||
@@ -0,0 +1,145 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * | ||
9 | * Copyright (C) 2010 Dominik Riebeling | ||
10 | * | ||
11 | * This program is free software; you can redistribute it and/or | ||
12 | * modify it under the terms of the GNU General Public License | ||
13 | * as published by the Free Software Foundation; either version 2 | ||
14 | * of the License, or (at your option) any later version. | ||
15 | * | ||
16 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
17 | * KIND, either express or implied. | ||
18 | * | ||
19 | ****************************************************************************/ | ||
20 | |||
21 | #include <QtTest/QtTest> | ||
22 | #include <QObject> | ||
23 | #include "utils.h" | ||
24 | |||
25 | |||
26 | class TestVersionCompare : public QObject | ||
27 | { | ||
28 | Q_OBJECT | ||
29 | private slots: | ||
30 | void testCompare(); | ||
31 | void testCompare_data(); | ||
32 | void testTrim(); | ||
33 | void testTrim_data(); | ||
34 | }; | ||
35 | |||
36 | |||
37 | struct { | ||
38 | const char* first; | ||
39 | const char* second; | ||
40 | const int expected; | ||
41 | } const compdata[] = | ||
42 | { | ||
43 | { "1.2.3", "1.2.3 ", 0 }, | ||
44 | { "1.2.3", " 1.2.3", 0 }, | ||
45 | { "1.2.3", "1.2.4", 1 }, | ||
46 | { "1.2.3", "1.3.0", 1 }, | ||
47 | { "1.2.3", "2.0.0", 1 }, | ||
48 | { "10.22.33", "10.22.33", 0 }, | ||
49 | { "10.22.33", "10.23.0", 1 }, | ||
50 | { "10.22.33", "11.0.0", 1 }, | ||
51 | { "1.2.3", "1.2.3.1", 1 }, | ||
52 | { "1.2.3", "1.2.3-1", 1 }, | ||
53 | { "1.2.3-1", "1.2.3.1", 1 }, | ||
54 | { "1.2.3-10", "1.2.3.0", 1 }, | ||
55 | { "1.2.3-1", "1.2.3.10", 1 }, | ||
56 | { "1.2.3-1", "1.2.3a", 1 }, | ||
57 | { "1.2.3", "1.2.3a", 1 }, | ||
58 | { "1.2.3a", "1.2.3b", 1 }, | ||
59 | { "1.2.3", "1.2.3b", 1 }, | ||
60 | { "1.2.3.0", "2.0.0", 1 }, | ||
61 | { "1.2.3b", "2.0.0", 1 }, | ||
62 | { "1.2.3", "2.0.0.1", 1 }, | ||
63 | { "test-1.2.3", "test-1.2.3.tar.gz", 0 }, | ||
64 | { "1.2.3", "test-1.2.3.tar.bz2", 0 }, | ||
65 | { "test-1.2.3.tar.gz", "test-1.2.3.tar.bz2", 0 }, | ||
66 | { "test-1.2.3.tar.gz", "program-1.2.3.1.tar.bz2", 1 }, | ||
67 | { "program-1.2.3.zip", "program-1.2.3a.zip", 1 }, | ||
68 | { "program-1.2.3.tar.bz2", "2.0.0", 1 }, | ||
69 | { "prog-1.2-64bit.tar.bz2", "prog-1.2.3.tar.bz2", 1 }, | ||
70 | { "prog-1.2-64bit.tar.bz2", "prog-1.2-64bit.tar.bz2", 0 }, | ||
71 | { "prog-1.2-64bit.tar.bz2", "prog-1.2.3-64bit.tar.bz2", 1 }, | ||
72 | { "prog-1.2a-64bit.tar.bz2","prog-1.2b-64bit.tar.bz2", 1 }, | ||
73 | { "prog-1.2-64bit.tar.bz2", "prog-1.2.3a-64bit.tar.bz2", 1 }, | ||
74 | { "prog-1.2a-64bit.tar.bz2","prog-1.2.3-64bit.tar.bz2", 1 }, | ||
75 | }; | ||
76 | |||
77 | struct { | ||
78 | const char* input; | ||
79 | const QString expected; | ||
80 | } const trimdata[] = | ||
81 | { | ||
82 | { "prog-1.2-64bit.tar.bz2", "1.2" }, | ||
83 | { "prog-1.2.tar.bz2", "1.2" }, | ||
84 | { "1.2.3", "1.2.3" }, | ||
85 | { " 1.2.3", "1.2.3" }, | ||
86 | { "1.2.3 ", "1.2.3" }, | ||
87 | { "10.22.33", "10.22.33" }, | ||
88 | { "test-1.2.3", "1.2.3" }, | ||
89 | { "1.2.3", "1.2.3" }, | ||
90 | { "test-1.2.3.tar.gz", "1.2.3" }, | ||
91 | { "prog-1.2-64bit.tar.bz2", "1.2" }, | ||
92 | { "prog-1.2a.tar.bz2", "1.2a" }, | ||
93 | { "prog-1.2a-64bit.tar.bz2","1.2a" }, | ||
94 | }; | ||
95 | |||
96 | |||
97 | void TestVersionCompare::testCompare_data() | ||
98 | { | ||
99 | QTest::addColumn<QString>("first"); | ||
100 | QTest::addColumn<QString>("second"); | ||
101 | QTest::addColumn<int>("expected"); | ||
102 | for(size_t i = 0; i < sizeof(compdata) / sizeof(compdata[0]); i++) { | ||
103 | QTest::newRow("") << compdata[i].first << compdata[i].second << compdata[i].expected; | ||
104 | } | ||
105 | } | ||
106 | |||
107 | |||
108 | void TestVersionCompare::testCompare() | ||
109 | { | ||
110 | QFETCH(QString, first); | ||
111 | QFETCH(QString, second); | ||
112 | QFETCH(int, expected); | ||
113 | |||
114 | QCOMPARE(Utils::compareVersionStrings(first, second), expected); | ||
115 | if(expected != 0) { | ||
116 | QCOMPARE(Utils::compareVersionStrings(second, first), -expected); | ||
117 | } | ||
118 | } | ||
119 | |||
120 | |||
121 | void TestVersionCompare::testTrim_data() | ||
122 | { | ||
123 | QTest::addColumn<QString>("input"); | ||
124 | QTest::addColumn<QString>("expected"); | ||
125 | for(size_t i = 0; i < sizeof(trimdata) / sizeof(trimdata[0]); i++) { | ||
126 | QTest::newRow("") << trimdata[i].input << trimdata[i].expected; | ||
127 | } | ||
128 | } | ||
129 | |||
130 | |||
131 | void TestVersionCompare::testTrim() | ||
132 | { | ||
133 | QFETCH(QString, input); | ||
134 | QFETCH(QString, expected); | ||
135 | |||
136 | QCOMPARE(Utils::trimVersionString(input), expected); | ||
137 | } | ||
138 | |||
139 | |||
140 | QTEST_MAIN(TestVersionCompare) | ||
141 | |||
142 | // this include is needed because we don't use a separate header file for the | ||
143 | // test class. It also needs to be at the end. | ||
144 | #include "test-compareversion.moc" | ||
145 | |||
diff --git a/utils/rbutilqt/test/test-compareversion.pro b/utils/rbutilqt/test/test-compareversion.pro new file mode 100644 index 0000000000..c8e5a899ac --- /dev/null +++ b/utils/rbutilqt/test/test-compareversion.pro | |||
@@ -0,0 +1,37 @@ | |||
1 | # | ||
2 | # __________ __ ___. | ||
3 | # Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | # Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | # Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | # Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | # \/ \/ \/ \/ \/ | ||
8 | # $Id$ | ||
9 | # | ||
10 | # All files in this archive are subject to the GNU General Public License. | ||
11 | # See the file COPYING in the source tree root for full license agreement. | ||
12 | # | ||
13 | # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
14 | # KIND, either express or implied. | ||
15 | # | ||
16 | |||
17 | # Test: Utils::compareVersionStrings(). | ||
18 | # | ||
19 | |||
20 | QT += testlib | ||
21 | |||
22 | TEMPLATE = app | ||
23 | TARGET = test-compareversion | ||
24 | INCLUDEPATH += . ../base stubs | ||
25 | |||
26 | # Input | ||
27 | SOURCES += \ | ||
28 | test-compareversion.cpp \ | ||
29 | stubs/stubs-compareversion.cpp \ | ||
30 | ../base/utils.cpp | ||
31 | |||
32 | HEADERS += \ | ||
33 | ../base/rbsettings.h \ | ||
34 | ../base/playerbuildinfo.h \ | ||
35 | ../base/rockboxinfo.h \ | ||
36 | ../base/utils.h | ||
37 | |||
diff --git a/utils/rbutilqt/test/test-httpget.cpp b/utils/rbutilqt/test/test-httpget.cpp new file mode 100644 index 0000000000..144adc62df --- /dev/null +++ b/utils/rbutilqt/test/test-httpget.cpp | |||
@@ -0,0 +1,547 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * | ||
9 | * Copyright (C) 2013 Dominik Riebeling | ||
10 | * | ||
11 | * This program is free software; you can redistribute it and/or | ||
12 | * modify it under the terms of the GNU General Public License | ||
13 | * as published by the Free Software Foundation; either version 2 | ||
14 | * of the License, or (at your option) any later version. | ||
15 | * | ||
16 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
17 | * KIND, either express or implied. | ||
18 | * | ||
19 | ****************************************************************************/ | ||
20 | |||
21 | #include <QtTest/QtTest> | ||
22 | #include <QtCore/QObject> | ||
23 | #include "httpget.h" | ||
24 | |||
25 | #define TEST_USER_AGENT "TestAgent/2.3" | ||
26 | #define TEST_HTTP_TIMEOUT 1000 | ||
27 | #define TEST_BINARY_BLOB "\x01\x10\x20\x30\x40\x50\x60\x70" \ | ||
28 | "\x80\x90\xff\xee\xdd\xcc\xbb\xaa" | ||
29 | |||
30 | // HttpDaemon is the the class that implements the simple HTTP server. | ||
31 | class HttpDaemon : public QTcpServer | ||
32 | { | ||
33 | Q_OBJECT | ||
34 | public: | ||
35 | HttpDaemon(quint16 port = 0, QObject* parent = 0) : QTcpServer(parent) | ||
36 | { | ||
37 | listen(QHostAddress::Any, port); | ||
38 | } | ||
39 | |||
40 | quint16 port(void) { return this->serverPort(); } | ||
41 | |||
42 | #if QT_VERSION < 0x050000 | ||
43 | void incomingConnection(int socket) | ||
44 | #else | ||
45 | // Qt 5 uses a different prototype for this function! | ||
46 | void incomingConnection(qintptr socket) | ||
47 | #endif | ||
48 | { | ||
49 | // When a new client connects, the server constructs a QTcpSocket and all | ||
50 | // communication with the client is done over this QTcpSocket. QTcpSocket | ||
51 | // works asynchronously, this means that all the communication is done | ||
52 | // in the two slots readClient() and discardClient(). | ||
53 | QTcpSocket* s = new QTcpSocket(this); | ||
54 | connect(s, SIGNAL(readyRead()), this, SLOT(readClient())); | ||
55 | connect(s, SIGNAL(disconnected()), this, SLOT(discardClient())); | ||
56 | s->setSocketDescriptor(socket); | ||
57 | } | ||
58 | QList<QString> lastRequestData(void) | ||
59 | { | ||
60 | return m_lastRequestData; | ||
61 | } | ||
62 | void setResponsesToSend(QList<QByteArray> response) | ||
63 | { | ||
64 | m_requestNumber = 0; | ||
65 | m_responsesToSend = response; | ||
66 | } | ||
67 | void reset(void) | ||
68 | { | ||
69 | m_requestNumber = 0; | ||
70 | m_lastRequestData.clear(); | ||
71 | QString now = | ||
72 | QDateTime::currentDateTime().toString("ddd, d MMM yyyy hh:mm:ss"); | ||
73 | m_defaultResponse = QByteArray( | ||
74 | "HTTP/1.1 404 Not Found\r\n" | ||
75 | "Date: " + now.toLatin1() + "\r\n" | ||
76 | "Last-Modified: " + now.toLatin1() + "\r\n" | ||
77 | "Connection: close\r\n" | ||
78 | "\r\n"); | ||
79 | } | ||
80 | |||
81 | private slots: | ||
82 | void readClient() | ||
83 | { | ||
84 | // This slot is called when the client sent data to the server. | ||
85 | QTcpSocket* socket = (QTcpSocket*)sender(); | ||
86 | // read whole request | ||
87 | QString request; | ||
88 | while(socket->canReadLine()) { | ||
89 | QString line = socket->readLine(); | ||
90 | request.append(line); | ||
91 | if(request.endsWith("\r\n\r\n")) { | ||
92 | m_lastRequestData.append(request); | ||
93 | |||
94 | if(m_requestNumber < m_responsesToSend.size()) | ||
95 | socket->write(m_responsesToSend.at(m_requestNumber)); | ||
96 | else | ||
97 | socket->write(m_defaultResponse); | ||
98 | socket->close(); | ||
99 | m_requestNumber++; | ||
100 | } | ||
101 | if (socket->state() == QTcpSocket::UnconnectedState) | ||
102 | delete socket; | ||
103 | } | ||
104 | } | ||
105 | void discardClient() | ||
106 | { | ||
107 | QTcpSocket* socket = (QTcpSocket*)sender(); | ||
108 | socket->deleteLater(); | ||
109 | } | ||
110 | |||
111 | private: | ||
112 | int m_requestNumber; | ||
113 | QList<QByteArray> m_responsesToSend; | ||
114 | QList<QString> m_lastRequestData; | ||
115 | QByteArray m_defaultResponse; | ||
116 | }; | ||
117 | |||
118 | |||
119 | class TestHttpGet : public QObject | ||
120 | { | ||
121 | Q_OBJECT | ||
122 | private slots: | ||
123 | void testFileUrlRequest(void); | ||
124 | void testCachedRequest(void); | ||
125 | void testUncachedRepeatedRequest(void); | ||
126 | void testUncachedMovedRequest(void); | ||
127 | void testUserAgent(void); | ||
128 | void testResponseCode(void); | ||
129 | void testContentToBuffer(void); | ||
130 | void testContentToFile(void); | ||
131 | void testNoServer(void); | ||
132 | void testServerTimestamp(void); | ||
133 | void testMovedQuery(void); | ||
134 | void init(void); | ||
135 | void cleanup(void); | ||
136 | |||
137 | public slots: | ||
138 | void waitTimeout(void) | ||
139 | { | ||
140 | m_waitTimeoutOccured = true; | ||
141 | } | ||
142 | QDir temporaryFolder(void) | ||
143 | { | ||
144 | // Qt unfortunately doesn't support creating temporary folders so | ||
145 | // we need to do that ourselves. | ||
146 | QString tempdir; | ||
147 | for(int i = 0; i < 100000; i++) { | ||
148 | tempdir = QDir::tempPath() + QString("/qttest-temp-%1").arg(i); | ||
149 | if(!QFileInfo(tempdir).exists()) break; | ||
150 | } | ||
151 | QDir().mkpath(tempdir); | ||
152 | return QDir(tempdir); | ||
153 | } | ||
154 | void rmTree(QString folder) | ||
155 | { | ||
156 | // no function in Qt to recursively delete a folder :( | ||
157 | QDir dir(folder); | ||
158 | Q_FOREACH(QFileInfo info, dir.entryInfoList(QDir::NoDotAndDotDot | ||
159 | | QDir::System | QDir::Hidden | QDir::AllDirs | ||
160 | | QDir::Files, QDir::DirsFirst)) { | ||
161 | if(info.isDir()) rmTree(info.absoluteFilePath()); | ||
162 | else QFile::remove(info.absoluteFilePath()); | ||
163 | } | ||
164 | dir.rmdir(folder); | ||
165 | } | ||
166 | private: | ||
167 | HttpDaemon *m_daemon; | ||
168 | QByteArray m_port; | ||
169 | bool m_waitTimeoutOccured; | ||
170 | QString m_now; | ||
171 | QDir m_cachedir; | ||
172 | HttpGet *m_getter; | ||
173 | QSignalSpy *m_doneSpy; | ||
174 | QSignalSpy *m_progressSpy; | ||
175 | }; | ||
176 | |||
177 | |||
178 | void TestHttpGet::init(void) | ||
179 | { | ||
180 | m_now = QDateTime::currentDateTime().toString("ddd, d MMM yyyy hh:mm:ss"); | ||
181 | m_daemon = new HttpDaemon(0, this); // use port 0 to auto-pick | ||
182 | m_daemon->reset(); | ||
183 | m_port = QString("%1").arg(m_daemon->port()).toLatin1(); | ||
184 | m_cachedir = temporaryFolder(); | ||
185 | m_getter = new HttpGet(this); | ||
186 | m_doneSpy = new QSignalSpy(m_getter, SIGNAL(done(bool))); | ||
187 | m_progressSpy = new QSignalSpy(m_getter, SIGNAL(dataReadProgress(int, int))); | ||
188 | m_waitTimeoutOccured = false; | ||
189 | } | ||
190 | |||
191 | void TestHttpGet::cleanup(void) | ||
192 | { | ||
193 | rmTree(m_cachedir.absolutePath()); | ||
194 | if(m_getter) { | ||
195 | m_getter->abort(); delete m_getter; m_getter = NULL; | ||
196 | } | ||
197 | if(m_daemon) { delete m_daemon; m_daemon = NULL; } | ||
198 | if(m_doneSpy) { delete m_doneSpy; m_doneSpy = NULL; } | ||
199 | if(m_progressSpy) { delete m_progressSpy; m_progressSpy = NULL; } | ||
200 | } | ||
201 | |||
202 | void TestHttpGet::testFileUrlRequest(void) | ||
203 | { | ||
204 | QTimer::singleShot(TEST_HTTP_TIMEOUT, this, SLOT(waitTimeout(void))); | ||
205 | |||
206 | QString teststring = "The quick brown fox jumps over the lazy dog."; | ||
207 | QTemporaryFile datafile; | ||
208 | datafile.open(); | ||
209 | datafile.write(teststring.toLatin1()); | ||
210 | m_getter->getFile(QUrl::fromLocalFile(datafile.fileName())); | ||
211 | datafile.close(); | ||
212 | while(m_doneSpy->count() == 0 && m_waitTimeoutOccured == false) | ||
213 | QCoreApplication::processEvents(); | ||
214 | |||
215 | QCOMPARE(m_doneSpy->count(), 1); | ||
216 | QCOMPARE(m_waitTimeoutOccured, false); | ||
217 | QCOMPARE(m_daemon->lastRequestData().size(), 0); | ||
218 | QCOMPARE(m_getter->readAll(), teststring.toLatin1()); | ||
219 | QCOMPARE(m_getter->httpResponse(), 200); | ||
220 | QCOMPARE(m_progressSpy->at(0).at(0).toInt(), 0); | ||
221 | } | ||
222 | |||
223 | |||
224 | /* On uncached requests, HttpGet is supposed to sent a GET request only. | ||
225 | */ | ||
226 | void TestHttpGet::testUncachedRepeatedRequest(void) | ||
227 | { | ||
228 | QList<QByteArray> responses; | ||
229 | responses << QByteArray( | ||
230 | "HTTP/1.1 200 OK\r\n" | ||
231 | "Date: " + m_now.toLatin1() + "\r\n" | ||
232 | "Last-Modified: " + m_now.toLatin1() + "\r\n" | ||
233 | "\r\n\r\n"); | ||
234 | responses << QByteArray( | ||
235 | "HTTP/1.1 200 OK\r\n" | ||
236 | "Last-Modified: " + m_now.toLatin1() + "\r\n" | ||
237 | "Date: " + m_now.toLatin1() + "\r\n" | ||
238 | "\r\n" | ||
239 | "<html></html>\r\n\r\n"); | ||
240 | m_daemon->setResponsesToSend(responses); | ||
241 | |||
242 | QTimer::singleShot(TEST_HTTP_TIMEOUT, this, SLOT(waitTimeout(void))); | ||
243 | |||
244 | m_getter->getFile(QUrl("http://localhost:" + m_port + "/test1.txt")); | ||
245 | while(m_doneSpy->count() == 0 && m_waitTimeoutOccured == false) | ||
246 | QCoreApplication::processEvents(); | ||
247 | |||
248 | QCOMPARE(m_doneSpy->count(), 1); | ||
249 | QCOMPARE(m_waitTimeoutOccured, false); | ||
250 | QCOMPARE(m_daemon->lastRequestData().size(), 1); | ||
251 | QCOMPARE(m_daemon->lastRequestData().at(0).startsWith("GET"), true); | ||
252 | |||
253 | // request second time | ||
254 | m_getter->getFile(QUrl("http://localhost:" + m_port + "/test1.txt")); | ||
255 | while(m_doneSpy->count() < 2 && m_waitTimeoutOccured == false) | ||
256 | QCoreApplication::processEvents(); | ||
257 | QCOMPARE(m_doneSpy->count(), 2); | ||
258 | QCOMPARE(m_waitTimeoutOccured, false); | ||
259 | QCOMPARE(m_daemon->lastRequestData().size(), 2); | ||
260 | QCOMPARE(m_daemon->lastRequestData().at(1).startsWith("GET"), true); | ||
261 | QCOMPARE(m_getter->httpResponse(), 200); | ||
262 | } | ||
263 | |||
264 | /* With enabled cache HttpGet is supposed to check the server file using a HEAD | ||
265 | * request first, then request the file using GET if the server file is newer | ||
266 | * than the cached one (or the file does not exist in the cache) | ||
267 | */ | ||
268 | void TestHttpGet::testCachedRequest(void) | ||
269 | { | ||
270 | QList<QByteArray> responses; | ||
271 | responses << QByteArray( | ||
272 | "HTTP/1.1 302 Found\r\n" | ||
273 | "Location: http://localhost:" + m_port + "/test2.txt\r\n" | ||
274 | "Date: " + m_now.toLatin1() + "\r\n" | ||
275 | "Last-Modified: " + m_now.toLatin1() + "\r\n" | ||
276 | "\r\n"); | ||
277 | responses << QByteArray( | ||
278 | "HTTP/1.1 200 OK\r\n" | ||
279 | "Last-Modified: " + m_now.toLatin1() + "\r\n" | ||
280 | "Date: " + m_now.toLatin1() + "\r\n" | ||
281 | "\r\n" | ||
282 | "<html></html>\r\n\r\n"); | ||
283 | responses << QByteArray( | ||
284 | "HTTP/1.1 200 OK\r\n" | ||
285 | "Last-Modified: 1 Jan 2000 00:00:00\r\n" | ||
286 | "Date: " + m_now.toLatin1() + "\r\n" | ||
287 | "\r\n"); | ||
288 | m_daemon->setResponsesToSend(responses); | ||
289 | |||
290 | QTimer::singleShot(TEST_HTTP_TIMEOUT, this, SLOT(waitTimeout(void))); | ||
291 | |||
292 | m_getter->setCache(m_cachedir); | ||
293 | m_getter->getFile(QUrl("http://localhost:" + m_port + "/test1.txt")); | ||
294 | while(m_doneSpy->count() == 0 && m_waitTimeoutOccured == false) | ||
295 | QCoreApplication::processEvents(); | ||
296 | |||
297 | QList<QString> requests = m_daemon->lastRequestData(); | ||
298 | QCOMPARE(m_doneSpy->count(), 1); | ||
299 | QCOMPARE(m_doneSpy->at(0).at(0).toBool(), false); | ||
300 | QCOMPARE(m_waitTimeoutOccured, false); | ||
301 | QCOMPARE(requests.size(), 2); | ||
302 | QCOMPARE(requests.at(0).startsWith("GET"), true); | ||
303 | QCOMPARE(requests.at(1).startsWith("GET"), true); | ||
304 | QCOMPARE(m_getter->httpResponse(), 200); | ||
305 | |||
306 | // request real file, this time the response should come from cache. | ||
307 | m_getter->getFile(QUrl("http://localhost:" + m_port + "/test2.txt")); | ||
308 | while(m_doneSpy->count() < 2 && m_waitTimeoutOccured == false) | ||
309 | QCoreApplication::processEvents(); | ||
310 | QCOMPARE(m_doneSpy->count(), 2); // 2 requests, 2 times done() | ||
311 | QCOMPARE(m_doneSpy->at(1).at(0).toBool(), false); | ||
312 | QCOMPARE(m_waitTimeoutOccured, false); | ||
313 | QCOMPARE(m_daemon->lastRequestData().size(), 3); | ||
314 | // redirect will not cache as the redirection target file. | ||
315 | QCOMPARE(m_daemon->lastRequestData().at(2).startsWith("GET"), true); | ||
316 | QCOMPARE(m_getter->httpResponse(), 200); | ||
317 | } | ||
318 | |||
319 | /* When a custom user agent is set all requests are supposed to contain it. | ||
320 | * Enable cache to make HttpGet performs a HEAD request. Answer with 302, so | ||
321 | * HttpGet follows and sends another HEAD request before finally doing a GET. | ||
322 | */ | ||
323 | void TestHttpGet::testUserAgent(void) | ||
324 | { | ||
325 | QList<QByteArray> responses; | ||
326 | responses << QByteArray( | ||
327 | "HTTP/1.1 200 OK\r\n" | ||
328 | "Date: " + m_now.toLatin1() + "\r\n" | ||
329 | "Last-Modified: " + m_now.toLatin1() + "\r\n" | ||
330 | "\r\n\r\n"); | ||
331 | responses << QByteArray( | ||
332 | "HTTP/1.1 200 OK\r\n" | ||
333 | "Last-Modified: " + m_now.toLatin1() + "\r\n" | ||
334 | "Date: " + m_now.toLatin1() + "\r\n" | ||
335 | "\r\n" | ||
336 | "<html></html>\r\n\r\n"); | ||
337 | m_daemon->setResponsesToSend(responses); | ||
338 | |||
339 | QTimer::singleShot(TEST_HTTP_TIMEOUT, this, SLOT(waitTimeout(void))); | ||
340 | |||
341 | m_getter->setGlobalUserAgent(TEST_USER_AGENT); | ||
342 | m_getter->setCache(m_cachedir); | ||
343 | m_getter->getFile(QUrl("http://localhost:" + m_port + "/test1.txt")); | ||
344 | while(m_doneSpy->count() == 0 && m_waitTimeoutOccured == false) | ||
345 | QCoreApplication::processEvents(); | ||
346 | |||
347 | QList<QString> requests = m_daemon->lastRequestData(); | ||
348 | QCOMPARE(m_doneSpy->count(), 1); | ||
349 | QCOMPARE(m_waitTimeoutOccured, false); | ||
350 | QCOMPARE(requests.size(), 1); | ||
351 | QCOMPARE(requests.at(0).startsWith("GET"), true); | ||
352 | |||
353 | for(int i = 0; i < requests.size(); ++i) { | ||
354 | QRegExp rx("User-Agent:[\t ]+([a-zA-Z0-9\\./]+)"); | ||
355 | bool userAgentFound = rx.indexIn(requests.at(i)) > 0 ? true : false; | ||
356 | QCOMPARE(userAgentFound, true); | ||
357 | QString userAgentString = rx.cap(1); | ||
358 | QCOMPARE(userAgentString, QString(TEST_USER_AGENT)); | ||
359 | } | ||
360 | } | ||
361 | |||
362 | void TestHttpGet::testUncachedMovedRequest(void) | ||
363 | { | ||
364 | QList<QByteArray> responses; | ||
365 | responses << QByteArray( | ||
366 | "HTTP/1.1 302 Found\r\n" | ||
367 | "Location: http://localhost:" + m_port + "/test2.txt\r\n" | ||
368 | "Date: " + m_now.toLatin1() + "\r\n" | ||
369 | "Last-Modified: " + m_now.toLatin1() + "\r\n" | ||
370 | "\r\n"); | ||
371 | responses << QByteArray( | ||
372 | "HTTP/1.1 200 OK\r\n" | ||
373 | "Last-Modified: " + m_now.toLatin1() + "\r\n" | ||
374 | "Date: " + m_now.toLatin1() + "\r\n" | ||
375 | "\r\n" | ||
376 | "<html></html>\r\n\r\n"); | ||
377 | m_daemon->setResponsesToSend(responses); | ||
378 | |||
379 | QTimer::singleShot(TEST_HTTP_TIMEOUT, this, SLOT(waitTimeout(void))); | ||
380 | |||
381 | m_getter->getFile(QUrl("http://localhost:" + m_port + "/test1.php?var=1&b=foo")); | ||
382 | while(m_doneSpy->count() == 0 && m_waitTimeoutOccured == false) | ||
383 | QCoreApplication::processEvents(); | ||
384 | |||
385 | QCOMPARE(m_doneSpy->count(), 1); | ||
386 | QCOMPARE(m_waitTimeoutOccured, false); | ||
387 | QCOMPARE(m_daemon->lastRequestData().size(), 2); | ||
388 | QCOMPARE(m_daemon->lastRequestData().at(0).startsWith("GET"), true); | ||
389 | QCOMPARE(m_daemon->lastRequestData().at(1).startsWith("GET"), true); | ||
390 | } | ||
391 | |||
392 | void TestHttpGet::testResponseCode(void) | ||
393 | { | ||
394 | QTimer::singleShot(TEST_HTTP_TIMEOUT, this, SLOT(waitTimeout(void))); | ||
395 | |||
396 | m_getter->getFile(QUrl("http://localhost:" + m_port + "/test1.txt")); | ||
397 | while(m_doneSpy->count() == 0 && m_waitTimeoutOccured == false) | ||
398 | QCoreApplication::processEvents(); | ||
399 | |||
400 | QCOMPARE(m_doneSpy->count(), 1); | ||
401 | QCOMPARE(m_doneSpy->at(0).at(0).toBool(), true); | ||
402 | QCOMPARE(m_waitTimeoutOccured, false); | ||
403 | QCOMPARE(m_daemon->lastRequestData().size(), 1); | ||
404 | QCOMPARE(m_daemon->lastRequestData().at(0).startsWith("GET"), true); | ||
405 | QCOMPARE(m_getter->httpResponse(), 404); | ||
406 | } | ||
407 | |||
408 | void TestHttpGet::testContentToBuffer(void) | ||
409 | { | ||
410 | QList<QByteArray> responses; | ||
411 | responses << QByteArray( | ||
412 | "HTTP/1.1 200 OK\r\n" | ||
413 | "Last-Modified: " + m_now.toLatin1() + "\r\n" | ||
414 | "Date: " + m_now.toLatin1() + "\r\n" | ||
415 | "\r\n" | ||
416 | TEST_BINARY_BLOB); | ||
417 | m_daemon->setResponsesToSend(responses); | ||
418 | |||
419 | QTimer::singleShot(TEST_HTTP_TIMEOUT, this, SLOT(waitTimeout(void))); | ||
420 | |||
421 | m_getter->getFile(QUrl("http://localhost:" + m_port + "/test1.txt")); | ||
422 | while(m_doneSpy->count() == 0 && m_waitTimeoutOccured == false) | ||
423 | QCoreApplication::processEvents(); | ||
424 | |||
425 | QCOMPARE(m_doneSpy->count(), 1); | ||
426 | QCOMPARE(m_waitTimeoutOccured, false); | ||
427 | QCOMPARE(m_getter->readAll(), QByteArray(TEST_BINARY_BLOB)); | ||
428 | // sizeof(TEST_BINARY_BLOB) will include an additional terminating NULL. | ||
429 | QCOMPARE(m_getter->readAll().size(), (int)sizeof(TEST_BINARY_BLOB) - 1); | ||
430 | QCOMPARE(m_progressSpy->at(m_progressSpy->count() - 1).at(0).toInt(), (int)sizeof(TEST_BINARY_BLOB) - 1); | ||
431 | QCOMPARE(m_progressSpy->at(m_progressSpy->count() - 1).at(1).toInt(), (int)sizeof(TEST_BINARY_BLOB) - 1); | ||
432 | } | ||
433 | |||
434 | void TestHttpGet::testContentToFile(void) | ||
435 | { | ||
436 | QTemporaryFile tf(this); | ||
437 | QList<QByteArray> responses; | ||
438 | responses << QByteArray( | ||
439 | "HTTP/1.1 200 OK\r\n" | ||
440 | "Last-Modified: " + m_now.toLatin1() + "\r\n" | ||
441 | "Date: " + m_now.toLatin1() + "\r\n" | ||
442 | "\r\n" | ||
443 | TEST_BINARY_BLOB); | ||
444 | m_daemon->setResponsesToSend(responses); | ||
445 | |||
446 | QTimer::singleShot(TEST_HTTP_TIMEOUT, this, SLOT(waitTimeout(void))); | ||
447 | |||
448 | m_getter->setFile(&tf); | ||
449 | m_getter->getFile(QUrl("http://localhost:" + m_port + "/test1.txt")); | ||
450 | while(m_doneSpy->count() == 0 && m_waitTimeoutOccured == false) | ||
451 | QCoreApplication::processEvents(); | ||
452 | |||
453 | QCOMPARE(m_doneSpy->count(), 1); | ||
454 | QCOMPARE(m_waitTimeoutOccured, false); | ||
455 | |||
456 | tf.open(); | ||
457 | QByteArray data = tf.readAll(); | ||
458 | QCOMPARE(data, QByteArray(TEST_BINARY_BLOB)); | ||
459 | QCOMPARE((unsigned long)data.size(), sizeof(TEST_BINARY_BLOB) - 1); | ||
460 | tf.close(); | ||
461 | } | ||
462 | |||
463 | void TestHttpGet::testNoServer(void) | ||
464 | { | ||
465 | QTimer::singleShot(TEST_HTTP_TIMEOUT, this, SLOT(waitTimeout(void))); | ||
466 | m_getter->getFile(QUrl("http://localhost:53/test1.txt")); | ||
467 | while(m_doneSpy->count() == 0 && m_waitTimeoutOccured == false) | ||
468 | QCoreApplication::processEvents(); | ||
469 | |||
470 | QCOMPARE(m_doneSpy->count(), 1); | ||
471 | QCOMPARE(m_doneSpy->at(0).at(0).toBool(), true); | ||
472 | QCOMPARE(m_waitTimeoutOccured, false); | ||
473 | } | ||
474 | |||
475 | void TestHttpGet::testServerTimestamp(void) | ||
476 | { | ||
477 | QList<QByteArray> responses; | ||
478 | responses << QByteArray( | ||
479 | "HTTP/1.1 200 OK\r\n" | ||
480 | "Last-Modified: Wed, 20 Jan 2010 10:20:30\r\n" // RFC 822 | ||
481 | "Date: Wed, 20 Jan 2010 10:20:30\r\n" | ||
482 | "\r\n" | ||
483 | "\r\n"); | ||
484 | responses << QByteArray( | ||
485 | "HTTP/1.1 200 OK\r\n" | ||
486 | "Last-Modified: Sat Feb 19 09:08:07 2011\r\n" // asctime | ||
487 | "Date: Sat Feb 19 09:08:07 2011\r\n" | ||
488 | "\r\n" | ||
489 | "\r\n"); | ||
490 | |||
491 | QList<QDateTime> times; | ||
492 | times << QDateTime::fromString("2010-01-20T11:20:30", Qt::ISODate); | ||
493 | times << QDateTime::fromString("2011-02-19T10:08:07", Qt::ISODate); | ||
494 | |||
495 | m_daemon->setResponsesToSend(responses); | ||
496 | |||
497 | QTimer::singleShot(TEST_HTTP_TIMEOUT, this, SLOT(waitTimeout(void))); | ||
498 | |||
499 | int count = m_doneSpy->count(); | ||
500 | for(int i = 0; i < responses.size(); ++i) { | ||
501 | m_getter->getFile(QUrl("http://localhost:" + m_port + "/test1.txt")); | ||
502 | while(m_doneSpy->count() == count && m_waitTimeoutOccured == false) | ||
503 | QCoreApplication::processEvents(); | ||
504 | count = m_doneSpy->count(); | ||
505 | QCOMPARE(m_getter->timestamp(), times.at(i)); | ||
506 | } | ||
507 | } | ||
508 | |||
509 | void TestHttpGet::testMovedQuery(void) | ||
510 | { | ||
511 | QList<QByteArray> responses; | ||
512 | responses << QByteArray( | ||
513 | "HTTP/1.1 302 Found\r\n" | ||
514 | "Location: http://localhost:" + m_port + "/test2.php\r\n" | ||
515 | "Date: " + m_now.toLatin1() + "\r\n" | ||
516 | "Last-Modified: " + m_now.toLatin1() + "\r\n" | ||
517 | "\r\n"); | ||
518 | responses << QByteArray( | ||
519 | "HTTP/1.1 200 OK\r\n" | ||
520 | "Last-Modified: " + m_now.toLatin1() + "\r\n" | ||
521 | "Date: " + m_now.toLatin1() + "\r\n" | ||
522 | "\r\n" | ||
523 | "<html></html>\r\n\r\n"); | ||
524 | m_daemon->setResponsesToSend(responses); | ||
525 | |||
526 | QTimer::singleShot(TEST_HTTP_TIMEOUT, this, SLOT(waitTimeout(void))); | ||
527 | |||
528 | m_getter->getFile(QUrl("http://localhost:" + m_port + "/test1.php?var=1&b=foo")); | ||
529 | while(m_doneSpy->count() == 0 && m_waitTimeoutOccured == false) | ||
530 | QCoreApplication::processEvents(); | ||
531 | |||
532 | QCOMPARE(m_doneSpy->count(), 1); | ||
533 | QCOMPARE(m_waitTimeoutOccured, false); | ||
534 | QCOMPARE(m_getter->httpResponse(), 200); | ||
535 | QCOMPARE(m_daemon->lastRequestData().size(), 2); | ||
536 | QCOMPARE(m_daemon->lastRequestData().at(0).startsWith("GET"), true); | ||
537 | QCOMPARE(m_daemon->lastRequestData().at(1).startsWith("GET"), true); | ||
538 | // current implementation keeps order of query items. | ||
539 | QCOMPARE((bool)m_daemon->lastRequestData().at(1).contains("/test2.php?var=1&b=foo"), true); | ||
540 | } | ||
541 | |||
542 | QTEST_MAIN(TestHttpGet) | ||
543 | |||
544 | // this include is needed because we don't use a separate header file for the | ||
545 | // test class. It also needs to be at the end. | ||
546 | #include "test-httpget.moc" | ||
547 | |||
diff --git a/utils/rbutilqt/test/test-httpget.pro b/utils/rbutilqt/test/test-httpget.pro new file mode 100644 index 0000000000..3189ad2266 --- /dev/null +++ b/utils/rbutilqt/test/test-httpget.pro | |||
@@ -0,0 +1,31 @@ | |||
1 | # | ||
2 | # __________ __ ___. | ||
3 | # Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | # Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | # Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | # Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | # \/ \/ \/ \/ \/ | ||
8 | # | ||
9 | # All files in this archive are subject to the GNU General Public License. | ||
10 | # See the file COPYING in the source tree root for full license agreement. | ||
11 | # | ||
12 | # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
13 | # KIND, either express or implied. | ||
14 | # | ||
15 | |||
16 | # | ||
17 | include(tests.pri) | ||
18 | |||
19 | TEMPLATE = app | ||
20 | TARGET = test-httpget | ||
21 | INCLUDEPATH += . ../base stubs | ||
22 | QT += network | ||
23 | |||
24 | # Input | ||
25 | SOURCES += \ | ||
26 | test-httpget.cpp | ||
27 | |||
28 | SOURCES += ../base/httpget.cpp | ||
29 | |||
30 | HEADERS += ../base/httpget.h | ||
31 | |||
diff --git a/utils/rbutilqt/test/test-playerbuildinfo.cpp b/utils/rbutilqt/test/test-playerbuildinfo.cpp new file mode 100644 index 0000000000..a250e37979 --- /dev/null +++ b/utils/rbutilqt/test/test-playerbuildinfo.cpp | |||
@@ -0,0 +1,240 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * | ||
9 | * Copyright (C) 2020 Dominik Riebeling | ||
10 | * | ||
11 | * This program is free software; you can redistribute it and/or | ||
12 | * modify it under the terms of the GNU General Public License | ||
13 | * as published by the Free Software Foundation; either version 2 | ||
14 | * of the License, or (at your option) any later version. | ||
15 | * | ||
16 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
17 | * KIND, either express or implied. | ||
18 | * | ||
19 | ****************************************************************************/ | ||
20 | |||
21 | #include <QtTest> | ||
22 | #include <QObject> | ||
23 | #include "playerbuildinfo.h" | ||
24 | #include "rbsettings.h" | ||
25 | |||
26 | class TestPlayerBuildInfo : public QObject | ||
27 | { | ||
28 | Q_OBJECT | ||
29 | |||
30 | private slots: | ||
31 | void testBuildInfo(); | ||
32 | void testBuildInfo_data(); | ||
33 | void testPlayerInfo(); | ||
34 | void testPlayerInfo_data(); | ||
35 | }; | ||
36 | |||
37 | const char* testinfo = | ||
38 | "[release]\n" | ||
39 | "build_url=https://buildurl/release/%VERSION%/rockbox-%TARGET%-%VERSION%.zip\n" | ||
40 | "voice_url=https://buildurl/release/%VERSION%/voice-%TARGET%-%VERSION%.zip\n" | ||
41 | "manual_url=https://buildurl/release/%VERSION%/manual-%TARGET%-%VERSION%.zip\n" | ||
42 | "source_url=https://buildurl/release/%VERSION%/rockbox-%TARGET%-src-%VERSION%.zip\n" | ||
43 | "font_url=https://buildurl/release/%VERSION%/fonts-%VERSION%.zip\n" | ||
44 | "archosfmrecorder=3.11.2\n" | ||
45 | "iaudiom3=3.11.2,http://dl.rockbox.org/release/3.11.2/rockbox-iaudiom5-3.11.2.zip\n" | ||
46 | "sansae200 = 3.15\n" | ||
47 | "iriverh100 = 3.11.2, http://dl.rockbox.org/release/3.11.2/rockbox-iriverh100-3.11.2.zip\n" | ||
48 | "iriverh120 = 3.3\n" | ||
49 | "iriverh300 = \n" | ||
50 | "[release-candidate]\n" | ||
51 | "build_url=https://buildurl/rc/%VERSION%/rockbox-%TARGET%-%VERSION%.zip\n" | ||
52 | "gigabeatfx=f9dce96,http://dl.rockbox.org/rc/f9dce96/rockbox-gigabeatfx.zip\n" | ||
53 | "archosfmrecorder=f9dce96\n" | ||
54 | "archosrecorder = f9dce96\n" | ||
55 | "iaudiox5=f9dce96,http://dl.rockbox.org/rc/f9dce96/rockbox-iaudiox5.zip\n" | ||
56 | "[development]\n" | ||
57 | "build_url=https://buildurl/dev/rockbox-%TARGET%.zip\n" | ||
58 | "iriverh100 = be1be79\n" | ||
59 | "iaudiox5 = be1be76\n" | ||
60 | "[dailies]\n" | ||
61 | "timestamp = 20201113\n" | ||
62 | "rev = 362f7a3\n" | ||
63 | "[daily]\n" | ||
64 | "build_url=https://buildurl/daily/rockbox-%TARGET%-%VERSION%.zip\n" | ||
65 | "iriverh100 = f9dce00\n" | ||
66 | "[bleeding]\n" | ||
67 | "timestamp = 20201114T105723Z\n" | ||
68 | "rev = be1be79\n" | ||
69 | "[status]\n" | ||
70 | "archosfmrecorder=3\n" | ||
71 | "iriverh100=2\n" | ||
72 | "iriverh300=1\n" | ||
73 | "iriverh10=0\n" | ||
74 | "[voices]\n" | ||
75 | "3.15=english,francais\n" | ||
76 | "3.11.2=english\n" | ||
77 | "daily=deutsch,english,francais\n" | ||
78 | ; | ||
79 | |||
80 | Q_DECLARE_METATYPE(PlayerBuildInfo::BuildInfo); | ||
81 | Q_DECLARE_METATYPE(PlayerBuildInfo::BuildType); | ||
82 | Q_DECLARE_METATYPE(PlayerBuildInfo::DeviceInfo); | ||
83 | |||
84 | struct { | ||
85 | QString target; | ||
86 | PlayerBuildInfo::BuildInfo item; | ||
87 | PlayerBuildInfo::BuildType type; | ||
88 | QString expected; | ||
89 | } testdataBuild[] = | ||
90 | { | ||
91 | // release builds | ||
92 | { "iriverh100", PlayerBuildInfo::BuildVoiceLangs, PlayerBuildInfo::TypeRelease, "english" }, | ||
93 | { "iriverh300", PlayerBuildInfo::BuildVersion, PlayerBuildInfo::TypeRelease, "" }, | ||
94 | { "iriverh300", PlayerBuildInfo::BuildUrl, PlayerBuildInfo::TypeRelease, "" }, | ||
95 | { "iriverh10", PlayerBuildInfo::BuildVersion, PlayerBuildInfo::TypeRelease, "" }, | ||
96 | { "iriverh10", PlayerBuildInfo::BuildUrl, PlayerBuildInfo::TypeRelease, "" }, | ||
97 | { "archosfmrecorder", PlayerBuildInfo::BuildVersion, PlayerBuildInfo::TypeRelease, "3.11.2" }, | ||
98 | { "iaudiom3", PlayerBuildInfo::BuildVersion, PlayerBuildInfo::TypeRelease, "3.11.2" }, | ||
99 | { "iaudiom3", PlayerBuildInfo::BuildUrl, PlayerBuildInfo::TypeRelease, "http://dl.rockbox.org/release/3.11.2/rockbox-iaudiom5-3.11.2.zip" }, | ||
100 | { "sansae200", PlayerBuildInfo::BuildVersion, PlayerBuildInfo::TypeRelease, "3.15" }, | ||
101 | { "sansae200", PlayerBuildInfo::BuildUrl, PlayerBuildInfo::TypeRelease, "https://buildurl/release/3.15/rockbox-sansae200-3.15.zip" }, | ||
102 | { "iriverh100", PlayerBuildInfo::BuildVersion, PlayerBuildInfo::TypeRelease, "3.11.2" }, | ||
103 | { "iriverh100", PlayerBuildInfo::BuildUrl, PlayerBuildInfo::TypeRelease, "http://dl.rockbox.org/release/3.11.2/rockbox-iriverh100-3.11.2.zip" }, | ||
104 | { "iriverh100", PlayerBuildInfo::BuildVoiceUrl, PlayerBuildInfo::TypeRelease, "https://buildurl/release/3.11.2/voice-iriverh100-3.11.2.zip" }, | ||
105 | { "iriverh100", PlayerBuildInfo::BuildManualUrl, PlayerBuildInfo::TypeRelease, "https://buildurl/release/3.11.2/manual-iriverh100-3.11.2.zip" }, | ||
106 | { "iriverh100", PlayerBuildInfo::BuildSourceUrl, PlayerBuildInfo::TypeRelease, "https://buildurl/release/3.11.2/rockbox-iriverh100-src-3.11.2.zip" }, | ||
107 | // h120 uses the same manual as h100. | ||
108 | { "iriverh120", PlayerBuildInfo::BuildManualUrl, PlayerBuildInfo::TypeRelease, "https://buildurl/release/3.3/manual-iriverh100-3.3.zip" }, | ||
109 | { "iriverh100", PlayerBuildInfo::BuildFontUrl, PlayerBuildInfo::TypeRelease, "https://buildurl/release/3.11.2/fonts-3.11.2.zip" }, | ||
110 | |||
111 | // rc builds | ||
112 | { "gigabeatfx", PlayerBuildInfo::BuildVersion, PlayerBuildInfo::TypeCandidate, "f9dce96" }, | ||
113 | { "gigabeatfx", PlayerBuildInfo::BuildUrl, PlayerBuildInfo::TypeCandidate, "http://dl.rockbox.org/rc/f9dce96/rockbox-gigabeatfx.zip" }, | ||
114 | { "archosfmrecorder", PlayerBuildInfo::BuildVersion, PlayerBuildInfo::TypeCandidate, "f9dce96" }, | ||
115 | { "archosfmrecorder", PlayerBuildInfo::BuildUrl, PlayerBuildInfo::TypeCandidate, "https://buildurl/rc/f9dce96/rockbox-archosfmrecorder-f9dce96.zip" }, | ||
116 | { "archosrecorder", PlayerBuildInfo::BuildVersion, PlayerBuildInfo::TypeCandidate, "f9dce96" }, | ||
117 | { "archosrecorder", PlayerBuildInfo::BuildUrl, PlayerBuildInfo::TypeCandidate, "https://buildurl/rc/f9dce96/rockbox-archosrecorder-f9dce96.zip" }, | ||
118 | { "iaudiox5", PlayerBuildInfo::BuildVersion, PlayerBuildInfo::TypeCandidate, "f9dce96" }, | ||
119 | { "iaudiox5", PlayerBuildInfo::BuildUrl, PlayerBuildInfo::TypeCandidate, "http://dl.rockbox.org/rc/f9dce96/rockbox-iaudiox5.zip" }, | ||
120 | { "iaudiox5.v", PlayerBuildInfo::BuildVersion, PlayerBuildInfo::TypeCandidate, "f9dce96" }, | ||
121 | { "iaudiox5.v", PlayerBuildInfo::BuildUrl, PlayerBuildInfo::TypeCandidate, "http://dl.rockbox.org/rc/f9dce96/rockbox-iaudiox5.zip" }, | ||
122 | |||
123 | // devel builds | ||
124 | { "iriverh100", PlayerBuildInfo::BuildUrl, PlayerBuildInfo::TypeDevel, "https://buildurl/dev/rockbox-iriverh100.zip" }, | ||
125 | { "iaudiox5.v", PlayerBuildInfo::BuildVersion, PlayerBuildInfo::TypeDevel, "be1be76" }, | ||
126 | { "iaudiox5.v", PlayerBuildInfo::BuildUrl, PlayerBuildInfo::TypeDevel, "https://buildurl/dev/rockbox-iaudiox5.zip" }, | ||
127 | |||
128 | // daily builds | ||
129 | { "iriverh100", PlayerBuildInfo::BuildVoiceLangs, PlayerBuildInfo::TypeDaily, "deutsch,english,francais" }, | ||
130 | { "iriverh100", PlayerBuildInfo::BuildVersion, PlayerBuildInfo::TypeDaily, "f9dce00" }, | ||
131 | { "iriverh100", PlayerBuildInfo::BuildUrl, PlayerBuildInfo::TypeDaily, "https://buildurl/daily/rockbox-iriverh100-f9dce00.zip" }, | ||
132 | }; | ||
133 | |||
134 | struct { | ||
135 | QString target; | ||
136 | PlayerBuildInfo::DeviceInfo item; | ||
137 | QString expected; | ||
138 | } testdataPlayer[] = | ||
139 | { | ||
140 | { "archosfmrecorder", PlayerBuildInfo::BuildStatus, "3" }, | ||
141 | { "iriverh10", PlayerBuildInfo::BuildStatus, "0" }, | ||
142 | { "iriverh100", PlayerBuildInfo::BuildStatus, "2" }, | ||
143 | { "iriverh300", PlayerBuildInfo::BuildStatus, "1" }, | ||
144 | { "archosfmrecorder", PlayerBuildInfo::BuildStatus, "3" }, | ||
145 | { "archosfmrecorder", PlayerBuildInfo::DisplayName, "Jukebox Recorder FM"}, | ||
146 | { "archosfmrecorder", PlayerBuildInfo::BootloaderMethod, "none" }, | ||
147 | { "archosfmrecorder", PlayerBuildInfo::BootloaderName, "" }, | ||
148 | { "archosfmrecorder", PlayerBuildInfo::BootloaderFile, "" }, | ||
149 | { "archosfmrecorder", PlayerBuildInfo::BootloaderFilter, "" }, | ||
150 | { "archosfmrecorder", PlayerBuildInfo::Encoder, "lame" }, | ||
151 | { "archosfmrecorder", PlayerBuildInfo::Brand, "Archos" }, | ||
152 | { "archosfmrecorder", PlayerBuildInfo::PlayerPicture, "archosfmrecorder"}, | ||
153 | { "iriverh100", PlayerBuildInfo::BuildStatus, "2" }, | ||
154 | { "iriverh100", PlayerBuildInfo::BootloaderMethod, "hex" }, | ||
155 | { "iriverh100", PlayerBuildInfo::BootloaderFilter, "*.hex *.zip" }, | ||
156 | { "ipodmini2g", PlayerBuildInfo::Encoder, "rbspeex" }, | ||
157 | { "078174b1", PlayerBuildInfo::DisplayName, "Sansa View" }, | ||
158 | { "de", PlayerBuildInfo::LanguageInfo, "deutsch,Deutsch" }, | ||
159 | { "en_US", PlayerBuildInfo::LanguageInfo, "english-us,English (US)" }, | ||
160 | }; | ||
161 | |||
162 | void TestPlayerBuildInfo::testBuildInfo_data() | ||
163 | { | ||
164 | QTest::addColumn<QString>("target"); | ||
165 | QTest::addColumn<PlayerBuildInfo::BuildInfo>("item"); | ||
166 | QTest::addColumn<PlayerBuildInfo::BuildType>("type"); | ||
167 | QTest::addColumn<QString>("expected"); | ||
168 | for (size_t i = 0; i < sizeof(testdataBuild) / sizeof(testdataBuild[0]); i++) | ||
169 | QTest::newRow("") << testdataBuild[i].target << testdataBuild[i].item | ||
170 | << testdataBuild[i].type << testdataBuild[i].expected; | ||
171 | } | ||
172 | |||
173 | |||
174 | void TestPlayerBuildInfo::testBuildInfo() | ||
175 | { | ||
176 | // create a temporary file for test input. Do not use QSettings() to allow | ||
177 | // creating different format variations. | ||
178 | QTemporaryFile tf(this); | ||
179 | tf.open(); | ||
180 | QString filename = tf.fileName(); | ||
181 | tf.write(testinfo); | ||
182 | tf.close(); | ||
183 | |||
184 | PlayerBuildInfo::instance()->setBuildInfo(filename); | ||
185 | |||
186 | QFETCH(QString, target); | ||
187 | QFETCH(PlayerBuildInfo::BuildInfo, item); | ||
188 | QFETCH(PlayerBuildInfo::BuildType, type); | ||
189 | QFETCH(QString, expected); | ||
190 | |||
191 | RbSettings::setValue(RbSettings::CurrentPlatform, target); | ||
192 | QVariant result = PlayerBuildInfo::instance()->value(item, type); | ||
193 | if(result.canConvert(QMetaType::QString)) | ||
194 | QCOMPARE(result.toString(), QString(expected)); | ||
195 | else | ||
196 | QCOMPARE(result.toStringList().join(","), QString(expected)); | ||
197 | } | ||
198 | |||
199 | |||
200 | // NOTE: These tests rely on rbutil.ini | ||
201 | void TestPlayerBuildInfo::testPlayerInfo_data() | ||
202 | { | ||
203 | QTest::addColumn<QString>("target"); | ||
204 | QTest::addColumn<PlayerBuildInfo::DeviceInfo>("item"); | ||
205 | QTest::addColumn<QString>("expected"); | ||
206 | for (size_t i = 0; i < sizeof(testdataPlayer) / sizeof(testdataPlayer[0]); i++) | ||
207 | QTest::newRow("") << testdataPlayer[i].target << testdataPlayer[i].item | ||
208 | << testdataPlayer[i].expected; | ||
209 | } | ||
210 | |||
211 | void TestPlayerBuildInfo::testPlayerInfo() | ||
212 | { | ||
213 | // create a temporary file for test input. Do not use QSettings() to allow | ||
214 | // creating different format variations. | ||
215 | QTemporaryFile tf(this); | ||
216 | tf.open(); | ||
217 | QString filename = tf.fileName(); | ||
218 | tf.write(testinfo); | ||
219 | tf.close(); | ||
220 | |||
221 | PlayerBuildInfo::instance()->setBuildInfo(filename); | ||
222 | |||
223 | QFETCH(QString, target); | ||
224 | QFETCH(PlayerBuildInfo::DeviceInfo, item); | ||
225 | QFETCH(QString, expected); | ||
226 | |||
227 | QVariant result = PlayerBuildInfo::instance()->value(item, target); | ||
228 | if(result.canConvert(QMetaType::QString)) | ||
229 | QCOMPARE(result.toString(), QString(expected)); | ||
230 | else | ||
231 | QCOMPARE(result.toStringList().join(","), QString(expected)); | ||
232 | } | ||
233 | |||
234 | |||
235 | QTEST_MAIN(TestPlayerBuildInfo) | ||
236 | |||
237 | // this include is needed because we don't use a separate header file for the | ||
238 | // test class. It also needs to be at the end. | ||
239 | #include "test-playerbuildinfo.moc" | ||
240 | |||
diff --git a/utils/rbutilqt/test/test-playerbuildinfo.pro b/utils/rbutilqt/test/test-playerbuildinfo.pro new file mode 100644 index 0000000000..724da59162 --- /dev/null +++ b/utils/rbutilqt/test/test-playerbuildinfo.pro | |||
@@ -0,0 +1,35 @@ | |||
1 | # | ||
2 | # __________ __ ___. | ||
3 | # Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | # Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | # Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | # Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | # \/ \/ \/ \/ \/ | ||
8 | # | ||
9 | # All files in this archive are subject to the GNU General Public License. | ||
10 | # See the file COPYING in the source tree root for full license agreement. | ||
11 | # | ||
12 | # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
13 | # KIND, either express or implied. | ||
14 | # | ||
15 | |||
16 | # | ||
17 | |||
18 | QT += testlib | ||
19 | |||
20 | TEMPLATE = app | ||
21 | TARGET = test-playerbuildinfo | ||
22 | INCLUDEPATH += . ../base stubs | ||
23 | |||
24 | # Input | ||
25 | SOURCES += \ | ||
26 | test-playerbuildinfo.cpp \ | ||
27 | stubs/stubs-playerbuildinfo.cpp \ | ||
28 | ../base/playerbuildinfo.cpp | ||
29 | |||
30 | HEADERS += \ | ||
31 | ../base/rbsettings.h \ | ||
32 | ../base/rockboxinfo.h \ | ||
33 | ../base/systeminfo.h \ | ||
34 | |||
35 | RESOURCES += ../rbutilqt.qrc | ||
diff --git a/utils/rbutilqt/test/test-rockboxinfo.cpp b/utils/rbutilqt/test/test-rockboxinfo.cpp new file mode 100644 index 0000000000..9d2b53b3ab --- /dev/null +++ b/utils/rbutilqt/test/test-rockboxinfo.cpp | |||
@@ -0,0 +1,187 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * | ||
9 | * Copyright (C) 2012 Dominik Riebeling | ||
10 | * | ||
11 | * This program is free software; you can redistribute it and/or | ||
12 | * modify it under the terms of the GNU General Public License | ||
13 | * as published by the Free Software Foundation; either version 2 | ||
14 | * of the License, or (at your option) any later version. | ||
15 | * | ||
16 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
17 | * KIND, either express or implied. | ||
18 | * | ||
19 | ****************************************************************************/ | ||
20 | |||
21 | #include <QtTest/QtTest> | ||
22 | #include <QObject> | ||
23 | #include "rockboxinfo.h" | ||
24 | |||
25 | |||
26 | class TestRockboxInfo : public QObject | ||
27 | { | ||
28 | Q_OBJECT | ||
29 | private slots: | ||
30 | void testVersion(); | ||
31 | void testVersion_data(); | ||
32 | void testMemory(); | ||
33 | void testMemory_data(); | ||
34 | void testTarget(); | ||
35 | void testTarget_data(); | ||
36 | void testFeatures(); | ||
37 | void testFeatures_data(); | ||
38 | }; | ||
39 | |||
40 | |||
41 | void TestRockboxInfo::testVersion_data() | ||
42 | { | ||
43 | struct { | ||
44 | const char* input; | ||
45 | const char* revision; | ||
46 | const char* version; | ||
47 | const char* release; | ||
48 | } const testdata[] = | ||
49 | { | ||
50 | /* Input string revision full version release version */ | ||
51 | { "Version: r29629-110321", "29629", "r29629-110321", "" }, | ||
52 | { "Version: r29629M-110321", "29629M", "r29629M-110321", "" }, | ||
53 | { "Version: 3.10", "", "3.10", "3.10" }, | ||
54 | { "Version:\t3.10", "", "3.10", "3.10" }, | ||
55 | { "#Version: r29629-110321", "", "", "" }, | ||
56 | { "Version: e5b1b0f-120218", "e5b1b0f", "e5b1b0f-120218", "" }, | ||
57 | { "Version: e5b1b0fM-120218", "e5b1b0fM", "e5b1b0fM-120218", "" }, | ||
58 | { "#Version: e5b1b0f-120218", "", "", "" }, | ||
59 | { "Version: 3448f5b-120310", "3448f5b", "3448f5b-120310", "" }, | ||
60 | }; | ||
61 | |||
62 | |||
63 | QTest::addColumn<QString>("input"); | ||
64 | QTest::addColumn<QString>("revision"); | ||
65 | QTest::addColumn<QString>("version"); | ||
66 | QTest::addColumn<QString>("release"); | ||
67 | unsigned int i; | ||
68 | for(i = 0; i < sizeof(testdata) / sizeof(testdata[0]); i++) { | ||
69 | for (size_t i = 0; i < sizeof(testdata) / sizeof(testdata[0]); i++) { | ||
70 | QTest::newRow(testdata[i].input) | ||
71 | << testdata[i].input << testdata[i].revision | ||
72 | << testdata[i].version << testdata[i].release; | ||
73 | } | ||
74 | } | ||
75 | } | ||
76 | |||
77 | |||
78 | void TestRockboxInfo::testVersion() | ||
79 | { | ||
80 | QFETCH(QString, input); | ||
81 | QFETCH(QString, revision); | ||
82 | QFETCH(QString, version); | ||
83 | QFETCH(QString, release); | ||
84 | QTemporaryFile tf(this); | ||
85 | tf.open(); | ||
86 | QString filename = tf.fileName(); | ||
87 | tf.write(input.toLatin1()); | ||
88 | tf.write("\n"); | ||
89 | tf.close(); | ||
90 | |||
91 | RockboxInfo info("", filename); | ||
92 | QCOMPARE(info.version(), QString(version)); | ||
93 | QCOMPARE(info.revision(), QString(revision)); | ||
94 | QCOMPARE(info.release(), QString(release)); | ||
95 | } | ||
96 | |||
97 | void TestRockboxInfo::testTarget_data() | ||
98 | { | ||
99 | QTest::addColumn<QString>("target"); | ||
100 | QTest::newRow("sansae200") << "sansae200"; | ||
101 | QTest::newRow("gigabeats") << "gigabeats"; | ||
102 | QTest::newRow("iriverh100") << "iriverh100"; | ||
103 | QTest::newRow("unknown") << "unknown"; | ||
104 | } | ||
105 | |||
106 | void TestRockboxInfo::testTarget() | ||
107 | { | ||
108 | int j; | ||
109 | QStringList prefix; | ||
110 | prefix << "Target: "; // << "Target:\t" << "Target: "; | ||
111 | for(j = 0; j < prefix.size(); ++j) { | ||
112 | QFETCH(QString, target); | ||
113 | QTemporaryFile tf(this); | ||
114 | tf.open(); | ||
115 | QString filename = tf.fileName(); | ||
116 | tf.write(prefix.at(j).toLatin1()); | ||
117 | tf.write(target.toLatin1()); | ||
118 | tf.write("\n"); | ||
119 | tf.close(); | ||
120 | |||
121 | RockboxInfo info("", filename); | ||
122 | QCOMPARE(info.target(), target); | ||
123 | } | ||
124 | } | ||
125 | |||
126 | void TestRockboxInfo::testMemory_data() | ||
127 | { | ||
128 | QTest::addColumn<QString>("memory"); | ||
129 | QTest::newRow("8") << "8"; | ||
130 | QTest::newRow("16") << "16"; | ||
131 | QTest::newRow("32") << "32"; | ||
132 | QTest::newRow("64") << "64"; | ||
133 | } | ||
134 | |||
135 | void TestRockboxInfo::testMemory() | ||
136 | { | ||
137 | int j; | ||
138 | QStringList prefix; | ||
139 | prefix << "Memory: " << "Memory:\t" << "Memory: "; | ||
140 | for(j = 0; j < prefix.size(); ++j) { | ||
141 | QFETCH(QString, memory); | ||
142 | QTemporaryFile tf(this); | ||
143 | tf.open(); | ||
144 | QString filename = tf.fileName(); | ||
145 | tf.write(prefix.at(j).toLatin1()); | ||
146 | tf.write(memory.toLatin1()); | ||
147 | tf.write("\n"); | ||
148 | tf.close(); | ||
149 | |||
150 | RockboxInfo info("", filename); | ||
151 | QCOMPARE(info.ram(), memory.toInt()); | ||
152 | } | ||
153 | } | ||
154 | |||
155 | void TestRockboxInfo::testFeatures_data() | ||
156 | { | ||
157 | QTest::addColumn<QString>("features"); | ||
158 | QTest::newRow("1") << "backlight_brightness:button_light:dircache:flash_storage"; | ||
159 | QTest::newRow("2") << "pitchscreen:multivolume:multidrive_usb:quickscreen"; | ||
160 | } | ||
161 | |||
162 | void TestRockboxInfo::testFeatures() | ||
163 | { | ||
164 | int j; | ||
165 | QStringList prefix; | ||
166 | prefix << "Features: " << "Features:\t" << "Features: "; | ||
167 | for(j = 0; j < prefix.size(); ++j) { | ||
168 | QFETCH(QString, features); | ||
169 | QTemporaryFile tf(this); | ||
170 | tf.open(); | ||
171 | QString filename = tf.fileName(); | ||
172 | tf.write(prefix.at(j).toLatin1()); | ||
173 | tf.write(features.toLatin1()); | ||
174 | tf.write("\n"); | ||
175 | tf.close(); | ||
176 | |||
177 | RockboxInfo info("", filename); | ||
178 | QCOMPARE(info.features(), features); | ||
179 | } | ||
180 | } | ||
181 | |||
182 | QTEST_MAIN(TestRockboxInfo) | ||
183 | |||
184 | // this include is needed because we don't use a separate header file for the | ||
185 | // test class. It also needs to be at the end. | ||
186 | #include "test-rockboxinfo.moc" | ||
187 | |||
diff --git a/utils/rbutilqt/test/test-rockboxinfo.pro b/utils/rbutilqt/test/test-rockboxinfo.pro new file mode 100644 index 0000000000..88bc83a5b7 --- /dev/null +++ b/utils/rbutilqt/test/test-rockboxinfo.pro | |||
@@ -0,0 +1,30 @@ | |||
1 | # | ||
2 | # __________ __ ___. | ||
3 | # Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | # Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | # Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | # Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | # \/ \/ \/ \/ \/ | ||
8 | # | ||
9 | # All files in this archive are subject to the GNU General Public License. | ||
10 | # See the file COPYING in the source tree root for full license agreement. | ||
11 | # | ||
12 | # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
13 | # KIND, either express or implied. | ||
14 | # | ||
15 | |||
16 | # | ||
17 | QT += testlib | ||
18 | |||
19 | TEMPLATE = app | ||
20 | TARGET = test-rockboxinfo | ||
21 | INCLUDEPATH += . ../base stubs | ||
22 | |||
23 | # Input | ||
24 | SOURCES += \ | ||
25 | test-rockboxinfo.cpp \ | ||
26 | ../base/rockboxinfo.cpp | ||
27 | |||
28 | HEADERS += \ | ||
29 | ../base/rockboxinfo.h | ||
30 | |||
diff --git a/utils/rbutilqt/test/tests.pri b/utils/rbutilqt/test/tests.pri new file mode 100644 index 0000000000..7dc6ffda7b --- /dev/null +++ b/utils/rbutilqt/test/tests.pri | |||
@@ -0,0 +1,24 @@ | |||
1 | # | ||
2 | # __________ __ ___. | ||
3 | # Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | # Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | # Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | # Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | # \/ \/ \/ \/ \/ | ||
8 | # | ||
9 | # All files in this archive are subject to the GNU General Public License. | ||
10 | # See the file COPYING in the source tree root for full license agreement. | ||
11 | # | ||
12 | # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
13 | # KIND, either express or implied. | ||
14 | # | ||
15 | |||
16 | # common settings for tests. | ||
17 | |||
18 | CONFIG += qtestlib | ||
19 | DEPENDPATH += . | ||
20 | OBJECTS_DIR = build/$$TARGET | ||
21 | UI_DIR = build/$$TARGET | ||
22 | MOC_DIR = build/$$TARGET | ||
23 | RCC_DIR = build/$$TARGET | ||
24 | QT -= gui | ||