Chris@1022
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@1022
|
2
|
Chris@1022
|
3 /*
|
Chris@1022
|
4 Sonic Visualiser
|
Chris@1022
|
5 An audio file viewer and annotation editor.
|
Chris@1022
|
6 Centre for Digital Music, Queen Mary, University of London.
|
Chris@1022
|
7
|
Chris@1022
|
8 This program is free software; you can redistribute it and/or
|
Chris@1022
|
9 modify it under the terms of the GNU General Public License as
|
Chris@1022
|
10 published by the Free Software Foundation; either version 2 of the
|
Chris@1022
|
11 License, or (at your option) any later version. See the file
|
Chris@1022
|
12 COPYING included with this distribution for more information.
|
Chris@1022
|
13 */
|
Chris@1022
|
14
|
Chris@1022
|
15 #ifndef TEST_STRINGBITS_H
|
Chris@1022
|
16 #define TEST_STRINGBITS_H
|
Chris@1022
|
17
|
Chris@1022
|
18 #include "../StringBits.h"
|
Chris@1022
|
19
|
Chris@1022
|
20 #include <QObject>
|
Chris@1022
|
21 #include <QStringList>
|
Chris@1022
|
22 #include <QtTest>
|
Chris@1022
|
23
|
Chris@1022
|
24 #include <iostream>
|
Chris@1022
|
25
|
Chris@1022
|
26 using namespace std;
|
Chris@1022
|
27
|
Chris@1022
|
28 class TestStringBits : public QObject
|
Chris@1022
|
29 {
|
Chris@1022
|
30 Q_OBJECT
|
Chris@1022
|
31
|
Chris@1022
|
32 private:
|
Chris@1022
|
33 void testSplitQuoted(QString in, QStringList out) {
|
Chris@1022
|
34 // Only suitable where the output strings do not have
|
Chris@1022
|
35 // consecutive spaces in them
|
Chris@1022
|
36 QCOMPARE(StringBits::splitQuoted(in, ' '), out);
|
Chris@1022
|
37 QString in2(in);
|
Chris@1022
|
38 in2.replace(' ', ',');
|
Chris@1022
|
39 QStringList out2;
|
Chris@1022
|
40 foreach (QString o, out) {
|
Chris@1022
|
41 out2 << o.replace(' ', ',');
|
Chris@1022
|
42 }
|
Chris@1022
|
43 QCOMPARE(StringBits::splitQuoted(in2, ','), out2);
|
Chris@1022
|
44 }
|
Chris@1022
|
45
|
Chris@1022
|
46 private slots:
|
Chris@1854
|
47 void empty() {
|
Chris@1854
|
48 QString in = "";
|
Chris@1854
|
49 QStringList out;
|
Chris@1854
|
50 testSplitQuoted(in, out);
|
Chris@1854
|
51 }
|
Chris@1854
|
52
|
Chris@1854
|
53 void empties() {
|
Chris@1854
|
54
|
Chris@1854
|
55 // Behaviour here differs based on what the separator is
|
Chris@1854
|
56 // (spaces are coalesced)
|
Chris@1854
|
57
|
Chris@1854
|
58 QString in;
|
Chris@1854
|
59 QStringList out;
|
Chris@1854
|
60 out << "" << "";
|
Chris@1854
|
61
|
Chris@1854
|
62 in = " ";
|
Chris@1854
|
63 QCOMPARE(StringBits::splitQuoted(in, ' '), out);
|
Chris@1854
|
64
|
Chris@1854
|
65 in = ",";
|
Chris@1854
|
66 QCOMPARE(StringBits::splitQuoted(in, ','), out);
|
Chris@1854
|
67
|
Chris@1854
|
68 in = " ";
|
Chris@1854
|
69 QCOMPARE(StringBits::splitQuoted(in, ' '), out);
|
Chris@1854
|
70
|
Chris@1854
|
71 in = ",,";
|
Chris@1854
|
72 out << "";
|
Chris@1854
|
73 QCOMPARE(StringBits::splitQuoted(in, ','), out);
|
Chris@1854
|
74 }
|
Chris@1854
|
75
|
Chris@1022
|
76 void simple() {
|
Chris@1022
|
77 QString in = "a b c d";
|
Chris@1022
|
78 QStringList out;
|
Chris@1022
|
79 out << "a" << "b" << "c" << "d";
|
Chris@1022
|
80 testSplitQuoted(in, out);
|
Chris@1022
|
81 }
|
Chris@1022
|
82
|
Chris@1022
|
83 void dquoted() {
|
Chris@1022
|
84 QString in = "a \"b c\" d";
|
Chris@1022
|
85 QStringList out;
|
Chris@1022
|
86 out << "a" << "b c" << "d";
|
Chris@1022
|
87 testSplitQuoted(in, out);
|
Chris@1022
|
88 }
|
Chris@1022
|
89
|
Chris@1022
|
90 void drunon() {
|
Chris@1022
|
91 QString in = "a \"b c\"d e";
|
Chris@1022
|
92 QStringList out;
|
Chris@1022
|
93 out << "a" << "b cd" << "e";
|
Chris@1022
|
94 testSplitQuoted(in, out);
|
Chris@1022
|
95 }
|
Chris@1022
|
96
|
Chris@1022
|
97 void squoted() {
|
Chris@1022
|
98 QString in = "a 'b c' d";
|
Chris@1022
|
99 QStringList out;
|
Chris@1022
|
100 out << "a" << "b c" << "d";
|
Chris@1022
|
101 testSplitQuoted(in, out);
|
Chris@1022
|
102 }
|
Chris@1022
|
103
|
Chris@1022
|
104 void srunon() {
|
Chris@1022
|
105 QString in = "a 'b c'd e";
|
Chris@1022
|
106 QStringList out;
|
Chris@1022
|
107 out << "a" << "b cd" << "e";
|
Chris@1022
|
108 testSplitQuoted(in, out);
|
Chris@1022
|
109 }
|
Chris@1022
|
110
|
Chris@1022
|
111 void dempty() {
|
Chris@1022
|
112 QString in = "\"\" \"\" \"\"";
|
Chris@1022
|
113 QStringList out;
|
Chris@1022
|
114 out << "" << "" << "";
|
Chris@1022
|
115 testSplitQuoted(in, out);
|
Chris@1022
|
116 }
|
Chris@1022
|
117
|
Chris@1022
|
118 void sempty() {
|
Chris@1022
|
119 QString in = "'' '' ''";
|
Chris@1022
|
120 QStringList out;
|
Chris@1022
|
121 out << "" << "" << "";
|
Chris@1022
|
122 testSplitQuoted(in, out);
|
Chris@1022
|
123 }
|
Chris@1022
|
124
|
Chris@1022
|
125 void descaped() {
|
Chris@1022
|
126 QString in = "a \"b c\\\" d\"";
|
Chris@1022
|
127 QStringList out;
|
Chris@1022
|
128 out << "a" << "b c\" d";
|
Chris@1022
|
129 testSplitQuoted(in, out);
|
Chris@1022
|
130 }
|
Chris@1022
|
131
|
Chris@1022
|
132 void sescaped() {
|
Chris@1022
|
133 QString in = "a 'b c\\' d'";
|
Chris@1022
|
134 QStringList out;
|
Chris@1022
|
135 out << "a" << "b c' d";
|
Chris@1022
|
136 testSplitQuoted(in, out);
|
Chris@1022
|
137 }
|
Chris@1022
|
138
|
Chris@1854
|
139 void ddescaped() {
|
Chris@1854
|
140 QString in = "a \"b c\"\" d\"";
|
Chris@1854
|
141 QStringList out;
|
Chris@1854
|
142 out << "a" << "b c\" d";
|
Chris@1854
|
143 testSplitQuoted(in, out);
|
Chris@1854
|
144 }
|
Chris@1854
|
145
|
Chris@1854
|
146 void sdescaped() {
|
Chris@1854
|
147 QString in = "a 'b c'' d'";
|
Chris@1854
|
148 QStringList out;
|
Chris@1854
|
149 out << "a" << "b c' d";
|
Chris@1854
|
150 testSplitQuoted(in, out);
|
Chris@1854
|
151 }
|
Chris@1854
|
152
|
Chris@1022
|
153 void dnested() {
|
Chris@1022
|
154 QString in = "a \"b c' d\"";
|
Chris@1022
|
155 QStringList out;
|
Chris@1022
|
156 out << "a" << "b c' d";
|
Chris@1022
|
157 testSplitQuoted(in, out);
|
Chris@1022
|
158 }
|
Chris@1022
|
159
|
Chris@1022
|
160 void snested() {
|
Chris@1022
|
161 QString in = "a 'b c\" d'";
|
Chris@1022
|
162 QStringList out;
|
Chris@1022
|
163 out << "a" << "b c\" d";
|
Chris@1022
|
164 testSplitQuoted(in, out);
|
Chris@1022
|
165 }
|
Chris@1022
|
166
|
Chris@1022
|
167 void snested2() {
|
Chris@1022
|
168 QString in = "aa 'bb cc\" dd'";
|
Chris@1022
|
169 QStringList out;
|
Chris@1022
|
170 out << "aa" << "bb cc\" dd";
|
Chris@1022
|
171 testSplitQuoted(in, out);
|
Chris@1022
|
172 }
|
Chris@1022
|
173
|
Chris@1524
|
174 void snested3() {
|
Chris@1524
|
175 QString in = "'aa bb cc\"' dd";
|
Chris@1524
|
176 QStringList out;
|
Chris@1524
|
177 out << "aa bb cc\"" << "dd";
|
Chris@1524
|
178 testSplitQuoted(in, out);
|
Chris@1524
|
179 }
|
Chris@1524
|
180
|
Chris@1524
|
181 void snested3a() {
|
Chris@1524
|
182 QString in = "\"aa bb cc'\" dd";
|
Chris@1524
|
183 QStringList out;
|
Chris@1524
|
184 out << "aa bb cc'" << "dd";
|
Chris@1524
|
185 testSplitQuoted(in, out);
|
Chris@1524
|
186 }
|
Chris@1524
|
187
|
Chris@1524
|
188 void snested4() {
|
Chris@1524
|
189 QString in = "'aa \"bb cc\" dd'";
|
Chris@1524
|
190 QStringList out;
|
Chris@1524
|
191 out << "aa \"bb cc\" dd";
|
Chris@1524
|
192 testSplitQuoted(in, out);
|
Chris@1524
|
193 }
|
Chris@1524
|
194
|
Chris@1524
|
195 void snested4a() {
|
Chris@1524
|
196 QString in = "\"aa 'bb cc' dd\"";
|
Chris@1524
|
197 QStringList out;
|
Chris@1524
|
198 out << "aa 'bb cc' dd";
|
Chris@1524
|
199 testSplitQuoted(in, out);
|
Chris@1524
|
200 }
|
Chris@1524
|
201
|
Chris@1022
|
202 void qquoted() {
|
Chris@1022
|
203 QString in = "a'a 'bb' \\\"cc\" dd\\\"";
|
Chris@1022
|
204 QStringList out;
|
Chris@1022
|
205 out << "a'a" << "bb" << "\"cc\"" << "dd\"";
|
Chris@1022
|
206 testSplitQuoted(in, out);
|
Chris@1022
|
207 }
|
Chris@1022
|
208
|
Chris@1524
|
209 void qspace() {
|
Chris@1524
|
210 QString in = "\"a a\":\"b:b\":\"c d\"";
|
Chris@1524
|
211 QStringList out1;
|
Chris@1524
|
212 // Can't start a quote in the middle of a bare field - they
|
Chris@1524
|
213 // are handled only if the first character in the field is a
|
Chris@1524
|
214 // quote. Otherwise we'd have trouble with apostrophes etc
|
Chris@1524
|
215 out1 << "a a:\"b:b\":\"c" << "d\"";
|
Chris@1524
|
216 QCOMPARE(StringBits::splitQuoted(in, ' '), out1);
|
Chris@1524
|
217 QStringList out2;
|
Chris@1524
|
218 out2 << "a a" << "b:b" << "c d";
|
Chris@1524
|
219 QCOMPARE(StringBits::splitQuoted(in, ':'), out2);
|
Chris@1524
|
220 }
|
Chris@1524
|
221
|
Chris@1022
|
222 void multispace() {
|
Chris@1022
|
223 QString in = " a'a \\' 'bb' ' \\\"cc\" ' dd\\\" '";
|
Chris@1022
|
224 QStringList out;
|
Chris@1854
|
225 out << "" << "a'a" << "'" << "bb" << " \"cc\" " << "dd\"" << "'";
|
Chris@1022
|
226 QCOMPARE(StringBits::splitQuoted(in, ' '), out);
|
Chris@1022
|
227
|
Chris@1022
|
228 QString in2 = ",,a'a,\\',,,,,,,,,'bb',,,,',,,,,,\\\"cc\",',dd\\\",'";
|
Chris@1022
|
229 QStringList out2;
|
Chris@1022
|
230 out2 << "" << "" << "a'a" << "'" << "" << "" << "" << "" << "" << ""
|
Chris@1022
|
231 << "" << "" << "bb" << "" << "" << "" << ",,,,,,\"cc\","
|
Chris@1022
|
232 << "dd\"" << "'";
|
Chris@1022
|
233 QCOMPARE(StringBits::splitQuoted(in2, ','), out2);
|
Chris@1022
|
234 }
|
Chris@1022
|
235 };
|
Chris@1022
|
236
|
Chris@1022
|
237 #endif
|
Chris@1022
|
238
|
Chris@1022
|
239 /* r928
|
Chris@1022
|
240 Config: Using QtTest library 5.3.2, Qt 5.3.2
|
Chris@1022
|
241 PASS : TestStringBits::initTestCase()
|
Chris@1022
|
242 PASS : TestStringBits::simple()
|
Chris@1022
|
243 PASS : TestStringBits::dquoted()
|
Chris@1022
|
244 PASS : TestStringBits::squoted()
|
Chris@1022
|
245 PASS : TestStringBits::descaped()
|
Chris@1022
|
246 FAIL! : TestStringBits::sescaped() Compared lists have different sizes.
|
Chris@1022
|
247 Actual (StringBits::splitQuoted(in, ' ')) size: 3
|
Chris@1022
|
248 Expected (out) size: 2
|
Chris@1022
|
249 Loc: [o/../TestStringBits.h(65)]
|
Chris@1022
|
250 PASS : TestStringBits::dnested()
|
Chris@1022
|
251 PASS : TestStringBits::snested()
|
Chris@1022
|
252 PASS : TestStringBits::snested2()
|
Chris@1022
|
253 PASS : TestStringBits::qquoted()
|
Chris@1022
|
254 FAIL! : TestStringBits::multispace() Compared lists differ at index 1.
|
Chris@1022
|
255 Actual (StringBits::splitQuoted(in, ' ')): " "
|
Chris@1022
|
256 Expected (out): "'"
|
Chris@1022
|
257 Loc: [o/../TestStringBits.h(100)]
|
Chris@1022
|
258 FAIL! : TestStringBits::qcommas() Compared lists have different sizes.
|
Chris@1022
|
259 Actual (StringBits::splitQuoted(in, ',')) size: 4
|
Chris@1022
|
260 Expected (out) size: 3
|
Chris@1022
|
261 Loc: [o/../TestStringBits.h(107)]
|
Chris@1022
|
262 PASS : TestStringBits::cleanupTestCase()
|
Chris@1022
|
263 Totals: 10 passed, 3 failed, 0 skipped
|
Chris@1022
|
264 */
|
Chris@1022
|
265
|
Chris@1022
|
266 /*curr
|
Chris@1022
|
267 PASS : TestStringBits::initTestCase()
|
Chris@1022
|
268 PASS : TestStringBits::simple()
|
Chris@1022
|
269 PASS : TestStringBits::dquoted()
|
Chris@1022
|
270 PASS : TestStringBits::squoted()
|
Chris@1022
|
271 PASS : TestStringBits::descaped()
|
Chris@1022
|
272 FAIL! : TestStringBits::sescaped() Compared lists have different sizes.
|
Chris@1022
|
273 Actual (StringBits::splitQuoted(in, ' ')) size: 3
|
Chris@1022
|
274 Expected (out) size: 2
|
Chris@1022
|
275 Loc: [o/../TestStringBits.h(65)]
|
Chris@1022
|
276 PASS : TestStringBits::dnested()
|
Chris@1022
|
277 PASS : TestStringBits::snested()
|
Chris@1022
|
278 PASS : TestStringBits::snested2()
|
Chris@1022
|
279 PASS : TestStringBits::qquoted()
|
Chris@1022
|
280 FAIL! : TestStringBits::multispace() Compared lists have different sizes.
|
Chris@1022
|
281 Actual (StringBits::splitQuoted(in, ' ')) size: 5
|
Chris@1022
|
282 Expected (out) size: 6
|
Chris@1022
|
283 Loc: [o/../TestStringBits.h(100)]
|
Chris@1022
|
284 PASS : TestStringBits::qcommas()
|
Chris@1022
|
285 PASS : TestStringBits::cleanupTestCase()
|
Chris@1022
|
286 Totals: 11 passed, 2 failed, 0 skipped
|
Chris@1022
|
287 */
|