comparison data/model/test/TestSparseModels.h @ 1677:f97d64b8674f single-point

Make XmlExportables store their export IDs and always obtain a new one, avoiding reuse when an object is allocated at the same heap location as a previous one. This makes the ID system stable enough to be used in the export tests.
author Chris Cannam
date Thu, 28 Mar 2019 11:55:02 +0000
parents 69ab62d378bf
children 0d89abd631ac
comparison
equal deleted inserted replaced
1676:3b51df7695a4 1677:f97d64b8674f
25 #include <QtTest> 25 #include <QtTest>
26 26
27 #include <iostream> 27 #include <iostream>
28 28
29 using namespace std; 29 using namespace std;
30
31 // NB model & dataset IDs in the export tests are incremental,
32 // depending on how many have been exported in previous tests - so
33 // when adding or removing tests we may occasionally need to update
34 // the IDs in other ones
30 35
31 class TestSparseModels : public QObject 36 class TestSparseModels : public QObject
32 { 37 {
33 Q_OBJECT 38 Q_OBJECT
34 39
116 QString xml; 121 QString xml;
117 QTextStream str(&xml, QIODevice::WriteOnly); 122 QTextStream str(&xml, QIODevice::WriteOnly);
118 m.toXml(str); 123 m.toXml(str);
119 str.flush(); 124 str.flush();
120 QString expected = 125 QString expected =
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" 126 "<model id='2' name='This &quot;&amp;&quot; that' sampleRate='100' start='20' end='60' type='sparse' dimensions='1' resolution='10' notifyOnAdd='true' dataset='1' />\n"
122 "<dataset id='0' dimensions='1'>\n" 127 "<dataset id='1' dimensions='1'>\n"
123 " <point frame='20' />\n" 128 " <point frame='20' />\n"
124 " <point frame='20' label='Label &amp;&apos;&quot;&gt;' />\n" 129 " <point frame='20' label='Label &amp;&apos;&quot;&gt;' />\n"
125 " <point frame='50' />\n" 130 " <point frame='50' />\n"
126 "</dataset>\n"; 131 "</dataset>\n";
127 expected.replace("\'", "\""); 132 expected.replace("\'", "\"");
200 m.add(p3); 205 m.add(p3);
201 QString xml; 206 QString xml;
202 QTextStream str(&xml, QIODevice::WriteOnly); 207 QTextStream str(&xml, QIODevice::WriteOnly);
203 m.toXml(str); 208 m.toXml(str);
204 str.flush(); 209 str.flush();
205
206 //!!! This is not guaranteed - object export ids are in order
207 //!!! of model pointer value, which is not trustworthy -
208 //!!! replace them with something else
209 210
210 QString expected = 211 QString expected =
211 "<model id='3' name='' sampleRate='100' start='20' end='80' type='sparse' dimensions='3' resolution='10' notifyOnAdd='true' dataset='2' subtype='note' valueQuantization='0' minimum='123.4' maximum='126.3' units='Hz' />\n" 212 "<model id='4' name='' sampleRate='100' start='20' end='80' type='sparse' dimensions='3' resolution='10' notifyOnAdd='true' dataset='3' subtype='note' valueQuantization='0' minimum='123.4' maximum='126.3' units='Hz' />\n"
212 "<dataset id='2' dimensions='3'>\n" 213 "<dataset id='3' dimensions='3'>\n"
213 " <point frame='20' value='124.3' duration='10' level='0.9' label='note 2' />\n" 214 " <point frame='20' value='124.3' duration='10' level='0.9' label='note 2' />\n"
214 " <point frame='20' value='123.4' duration='20' level='0.8' label='note 1' />\n" 215 " <point frame='20' value='123.4' duration='20' level='0.8' label='note 1' />\n"
215 " <point frame='50' value='126.3' duration='30' level='0.9' label='note 3' />\n" 216 " <point frame='50' value='126.3' duration='30' level='0.9' label='note 3' />\n"
216 "</dataset>\n"; 217 "</dataset>\n";
217 expected.replace("\'", "\""); 218 expected.replace("\'", "\"");
234 QTextStream str(&xml, QIODevice::WriteOnly); 235 QTextStream str(&xml, QIODevice::WriteOnly);
235 m.toXml(str); 236 m.toXml(str);
236 str.flush(); 237 str.flush();
237 238
238 QString expected = 239 QString expected =
239 "<model id='5' name='' sampleRate='100' start='20' end='80' type='sparse' dimensions='2' resolution='10' notifyOnAdd='true' dataset='4' subtype='text' />\n" 240 "<model id='6' name='' sampleRate='100' start='20' end='60' type='sparse' dimensions='2' resolution='10' notifyOnAdd='true' dataset='5' subtype='text' />\n"
240 "<dataset id='4' dimensions='2'>\n" 241 "<dataset id='5' dimensions='2'>\n"
241 " <point frame='20' height='0' label='text 2' />\n" 242 " <point frame='20' height='0' label='text 2' />\n"
242 " <point frame='20' height='1' label='text 1' />\n" 243 " <point frame='20' height='1' label='text 1' />\n"
243 " <point frame='50' height='0.3' label='text 3' />\n" 244 " <point frame='50' height='0.3' label='text 3' />\n"
244 "</dataset>\n"; 245 "</dataset>\n";
245 expected.replace("\'", "\""); 246 expected.replace("\'", "\"");
262 QTextStream str(&xml, QIODevice::WriteOnly); 263 QTextStream str(&xml, QIODevice::WriteOnly);
263 m.toXml(str); 264 m.toXml(str);
264 str.flush(); 265 str.flush();
265 266
266 QString expected = 267 QString expected =
267 "<model id='7' name='' sampleRate='100' start='20' end='80' type='sparse' dimensions='2' resolution='10' notifyOnAdd='true' dataset='4' subtype='path' />\n" 268 "<model id='7' name='' sampleRate='100' start='20' end='60' type='sparse' dimensions='2' resolution='10' notifyOnAdd='true' dataset='7' subtype='path' />\n"
268 "<dataset id='6' dimensions='2'>\n" 269 "<dataset id='7' dimensions='2'>\n"
269 " <point frame='20' mapframe='30' />\n" 270 " <point frame='20' mapframe='30' />\n"
270 " <point frame='40' mapframe='60' />\n" 271 " <point frame='40' mapframe='60' />\n"
271 " <point frame='50' mapframe='49' />\n" 272 " <point frame='50' mapframe='49' />\n"
272 "</dataset>\n"; 273 "</dataset>\n";
273 expected.replace("\'", "\""); 274 expected.replace("\'", "\"");
286 QTextStream str(&xml, QIODevice::WriteOnly); 287 QTextStream str(&xml, QIODevice::WriteOnly);
287 m.toXml(str); 288 m.toXml(str);
288 str.flush(); 289 str.flush();
289 290
290 QString expected = 291 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 "<model id='9' name='' sampleRate='100' start='20' end='30' type='sparse' dimensions='1' resolution='10' notifyOnAdd='true' dataset='8' subtype='image' />\n"
292 "<dataset id='2' dimensions='1'>\n" 293 "<dataset id='8' dimensions='1'>\n"
293 " <point frame='20' label='a label' image='/path/to/thing.png' />\n" 294 " <point frame='20' label='a label' image='/path/to/thing.png' />\n"
294 "</dataset>\n"; 295 "</dataset>\n";
295 expected.replace("\'", "\""); 296 expected.replace("\'", "\"");
296 if (xml != expected) { 297 if (xml != expected) {
297 cerr << "Obtained xml:\n" << xml 298 cerr << "Obtained xml:\n" << xml