summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDominik Riebeling <Dominik.Riebeling@gmail.com>2012-06-17 13:01:09 +0200
committerDominik Riebeling <Dominik.Riebeling@gmail.com>2012-06-17 13:01:09 +0200
commit14727b1ac362d9c0d7ca4f4225aab9193fce1569 (patch)
tree83bc6b81b0246abe291e934d0ed6bae03f9d1d71
parenta3d9ace41ecbdfe72486dd9ec4d0dabf5eec299c (diff)
downloadrockbox-14727b1ac362d9c0d7ca4f4225aab9193fce1569.zip
rockbox-14727b1ac362d9c0d7ca4f4225aab9193fce1569.tar.gz
rockbox-14727b1ac362d9c0d7ca4f4225aab9193fce1569.tar.bz2
rockbox-14727b1ac362d9c0d7ca4f4225aab9193fce1569.tar.xz
Implement unit test for ServerInfo input parsing.
Change-Id: I9e28c94ca72c7644a154e40a258d9f00df5f5edd
-rw-r--r--rbutil/rbutilqt/test/test-serverinfo.cpp104
-rw-r--r--rbutil/rbutilqt/test/test-serverinfo.pro37
2 files changed, 141 insertions, 0 deletions
diff --git a/rbutil/rbutilqt/test/test-serverinfo.cpp b/rbutil/rbutilqt/test/test-serverinfo.cpp
new file mode 100644
index 0000000..243dc56
--- /dev/null
+++ b/rbutil/rbutilqt/test/test-serverinfo.cpp
@@ -0,0 +1,104 @@
+/***************************************************************************
+ * __________ __ ___.
+ * 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 "serverinfo.h"
+
+class TestServerInfo : public QObject
+{
+ Q_OBJECT
+ private slots:
+ void testMain();
+};
+
+const char* testinfo =
+ "[release]\n"
+ "archosfmrecorder=3.11.2\n"
+ "iaudiom3=3.11.2,http://download.rockbox.org/release/3.11.2/rockbox-iaudiom5-3.11.2.zip\n"
+ "sansae200 = 3.11.2\n"
+ "iriverh100 = 3.11.2, http://download.rockbox.org/release/3.11.2/rockbox-iriverh100-3.11.2.zip\n"
+ "iriverh300 = \n"
+ "[release-candidate]\n"
+ "gigabeatfx=f9dce96,http://download.rockbox.org/release-candidate/f9dce96/rockbox-gigabeatfx.zip\n"
+ "archosfmrecorder=f9dce96\n"
+ "archosrecorder = f9dce96\n"
+ "iaudiox5=f9dce96,http://download.rockbox.org/release-candidate/f9dce96/rockbox-iaudiox5.zip\n";
+
+
+struct testvector {
+ const char* target;
+ ServerInfo::ServerInfos entry;
+ const char* expected;
+};
+
+
+const struct testvector testdata[] =
+{
+ { "archosfmrecorder", ServerInfo::CurReleaseVersion, "3.11.2" },
+ { "iaudiom3", ServerInfo::CurReleaseVersion, "3.11.2" },
+ { "iaudiom3", ServerInfo::CurReleaseUrl, "http://download.rockbox.org/release/3.11.2/rockbox-iaudiom5-3.11.2.zip" },
+ { "sansae200", ServerInfo::CurReleaseVersion, "3.11.2" },
+ { "sansae200", ServerInfo::CurReleaseUrl, "http://download.rockbox.org/release/3.11.2/rockbox-sansae200-3.11.2.zip" },
+ { "iriverh100", ServerInfo::CurReleaseVersion, "3.11.2" },
+ { "iriverh100", ServerInfo::CurReleaseUrl, "http://download.rockbox.org/release/3.11.2/rockbox-iriverh100-3.11.2.zip" },
+ { "iriverh300", ServerInfo::CurReleaseVersion, "" },
+ { "iriverh300", ServerInfo::CurReleaseUrl, "" },
+ { "iriverh10", ServerInfo::CurReleaseVersion, "" },
+ { "iriverh10", ServerInfo::CurReleaseUrl, "" },
+ { "gigabeatfx", ServerInfo::RelCandidateVersion, "f9dce96" },
+ { "gigabeatfx", ServerInfo::RelCandidateUrl, "http://download.rockbox.org/release-candidate/f9dce96/rockbox-gigabeatfx.zip" },
+ { "archosfmrecorder", ServerInfo::RelCandidateVersion, "" },
+ { "archosfmrecorder", ServerInfo::RelCandidateUrl, "" },
+ { "archosrecorder", ServerInfo::RelCandidateVersion, "" },
+ { "archosrecorder", ServerInfo::RelCandidateUrl, "" },
+ { "iaudiox5", ServerInfo::RelCandidateVersion, "f9dce96" },
+ { "iaudiox5", ServerInfo::RelCandidateUrl, "http://download.rockbox.org/release-candidate/f9dce96/rockbox-iaudiox5.zip" },
+ { "iaudiox5.v", ServerInfo::RelCandidateVersion, "f9dce96" },
+ { "iaudiox5.v", ServerInfo::RelCandidateUrl, "http://download.rockbox.org/release-candidate/f9dce96/rockbox-iaudiox5.zip" },
+};
+
+
+void TestServerInfo::testMain()
+{
+ // 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();
+
+ ServerInfo::readBuildInfo(filename);
+
+ unsigned int i;
+ for(i = 0; i < sizeof(testdata) / sizeof(struct testvector); i++) {
+ QString result = ServerInfo::platformValue(testdata[i].target, testdata[i].entry).toString();
+ QCOMPARE(result, QString(testdata[i].expected));
+ }
+}
+
+
+QTEST_MAIN(TestServerInfo)
+
+// 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-serverinfo.moc"
+
diff --git a/rbutil/rbutilqt/test/test-serverinfo.pro b/rbutil/rbutilqt/test/test-serverinfo.pro
new file mode 100644
index 0000000..1f6b1c1
--- /dev/null
+++ b/rbutil/rbutilqt/test/test-serverinfo.pro
@@ -0,0 +1,37 @@
+#
+# __________ __ ___.
+# 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-serverinfo
+INCLUDEPATH += . ../base
+
+# Input
+SOURCES += \
+ test-serverinfo.cpp \
+ ../base/rbsettings.cpp \
+ ../base/rockboxinfo.cpp \
+ ../base/systeminfo.cpp \
+ ../base/serverinfo.cpp
+
+HEADERS += \
+ ../base/rbsettings.h \
+ ../base/rockboxinfo.h \
+ ../base/systeminfo.h \
+ ../base/serverinfo.h \
+
+RESOURCES += ../rbutilqt.qrc