summaryrefslogtreecommitdiff
path: root/rbutil
diff options
context:
space:
mode:
authorDominik Riebeling <Dominik.Riebeling@gmail.com>2020-12-03 22:19:41 +0100
committerDominik Riebeling <Dominik.Riebeling@gmail.com>2020-12-03 22:25:12 +0100
commit7739bb31b3058476d5b805d82cd814ec6328e472 (patch)
tree18899de5f1d18009e73603346bdec8a4ab905581 /rbutil
parent3300815c44200c0dfb25de7cafe16a71abde57f0 (diff)
downloadrockbox-7739bb31b3058476d5b805d82cd814ec6328e472.tar.gz
rockbox-7739bb31b3058476d5b805d82cd814ec6328e472.zip
rbutil: Convert RockboxInfo unit test to data driven QTest.
Change-Id: Ic566f9be3532d327af4916605f0215da636ee7d6
Diffstat (limited to 'rbutil')
-rw-r--r--rbutil/rbutilqt/test/test-rockboxinfo.cpp166
-rw-r--r--rbutil/rbutilqt/test/test-rockboxinfo.pro2
2 files changed, 100 insertions, 68 deletions
diff --git a/rbutil/rbutilqt/test/test-rockboxinfo.cpp b/rbutil/rbutilqt/test/test-rockboxinfo.cpp
index e7191860d2..9d2b53b3ab 100644
--- a/rbutil/rbutilqt/test/test-rockboxinfo.cpp
+++ b/rbutil/rbutilqt/test/test-rockboxinfo.cpp
@@ -28,22 +28,24 @@ class TestRockboxInfo : public QObject
28 Q_OBJECT 28 Q_OBJECT
29 private slots: 29 private slots:
30 void testVersion(); 30 void testVersion();
31 void testVersion_data();
31 void testMemory(); 32 void testMemory();
33 void testMemory_data();
32 void testTarget(); 34 void testTarget();
35 void testTarget_data();
33 void testFeatures(); 36 void testFeatures();
37 void testFeatures_data();
34}; 38};
35 39
36 40
37void TestRockboxInfo::testVersion() 41void TestRockboxInfo::testVersion_data()
38{ 42{
39 struct testvector { 43 struct {
40 const char* versionline; 44 const char* input;
41 const char* revisionstring; 45 const char* revision;
42 const char* versionstring; 46 const char* version;
43 const char* releasestring; 47 const char* release;
44 }; 48 } const testdata[] =
45
46 const struct testvector testdata[] =
47 { 49 {
48 /* Input string revision full version release version */ 50 /* Input string revision full version release version */
49 { "Version: r29629-110321", "29629", "r29629-110321", "" }, 51 { "Version: r29629-110321", "29629", "r29629-110321", "" },
@@ -58,92 +60,122 @@ void TestRockboxInfo::testVersion()
58 }; 60 };
59 61
60 62
63 QTest::addColumn<QString>("input");
64 QTest::addColumn<QString>("revision");
65 QTest::addColumn<QString>("version");
66 QTest::addColumn<QString>("release");
61 unsigned int i; 67 unsigned int i;
62 for(i = 0; i < sizeof(testdata) / sizeof(struct testvector); i++) { 68 for(i = 0; i < sizeof(testdata) / sizeof(testdata[0]); i++) {
63 QTemporaryFile tf(this); 69 for (size_t i = 0; i < sizeof(testdata) / sizeof(testdata[0]); i++) {
64 tf.open(); 70 QTest::newRow(testdata[i].input)
65 QString filename = tf.fileName(); 71 << testdata[i].input << testdata[i].revision
66 tf.write(testdata[i].versionline); 72 << testdata[i].version << testdata[i].release;
67 tf.write("\n"); 73 }
68 tf.close();
69
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));
74 } 74 }
75} 75}
76 76
77 77
78void 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
97void 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
78void TestRockboxInfo::testTarget() 106void TestRockboxInfo::testTarget()
79{ 107{
80 int i, j; 108 int j;
81 QStringList targets;
82 targets << "sansae200" << "gigabeats" << "iriverh100" << "unknown";
83 QStringList prefix; 109 QStringList prefix;
84 prefix << "Target: "; // << "Target:\t" << "Target: "; 110 prefix << "Target: "; // << "Target:\t" << "Target: ";
85 for(j = 0; j < prefix.size(); ++j) { 111 for(j = 0; j < prefix.size(); ++j) {
86 for(i = 0; i < targets.size(); i++) { 112 QFETCH(QString, target);
87 QTemporaryFile tf(this); 113 QTemporaryFile tf(this);
88 tf.open(); 114 tf.open();
89 QString filename = tf.fileName(); 115 QString filename = tf.fileName();
90 tf.write(prefix.at(j).toLocal8Bit()); 116 tf.write(prefix.at(j).toLatin1());
91 tf.write(targets.at(i).toLocal8Bit()); 117 tf.write(target.toLatin1());
92 tf.write("\n"); 118 tf.write("\n");
93 tf.close(); 119 tf.close();
94 120
95 RockboxInfo info("", filename); 121 RockboxInfo info("", filename);
96 QCOMPARE(info.target(), targets.at(i)); 122 QCOMPARE(info.target(), target);
97 }
98 } 123 }
99} 124}
100 125
126void 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}
101 134
102void TestRockboxInfo::testMemory() 135void TestRockboxInfo::testMemory()
103{ 136{
104 int i, j; 137 int j;
105 QStringList memsizes;
106 memsizes << "8" << "16" << "32" << "64";
107 QStringList prefix; 138 QStringList prefix;
108 prefix << "Memory: " << "Memory:\t" << "Memory: "; 139 prefix << "Memory: " << "Memory:\t" << "Memory: ";
109 for(j = 0; j < prefix.size(); ++j) { 140 for(j = 0; j < prefix.size(); ++j) {
110 for(i = 0; i < memsizes.size(); i++) { 141 QFETCH(QString, memory);
111 QTemporaryFile tf(this); 142 QTemporaryFile tf(this);
112 tf.open(); 143 tf.open();
113 QString filename = tf.fileName(); 144 QString filename = tf.fileName();
114 tf.write(prefix.at(j).toLocal8Bit()); 145 tf.write(prefix.at(j).toLatin1());
115 tf.write(memsizes.at(i).toLocal8Bit()); 146 tf.write(memory.toLatin1());
116 tf.write("\n"); 147 tf.write("\n");
117 tf.close(); 148 tf.close();
118 149
119 RockboxInfo info("", filename); 150 RockboxInfo info("", filename);
120 QCOMPARE(info.ram(), memsizes.at(i).toInt()); 151 QCOMPARE(info.ram(), memory.toInt());
121 }
122 } 152 }
123} 153}
124 154
155void 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}
125 161
126void TestRockboxInfo::testFeatures() 162void TestRockboxInfo::testFeatures()
127{ 163{
128 int i, j; 164 int j;
129 QStringList features;
130 features << "backlight_brightness:button_light:dircache:flash_storage"
131 << "pitchscreen:multivolume:multidrive_usb:quickscreen";
132 QStringList prefix; 165 QStringList prefix;
133 prefix << "Features: " << "Features:\t" << "Features: "; 166 prefix << "Features: " << "Features:\t" << "Features: ";
134 for(j = 0; j < prefix.size(); ++j) { 167 for(j = 0; j < prefix.size(); ++j) {
135 for(i = 0; i < features.size(); i++) { 168 QFETCH(QString, features);
136 QTemporaryFile tf(this); 169 QTemporaryFile tf(this);
137 tf.open(); 170 tf.open();
138 QString filename = tf.fileName(); 171 QString filename = tf.fileName();
139 tf.write(prefix.at(j).toLocal8Bit()); 172 tf.write(prefix.at(j).toLatin1());
140 tf.write(features.at(i).toLocal8Bit()); 173 tf.write(features.toLatin1());
141 tf.write("\n"); 174 tf.write("\n");
142 tf.close(); 175 tf.close();
143 176
144 RockboxInfo info("", filename); 177 RockboxInfo info("", filename);
145 QCOMPARE(info.features(), features.at(i)); 178 QCOMPARE(info.features(), features);
146 }
147 } 179 }
148} 180}
149 181
diff --git a/rbutil/rbutilqt/test/test-rockboxinfo.pro b/rbutil/rbutilqt/test/test-rockboxinfo.pro
index 6cf7fdaf6c..88bc83a5b7 100644
--- a/rbutil/rbutilqt/test/test-rockboxinfo.pro
+++ b/rbutil/rbutilqt/test/test-rockboxinfo.pro
@@ -14,7 +14,7 @@
14# 14#
15 15
16# 16#
17include(tests.pri) 17QT += testlib
18 18
19TEMPLATE = app 19TEMPLATE = app
20TARGET = test-rockboxinfo 20TARGET = test-rockboxinfo