comparison data/model/test/TestSparseModels.h @ 1674:69ab62d378bf osc-script

Ensure image & text models get the proper attribute names (which are not the same as the default event ones)
author Chris Cannam
date Wed, 27 Mar 2019 16:06:35 +0000
parents a77a7e8c085c
children f97d64b8674f
comparison
equal deleted inserted replaced
1673:dfcd05e8bd2f 1674:69ab62d378bf
17 17
18 #include "../SparseOneDimensionalModel.h" 18 #include "../SparseOneDimensionalModel.h"
19 #include "../NoteModel.h" 19 #include "../NoteModel.h"
20 #include "../TextModel.h" 20 #include "../TextModel.h"
21 #include "../PathModel.h" 21 #include "../PathModel.h"
22 #include "../ImageModel.h"
22 23
23 #include <QObject> 24 #include <QObject>
24 #include <QtTest> 25 #include <QtTest>
25 26
26 #include <iostream> 27 #include <iostream>
104 } 105 }
105 106
106 void s1d_xml() { 107 void s1d_xml() {
107 SparseOneDimensionalModel m(100, 10, false); 108 SparseOneDimensionalModel m(100, 10, false);
108 m.setObjectName("This \"&\" that"); 109 m.setObjectName("This \"&\" that");
109 Event p1(20), p2(20), p3(50); 110 Event p1(20);
110 p2 = p2.withLabel("Label &'\">"); 111 Event p2(20, "Label &'\">");
112 Event p3(50, 12.4f, 16, ""); // value + duration should not be saved
111 m.add(p1); 113 m.add(p1);
112 m.add(p2); 114 m.add(p2);
113 m.add(p3); 115 m.add(p3);
114 QString xml; 116 QString xml;
115 QTextStream str(&xml, QIODevice::WriteOnly); 117 QTextStream str(&xml, QIODevice::WriteOnly);
116 m.toXml(str); 118 m.toXml(str);
117 str.flush(); 119 str.flush();
118 QString expected = 120 QString expected =
119 "<model id='1' name='This &quot;&amp;&quot; that' sampleRate='100' start='20' end='60' type='sparse' dimensions='1' resolution='10' notifyOnAdd='true' dataset='0' />\n" 121 "<model id='1' name='This &quot;&amp;&quot; that' sampleRate='100' start='20' end='60' type='sparse' dimensions='1' resolution='10' notifyOnAdd='true' dataset='0' />\n"
120 "<dataset id='0' dimensions='1'>\n" 122 "<dataset id='0' dimensions='1'>\n"
121 " <point frame='20' label='' />\n" 123 " <point frame='20' />\n"
122 " <point frame='20' label='Label &amp;&apos;&quot;&gt;' />\n" 124 " <point frame='20' label='Label &amp;&apos;&quot;&gt;' />\n"
123 " <point frame='50' label='' />\n" 125 " <point frame='50' />\n"
124 "</dataset>\n"; 126 "</dataset>\n";
125 expected.replace("\'", "\""); 127 expected.replace("\'", "\"");
126 if (xml != expected) { 128 if (xml != expected) {
127 cerr << "Obtained xml:\n" << xml 129 cerr << "Obtained xml:\n" << xml
128 << "\nExpected:\n" << expected << endl; 130 << "\nExpected:\n" << expected << endl;
224 TextModel m(100, 10, false); 226 TextModel m(100, 10, false);
225 Event p1(20, 1.0f, "text 1"); 227 Event p1(20, 1.0f, "text 1");
226 Event p2(20, 0.0f, "text 2"); 228 Event p2(20, 0.0f, "text 2");
227 Event p3(50, 0.3f, "text 3"); 229 Event p3(50, 0.3f, "text 3");
228 m.add(p1); 230 m.add(p1);
229 m.add(p2); 231 m.add(p2.withLevel(0.8f));
230 m.add(p3); 232 m.add(p3);
231 QString xml; 233 QString xml;
232 QTextStream str(&xml, QIODevice::WriteOnly); 234 QTextStream str(&xml, QIODevice::WriteOnly);
233 m.toXml(str); 235 m.toXml(str);
234 str.flush(); 236 str.flush();
274 << "\nExpected:\n" << expected << endl; 276 << "\nExpected:\n" << expected << endl;
275 } 277 }
276 QCOMPARE(xml, expected); 278 QCOMPARE(xml, expected);
277 } 279 }
278 280
281 void image_xml() {
282 ImageModel m(100, 10, false);
283 Event p1(20, 30, 40, "a label"); // value + duration should not be saved
284 m.add(p1.withURI("/path/to/thing.png").withLevel(0.8f));
285 QString xml;
286 QTextStream str(&xml, QIODevice::WriteOnly);
287 m.toXml(str);
288 str.flush();
289
290 QString expected =
291 "<model id='4' name='' sampleRate='100' start='20' end='30' type='sparse' dimensions='1' resolution='10' notifyOnAdd='true' dataset='2' subtype='image' />\n"
292 "<dataset id='2' dimensions='1'>\n"
293 " <point frame='20' label='a label' image='/path/to/thing.png' />\n"
294 "</dataset>\n";
295 expected.replace("\'", "\"");
296 if (xml != expected) {
297 cerr << "Obtained xml:\n" << xml
298 << "\nExpected:\n" << expected << endl;
299 }
300 QCOMPARE(xml, expected);
301 }
302
279 }; 303 };
280 304
281 #endif 305 #endif