Fix false positive in version detection.
[maemo-rb.git] / rbutil / rbutilqt / test / test-rockboxinfo.cpp
blobe7191860d2d11c26cda0020dc83be7269ccfea4f
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
9 * Copyright (C) 2012 Dominik Riebeling
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.
16 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
17 * KIND, either express or implied.
19 ****************************************************************************/
21 #include <QtTest/QtTest>
22 #include <QObject>
23 #include "rockboxinfo.h"
26 class TestRockboxInfo : public QObject
28 Q_OBJECT
29 private slots:
30 void testVersion();
31 void testMemory();
32 void testTarget();
33 void testFeatures();
37 void TestRockboxInfo::testVersion()
39 struct testvector {
40 const char* versionline;
41 const char* revisionstring;
42 const char* versionstring;
43 const char* releasestring;
46 const struct testvector testdata[] =
48 /* Input string revision full version release version */
49 { "Version: r29629-110321", "29629", "r29629-110321", "" },
50 { "Version: r29629M-110321", "29629M", "r29629M-110321", "" },
51 { "Version: 3.10", "", "3.10", "3.10" },
52 { "Version:\t3.10", "", "3.10", "3.10" },
53 { "#Version: r29629-110321", "", "", "" },
54 { "Version: e5b1b0f-120218", "e5b1b0f", "e5b1b0f-120218", "" },
55 { "Version: e5b1b0fM-120218", "e5b1b0fM", "e5b1b0fM-120218", "" },
56 { "#Version: e5b1b0f-120218", "", "", "" },
57 { "Version: 3448f5b-120310", "3448f5b", "3448f5b-120310", "" },
61 unsigned int i;
62 for(i = 0; i < sizeof(testdata) / sizeof(struct testvector); i++) {
63 QTemporaryFile tf(this);
64 tf.open();
65 QString filename = tf.fileName();
66 tf.write(testdata[i].versionline);
67 tf.write("\n");
68 tf.close();
70 RockboxInfo info("", filename);
71 QCOMPARE(info.version(), QString(testdata[i].versionstring));
72 QCOMPARE(info.revision(), QString(testdata[i].revisionstring));
73 QCOMPARE(info.release(), QString(testdata[i].releasestring));
78 void TestRockboxInfo::testTarget()
80 int i, j;
81 QStringList targets;
82 targets << "sansae200" << "gigabeats" << "iriverh100" << "unknown";
83 QStringList prefix;
84 prefix << "Target: "; // << "Target:\t" << "Target: ";
85 for(j = 0; j < prefix.size(); ++j) {
86 for(i = 0; i < targets.size(); i++) {
87 QTemporaryFile tf(this);
88 tf.open();
89 QString filename = tf.fileName();
90 tf.write(prefix.at(j).toLocal8Bit());
91 tf.write(targets.at(i).toLocal8Bit());
92 tf.write("\n");
93 tf.close();
95 RockboxInfo info("", filename);
96 QCOMPARE(info.target(), targets.at(i));
102 void TestRockboxInfo::testMemory()
104 int i, j;
105 QStringList memsizes;
106 memsizes << "8" << "16" << "32" << "64";
107 QStringList prefix;
108 prefix << "Memory: " << "Memory:\t" << "Memory: ";
109 for(j = 0; j < prefix.size(); ++j) {
110 for(i = 0; i < memsizes.size(); i++) {
111 QTemporaryFile tf(this);
112 tf.open();
113 QString filename = tf.fileName();
114 tf.write(prefix.at(j).toLocal8Bit());
115 tf.write(memsizes.at(i).toLocal8Bit());
116 tf.write("\n");
117 tf.close();
119 RockboxInfo info("", filename);
120 QCOMPARE(info.ram(), memsizes.at(i).toInt());
126 void TestRockboxInfo::testFeatures()
128 int i, j;
129 QStringList features;
130 features << "backlight_brightness:button_light:dircache:flash_storage"
131 << "pitchscreen:multivolume:multidrive_usb:quickscreen";
132 QStringList prefix;
133 prefix << "Features: " << "Features:\t" << "Features: ";
134 for(j = 0; j < prefix.size(); ++j) {
135 for(i = 0; i < features.size(); i++) {
136 QTemporaryFile tf(this);
137 tf.open();
138 QString filename = tf.fileName();
139 tf.write(prefix.at(j).toLocal8Bit());
140 tf.write(features.at(i).toLocal8Bit());
141 tf.write("\n");
142 tf.close();
144 RockboxInfo info("", filename);
145 QCOMPARE(info.features(), features.at(i));
150 QTEST_MAIN(TestRockboxInfo)
152 // this include is needed because we don't use a separate header file for the
153 // test class. It also needs to be at the end.
154 #include "test-rockboxinfo.moc"