comparison data/model/test/TestSparseModels.h @ 1661:353a2d15f213 single-point

Update TextModel
author Chris Cannam
date Fri, 22 Mar 2019 11:04:51 +0000
parents 8bf3a52a1604
children 628ffbb05856
comparison
equal deleted inserted replaced
1660:b234d4d011df 1661:353a2d15f213
15 #ifndef TEST_SPARSE_MODELS_H 15 #ifndef TEST_SPARSE_MODELS_H
16 #define TEST_SPARSE_MODELS_H 16 #define TEST_SPARSE_MODELS_H
17 17
18 #include "../SparseOneDimensionalModel.h" 18 #include "../SparseOneDimensionalModel.h"
19 #include "../NoteModel.h" 19 #include "../NoteModel.h"
20 #include "../TextModel.h"
20 21
21 #include <QObject> 22 #include <QObject>
22 #include <QtTest> 23 #include <QtTest>
23 24
24 #include <iostream> 25 #include <iostream>
215 cerr << "Obtained xml:\n" << xml 216 cerr << "Obtained xml:\n" << xml
216 << "\nExpected:\n" << expected << endl; 217 << "\nExpected:\n" << expected << endl;
217 } 218 }
218 QCOMPARE(xml, expected); 219 QCOMPARE(xml, expected);
219 } 220 }
221
222 void text_xml() {
223 TextModel m(100, 10, false);
224 Event p1(20, 1.0f, "text 1");
225 Event p2(20, 0.0f, "text 2");
226 Event p3(50, 0.3f, "text 3");
227 m.add(p1);
228 m.add(p2);
229 m.add(p3);
230 QString xml;
231 QTextStream str(&xml, QIODevice::WriteOnly);
232 m.toXml(str);
233 str.flush();
234
235 QString expected =
236 "<model id='5' name='' sampleRate='100' start='20' end='80' type='sparse' dimensions='2' resolution='10' notifyOnAdd='true' dataset='4' subtype='text' />\n"
237 "<dataset id='4' dimensions='2'>\n"
238 " <point frame='20' height='0' label='text 2' />\n"
239 " <point frame='20' height='1' label='text 1' />\n"
240 " <point frame='50' height='0.3' label='text 3' />\n"
241 "</dataset>\n";
242 expected.replace("\'", "\"");
243 if (xml != expected) {
244 cerr << "Obtained xml:\n" << xml
245 << "\nExpected:\n" << expected << endl;
246 }
247 QCOMPARE(xml, expected);
248 }
220 249
221 }; 250 };
222 251
223 #endif 252 #endif