annotate base/test/TestStringBits.h @ 1174:0ad516dc5d8d

Presume that the Vamp SDK exists at the directory next door
author Chris Cannam
date Fri, 18 Mar 2016 13:42:54 +0000
parents eecf544bed92
children 64ef24ebb19c
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@1022 131 void qquoted() {
Chris@1022 132 QString in = "a'a 'bb' \\\"cc\" dd\\\"";
Chris@1022 133 QStringList out;
Chris@1022 134 out << "a'a" << "bb" << "\"cc\"" << "dd\"";
Chris@1022 135 testSplitQuoted(in, out);
Chris@1022 136 }
Chris@1022 137
Chris@1022 138 void multispace() {
Chris@1022 139 QString in = " a'a \\' 'bb' ' \\\"cc\" ' dd\\\" '";
Chris@1022 140 QStringList out;
Chris@1022 141 out << "a'a" << "'" << "bb" << " \"cc\" " << "dd\"" << "'";
Chris@1022 142 QCOMPARE(StringBits::splitQuoted(in, ' '), out);
Chris@1022 143
Chris@1022 144 QString in2 = ",,a'a,\\',,,,,,,,,'bb',,,,',,,,,,\\\"cc\",',dd\\\",'";
Chris@1022 145 QStringList out2;
Chris@1022 146 out2 << "" << "" << "a'a" << "'" << "" << "" << "" << "" << "" << ""
Chris@1022 147 << "" << "" << "bb" << "" << "" << "" << ",,,,,,\"cc\","
Chris@1022 148 << "dd\"" << "'";
Chris@1022 149 QCOMPARE(StringBits::splitQuoted(in2, ','), out2);
Chris@1022 150 }
Chris@1022 151 };
Chris@1022 152
Chris@1022 153 #endif
Chris@1022 154
Chris@1022 155 /* r928
Chris@1022 156 Config: Using QtTest library 5.3.2, Qt 5.3.2
Chris@1022 157 PASS : TestStringBits::initTestCase()
Chris@1022 158 PASS : TestStringBits::simple()
Chris@1022 159 PASS : TestStringBits::dquoted()
Chris@1022 160 PASS : TestStringBits::squoted()
Chris@1022 161 PASS : TestStringBits::descaped()
Chris@1022 162 FAIL! : TestStringBits::sescaped() Compared lists have different sizes.
Chris@1022 163 Actual (StringBits::splitQuoted(in, ' ')) size: 3
Chris@1022 164 Expected (out) size: 2
Chris@1022 165 Loc: [o/../TestStringBits.h(65)]
Chris@1022 166 PASS : TestStringBits::dnested()
Chris@1022 167 PASS : TestStringBits::snested()
Chris@1022 168 PASS : TestStringBits::snested2()
Chris@1022 169 PASS : TestStringBits::qquoted()
Chris@1022 170 FAIL! : TestStringBits::multispace() Compared lists differ at index 1.
Chris@1022 171 Actual (StringBits::splitQuoted(in, ' ')): " "
Chris@1022 172 Expected (out): "'"
Chris@1022 173 Loc: [o/../TestStringBits.h(100)]
Chris@1022 174 FAIL! : TestStringBits::qcommas() Compared lists have different sizes.
Chris@1022 175 Actual (StringBits::splitQuoted(in, ',')) size: 4
Chris@1022 176 Expected (out) size: 3
Chris@1022 177 Loc: [o/../TestStringBits.h(107)]
Chris@1022 178 PASS : TestStringBits::cleanupTestCase()
Chris@1022 179 Totals: 10 passed, 3 failed, 0 skipped
Chris@1022 180 */
Chris@1022 181
Chris@1022 182 /*curr
Chris@1022 183 PASS : TestStringBits::initTestCase()
Chris@1022 184 PASS : TestStringBits::simple()
Chris@1022 185 PASS : TestStringBits::dquoted()
Chris@1022 186 PASS : TestStringBits::squoted()
Chris@1022 187 PASS : TestStringBits::descaped()
Chris@1022 188 FAIL! : TestStringBits::sescaped() Compared lists have different sizes.
Chris@1022 189 Actual (StringBits::splitQuoted(in, ' ')) size: 3
Chris@1022 190 Expected (out) size: 2
Chris@1022 191 Loc: [o/../TestStringBits.h(65)]
Chris@1022 192 PASS : TestStringBits::dnested()
Chris@1022 193 PASS : TestStringBits::snested()
Chris@1022 194 PASS : TestStringBits::snested2()
Chris@1022 195 PASS : TestStringBits::qquoted()
Chris@1022 196 FAIL! : TestStringBits::multispace() Compared lists have different sizes.
Chris@1022 197 Actual (StringBits::splitQuoted(in, ' ')) size: 5
Chris@1022 198 Expected (out) size: 6
Chris@1022 199 Loc: [o/../TestStringBits.h(100)]
Chris@1022 200 PASS : TestStringBits::qcommas()
Chris@1022 201 PASS : TestStringBits::cleanupTestCase()
Chris@1022 202 Totals: 11 passed, 2 failed, 0 skipped
Chris@1022 203 */