annotate base/test/TestStringBits.h @ 1758:83178b4bb698 by-id

Fix signal spec
author Chris Cannam
date Sun, 07 Jul 2019 16:42:47 +0100
parents 64ef24ebb19c
children bde22957545e
rev   line source
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@1022 47 void simple() {
Chris@1022 48 QString in = "a b c d";
Chris@1022 49 QStringList out;
Chris@1022 50 out << "a" << "b" << "c" << "d";
Chris@1022 51 testSplitQuoted(in, out);
Chris@1022 52 }
Chris@1022 53
Chris@1022 54 void dquoted() {
Chris@1022 55 QString in = "a \"b c\" d";
Chris@1022 56 QStringList out;
Chris@1022 57 out << "a" << "b c" << "d";
Chris@1022 58 testSplitQuoted(in, out);
Chris@1022 59 }
Chris@1022 60
Chris@1022 61 void drunon() {
Chris@1022 62 QString in = "a \"b c\"d e";
Chris@1022 63 QStringList out;
Chris@1022 64 out << "a" << "b cd" << "e";
Chris@1022 65 testSplitQuoted(in, out);
Chris@1022 66 }
Chris@1022 67
Chris@1022 68 void squoted() {
Chris@1022 69 QString in = "a 'b c' d";
Chris@1022 70 QStringList out;
Chris@1022 71 out << "a" << "b c" << "d";
Chris@1022 72 testSplitQuoted(in, out);
Chris@1022 73 }
Chris@1022 74
Chris@1022 75 void srunon() {
Chris@1022 76 QString in = "a 'b c'd e";
Chris@1022 77 QStringList out;
Chris@1022 78 out << "a" << "b cd" << "e";
Chris@1022 79 testSplitQuoted(in, out);
Chris@1022 80 }
Chris@1022 81
Chris@1022 82 void dempty() {
Chris@1022 83 QString in = "\"\" \"\" \"\"";
Chris@1022 84 QStringList out;
Chris@1022 85 out << "" << "" << "";
Chris@1022 86 testSplitQuoted(in, out);
Chris@1022 87 }
Chris@1022 88
Chris@1022 89 void sempty() {
Chris@1022 90 QString in = "'' '' ''";
Chris@1022 91 QStringList out;
Chris@1022 92 out << "" << "" << "";
Chris@1022 93 testSplitQuoted(in, out);
Chris@1022 94 }
Chris@1022 95
Chris@1022 96 void descaped() {
Chris@1022 97 QString in = "a \"b c\\\" d\"";
Chris@1022 98 QStringList out;
Chris@1022 99 out << "a" << "b c\" d";
Chris@1022 100 testSplitQuoted(in, out);
Chris@1022 101 }
Chris@1022 102
Chris@1022 103 void sescaped() {
Chris@1022 104 QString in = "a 'b c\\' d'";
Chris@1022 105 QStringList out;
Chris@1022 106 out << "a" << "b c' d";
Chris@1022 107 testSplitQuoted(in, out);
Chris@1022 108 }
Chris@1022 109
Chris@1022 110 void dnested() {
Chris@1022 111 QString in = "a \"b c' d\"";
Chris@1022 112 QStringList out;
Chris@1022 113 out << "a" << "b c' d";
Chris@1022 114 testSplitQuoted(in, out);
Chris@1022 115 }
Chris@1022 116
Chris@1022 117 void snested() {
Chris@1022 118 QString in = "a 'b c\" d'";
Chris@1022 119 QStringList out;
Chris@1022 120 out << "a" << "b c\" d";
Chris@1022 121 testSplitQuoted(in, out);
Chris@1022 122 }
Chris@1022 123
Chris@1022 124 void snested2() {
Chris@1022 125 QString in = "aa 'bb cc\" dd'";
Chris@1022 126 QStringList out;
Chris@1022 127 out << "aa" << "bb cc\" dd";
Chris@1022 128 testSplitQuoted(in, out);
Chris@1022 129 }
Chris@1022 130
Chris@1524 131 void snested3() {
Chris@1524 132 QString in = "'aa bb cc\"' dd";
Chris@1524 133 QStringList out;
Chris@1524 134 out << "aa bb cc\"" << "dd";
Chris@1524 135 testSplitQuoted(in, out);
Chris@1524 136 }
Chris@1524 137
Chris@1524 138 void snested3a() {
Chris@1524 139 QString in = "\"aa bb cc'\" dd";
Chris@1524 140 QStringList out;
Chris@1524 141 out << "aa bb cc'" << "dd";
Chris@1524 142 testSplitQuoted(in, out);
Chris@1524 143 }
Chris@1524 144
Chris@1524 145 void snested4() {
Chris@1524 146 QString in = "'aa \"bb cc\" dd'";
Chris@1524 147 QStringList out;
Chris@1524 148 out << "aa \"bb cc\" dd";
Chris@1524 149 testSplitQuoted(in, out);
Chris@1524 150 }
Chris@1524 151
Chris@1524 152 void snested4a() {
Chris@1524 153 QString in = "\"aa 'bb cc' dd\"";
Chris@1524 154 QStringList out;
Chris@1524 155 out << "aa 'bb cc' dd";
Chris@1524 156 testSplitQuoted(in, out);
Chris@1524 157 }
Chris@1524 158
Chris@1022 159 void qquoted() {
Chris@1022 160 QString in = "a'a 'bb' \\\"cc\" dd\\\"";
Chris@1022 161 QStringList out;
Chris@1022 162 out << "a'a" << "bb" << "\"cc\"" << "dd\"";
Chris@1022 163 testSplitQuoted(in, out);
Chris@1022 164 }
Chris@1022 165
Chris@1524 166 void qspace() {
Chris@1524 167 QString in = "\"a a\":\"b:b\":\"c d\"";
Chris@1524 168 QStringList out1;
Chris@1524 169 // Can't start a quote in the middle of a bare field - they
Chris@1524 170 // are handled only if the first character in the field is a
Chris@1524 171 // quote. Otherwise we'd have trouble with apostrophes etc
Chris@1524 172 out1 << "a a:\"b:b\":\"c" << "d\"";
Chris@1524 173 QCOMPARE(StringBits::splitQuoted(in, ' '), out1);
Chris@1524 174 QStringList out2;
Chris@1524 175 out2 << "a a" << "b:b" << "c d";
Chris@1524 176 QCOMPARE(StringBits::splitQuoted(in, ':'), out2);
Chris@1524 177 }
Chris@1524 178
Chris@1022 179 void multispace() {
Chris@1022 180 QString in = " a'a \\' 'bb' ' \\\"cc\" ' dd\\\" '";
Chris@1022 181 QStringList out;
Chris@1022 182 out << "a'a" << "'" << "bb" << " \"cc\" " << "dd\"" << "'";
Chris@1022 183 QCOMPARE(StringBits::splitQuoted(in, ' '), out);
Chris@1022 184
Chris@1022 185 QString in2 = ",,a'a,\\',,,,,,,,,'bb',,,,',,,,,,\\\"cc\",',dd\\\",'";
Chris@1022 186 QStringList out2;
Chris@1022 187 out2 << "" << "" << "a'a" << "'" << "" << "" << "" << "" << "" << ""
Chris@1022 188 << "" << "" << "bb" << "" << "" << "" << ",,,,,,\"cc\","
Chris@1022 189 << "dd\"" << "'";
Chris@1022 190 QCOMPARE(StringBits::splitQuoted(in2, ','), out2);
Chris@1022 191 }
Chris@1022 192 };
Chris@1022 193
Chris@1022 194 #endif
Chris@1022 195
Chris@1022 196 /* r928
Chris@1022 197 Config: Using QtTest library 5.3.2, Qt 5.3.2
Chris@1022 198 PASS : TestStringBits::initTestCase()
Chris@1022 199 PASS : TestStringBits::simple()
Chris@1022 200 PASS : TestStringBits::dquoted()
Chris@1022 201 PASS : TestStringBits::squoted()
Chris@1022 202 PASS : TestStringBits::descaped()
Chris@1022 203 FAIL! : TestStringBits::sescaped() Compared lists have different sizes.
Chris@1022 204 Actual (StringBits::splitQuoted(in, ' ')) size: 3
Chris@1022 205 Expected (out) size: 2
Chris@1022 206 Loc: [o/../TestStringBits.h(65)]
Chris@1022 207 PASS : TestStringBits::dnested()
Chris@1022 208 PASS : TestStringBits::snested()
Chris@1022 209 PASS : TestStringBits::snested2()
Chris@1022 210 PASS : TestStringBits::qquoted()
Chris@1022 211 FAIL! : TestStringBits::multispace() Compared lists differ at index 1.
Chris@1022 212 Actual (StringBits::splitQuoted(in, ' ')): " "
Chris@1022 213 Expected (out): "'"
Chris@1022 214 Loc: [o/../TestStringBits.h(100)]
Chris@1022 215 FAIL! : TestStringBits::qcommas() Compared lists have different sizes.
Chris@1022 216 Actual (StringBits::splitQuoted(in, ',')) size: 4
Chris@1022 217 Expected (out) size: 3
Chris@1022 218 Loc: [o/../TestStringBits.h(107)]
Chris@1022 219 PASS : TestStringBits::cleanupTestCase()
Chris@1022 220 Totals: 10 passed, 3 failed, 0 skipped
Chris@1022 221 */
Chris@1022 222
Chris@1022 223 /*curr
Chris@1022 224 PASS : TestStringBits::initTestCase()
Chris@1022 225 PASS : TestStringBits::simple()
Chris@1022 226 PASS : TestStringBits::dquoted()
Chris@1022 227 PASS : TestStringBits::squoted()
Chris@1022 228 PASS : TestStringBits::descaped()
Chris@1022 229 FAIL! : TestStringBits::sescaped() Compared lists have different sizes.
Chris@1022 230 Actual (StringBits::splitQuoted(in, ' ')) size: 3
Chris@1022 231 Expected (out) size: 2
Chris@1022 232 Loc: [o/../TestStringBits.h(65)]
Chris@1022 233 PASS : TestStringBits::dnested()
Chris@1022 234 PASS : TestStringBits::snested()
Chris@1022 235 PASS : TestStringBits::snested2()
Chris@1022 236 PASS : TestStringBits::qquoted()
Chris@1022 237 FAIL! : TestStringBits::multispace() Compared lists have different sizes.
Chris@1022 238 Actual (StringBits::splitQuoted(in, ' ')) size: 5
Chris@1022 239 Expected (out) size: 6
Chris@1022 240 Loc: [o/../TestStringBits.h(100)]
Chris@1022 241 PASS : TestStringBits::qcommas()
Chris@1022 242 PASS : TestStringBits::cleanupTestCase()
Chris@1022 243 Totals: 11 passed, 2 failed, 0 skipped
Chris@1022 244 */