diff options
Diffstat (limited to 'rbutil/rbutilqt/test/test-rockboxinfo.cpp')
-rw-r--r-- | rbutil/rbutilqt/test/test-rockboxinfo.cpp | 148 |
1 files changed, 148 insertions, 0 deletions
diff --git a/rbutil/rbutilqt/test/test-rockboxinfo.cpp b/rbutil/rbutilqt/test/test-rockboxinfo.cpp new file mode 100644 index 0000000000..541d1c18ee --- /dev/null +++ b/rbutil/rbutilqt/test/test-rockboxinfo.cpp | |||
@@ -0,0 +1,148 @@ | |||
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 testMemory(); | ||
32 | void testTarget(); | ||
33 | void testFeatures(); | ||
34 | }; | ||
35 | |||
36 | |||
37 | void TestRockboxInfo::testVersion() | ||
38 | { | ||
39 | struct testvector { | ||
40 | const char* versionline; | ||
41 | const char* revisionstring; | ||
42 | const char* versionstring; | ||
43 | const char* releasestring; | ||
44 | }; | ||
45 | |||
46 | const struct testvector testdata[] = | ||
47 | { | ||
48 | { "Version: r29629-110321", "29629", "r29629-110321", "" }, | ||
49 | { "Version: r29629M-110321", "29629M", "r29629M-110321", "" }, | ||
50 | { "Version: 3.10", "", "3.10", "3.10" }, | ||
51 | { "Version:\t3.10", "", "3.10", "3.10" }, | ||
52 | }; | ||
53 | |||
54 | |||
55 | unsigned int i; | ||
56 | for(i = 0; i < sizeof(testdata) / sizeof(struct testvector); i++) { | ||
57 | QTemporaryFile tf(this); | ||
58 | tf.open(); | ||
59 | QString filename = tf.fileName(); | ||
60 | tf.write(testdata[i].versionline); | ||
61 | tf.write("\n"); | ||
62 | tf.close(); | ||
63 | |||
64 | RockboxInfo info("", filename); | ||
65 | QCOMPARE(info.version(), QString(testdata[i].versionstring)); | ||
66 | QCOMPARE(info.revision(), QString(testdata[i].revisionstring)); | ||
67 | } | ||
68 | } | ||
69 | |||
70 | |||
71 | void TestRockboxInfo::testTarget() | ||
72 | { | ||
73 | unsigned int i, j; | ||
74 | QStringList targets; | ||
75 | targets << "sansae200" << "gigabeats" << "iriverh100" << "unknown"; | ||
76 | QStringList prefix; | ||
77 | prefix << "Target: "; // << "Target:\t" << "Target: "; | ||
78 | for(j = 0; j < prefix.size(); ++j) { | ||
79 | for(i = 0; i < targets.size(); i++) { | ||
80 | QTemporaryFile tf(this); | ||
81 | tf.open(); | ||
82 | QString filename = tf.fileName(); | ||
83 | tf.write(prefix.at(j).toLocal8Bit()); | ||
84 | tf.write(targets.at(i).toLocal8Bit()); | ||
85 | tf.write("\n"); | ||
86 | tf.close(); | ||
87 | |||
88 | RockboxInfo info("", filename); | ||
89 | QCOMPARE(info.target(), targets.at(i)); | ||
90 | } | ||
91 | } | ||
92 | } | ||
93 | |||
94 | |||
95 | void TestRockboxInfo::testMemory() | ||
96 | { | ||
97 | unsigned int i, j; | ||
98 | QStringList memsizes; | ||
99 | memsizes << "8" << "16" << "32" << "64"; | ||
100 | QStringList prefix; | ||
101 | prefix << "Memory: " << "Memory:\t" << "Memory: "; | ||
102 | for(j = 0; j < prefix.size(); ++j) { | ||
103 | for(i = 0; i < memsizes.size(); i++) { | ||
104 | QTemporaryFile tf(this); | ||
105 | tf.open(); | ||
106 | QString filename = tf.fileName(); | ||
107 | tf.write(prefix.at(j).toLocal8Bit()); | ||
108 | tf.write(memsizes.at(i).toLocal8Bit()); | ||
109 | tf.write("\n"); | ||
110 | tf.close(); | ||
111 | |||
112 | RockboxInfo info("", filename); | ||
113 | QCOMPARE(info.ram(), memsizes.at(i).toInt()); | ||
114 | } | ||
115 | } | ||
116 | } | ||
117 | |||
118 | |||
119 | void TestRockboxInfo::testFeatures() | ||
120 | { | ||
121 | unsigned int i, j; | ||
122 | QStringList features; | ||
123 | features << "backlight_brightness:button_light:dircache:flash_storage" | ||
124 | << "pitchscreen:multivolume:multidrive_usb:quickscreen"; | ||
125 | QStringList prefix; | ||
126 | prefix << "Features: " << "Features:\t" << "Features: "; | ||
127 | for(j = 0; j < prefix.size(); ++j) { | ||
128 | for(i = 0; i < features.size(); i++) { | ||
129 | QTemporaryFile tf(this); | ||
130 | tf.open(); | ||
131 | QString filename = tf.fileName(); | ||
132 | tf.write(prefix.at(j).toLocal8Bit()); | ||
133 | tf.write(features.at(i).toLocal8Bit()); | ||
134 | tf.write("\n"); | ||
135 | tf.close(); | ||
136 | |||
137 | RockboxInfo info("", filename); | ||
138 | QCOMPARE(info.features(), features.at(i)); | ||
139 | } | ||
140 | } | ||
141 | } | ||
142 | |||
143 | QTEST_MAIN(TestRockboxInfo) | ||
144 | |||
145 | // this include is needed because we don't use a separate header file for the | ||
146 | // test class. It also needs to be at the end. | ||
147 | #include "test-rockboxinfo.moc" | ||
148 | |||