3a01a933 |
1 | // Created on: 2004-03-05 |
2 | // Created by: Mikhail KUZMITCHEV |
3 | // Copyright (c) 2004-2014 OPEN CASCADE SAS |
4 | // |
5 | // This file is part of Open CASCADE Technology software library. |
6 | // |
7 | // This library is free software; you can redistribute it and/or modify it under |
8 | // the terms of the GNU Lesser General Public License version 2.1 as published |
9 | // by the Free Software Foundation, with special exception defined in the file |
10 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
11 | // distribution for complete text of the license and disclaimer of any warranty. |
12 | // |
13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. |
15 | |
16 | #include <QANCollection.hxx> |
17 | #include <QANCollection_Common.hxx> |
18 | |
19 | #include <Draw.hxx> |
20 | #include <Draw_Interpretor.hxx> |
21 | |
22 | #include <gp_Pnt.hxx> |
23 | |
985aed12 |
24 | #include <Precision.hxx> |
25 | |
e3a6386d |
26 | #include <NCollection_Vector.hxx> |
27 | |
3a01a933 |
28 | #define ItemType gp_Pnt |
29 | #define Key1Type Standard_Real |
30 | #define Key2Type Standard_Integer |
31 | |
32 | #include <NCollection_DefineArray1.hxx> |
33 | #include <NCollection_DefineHArray1.hxx> |
34 | ////////////////////////////////DEFINE_ARRAY1(QANCollection_Array1,QANCollection_BaseCol,ItemType) |
35 | ////////////////////////////////DEFINE_HARRAY1(QANCollection_HArray1,QANCollection_Array1) |
36 | DEFINE_ARRAY1(QANCollection_Array1Func,QANCollection_BaseColFunc,ItemType) |
37 | DEFINE_HARRAY1(QANCollection_HArray1Func,QANCollection_Array1Func) |
38 | IMPLEMENT_HARRAY1(QANCollection_HArray1Func) |
39 | |
40 | #include <NCollection_DefineArray2.hxx> |
41 | #include <NCollection_DefineHArray2.hxx> |
42 | ////////////////////////////////DEFINE_ARRAY2(QANCollection_Array2,QANCollection_BaseCol,ItemType) |
43 | ////////////////////////////////DEFINE_HARRAY2(QANCollection_HArray2,QANCollection_Array2) |
44 | DEFINE_ARRAY2(QANCollection_Array2Func,QANCollection_BaseColFunc,ItemType) |
45 | DEFINE_HARRAY2(QANCollection_HArray2Func,QANCollection_Array2Func) |
46 | IMPLEMENT_HARRAY2(QANCollection_HArray2Func) |
47 | |
48 | #include <NCollection_DefineMap.hxx> |
49 | #include <NCollection_DefineDataMap.hxx> |
50 | #include <NCollection_DefineDoubleMap.hxx> |
51 | #include <NCollection_DefineIndexedMap.hxx> |
52 | #include <NCollection_DefineIndexedDataMap.hxx> |
53 | ////////////////////////////////DEFINE_MAP(QANCollection_Map,QANCollection_Key1BaseCol,Key1Type) |
54 | ////////////////////////////////DEFINE_DATAMAP(QANCollection_DataMap,QANCollection_BaseCol,Key1Type,ItemType) |
55 | ////////////////////////////////DEFINE_DOUBLEMAP(QANCollection_DoubleMap,QANCollection_Key2BaseCol,Key1Type,Key2Type) |
56 | ////////////////////////////////DEFINE_INDEXEDMAP(QANCollection_IndexedMap,QANCollection_Key1BaseCol,Key1Type) |
57 | ////////////////////////////////DEFINE_INDEXEDDATAMAP(QANCollection_IDMap,QANCollection_BaseCol,Key1Type,ItemType) |
58 | DEFINE_MAP(QANCollection_MapFunc,QANCollection_Key1BaseColFunc,Key1Type) |
59 | DEFINE_DATAMAP(QANCollection_DataMapFunc,QANCollection_BaseColFunc,Key1Type,ItemType) |
60 | DEFINE_DOUBLEMAP(QANCollection_DoubleMapFunc,QANCollection_Key2BaseColFunc,Key1Type,Key2Type) |
61 | DEFINE_INDEXEDMAP(QANCollection_IndexedMapFunc,QANCollection_Key1BaseColFunc,Key1Type) |
62 | DEFINE_INDEXEDDATAMAP(QANCollection_IDMapFunc,QANCollection_BaseColFunc,Key1Type,ItemType) |
63 | |
64 | #include <NCollection_DefineList.hxx> |
65 | ////////////////////////////////DEFINE_LIST(QANCollection_List,QANCollection_BaseCol,ItemType) |
66 | DEFINE_LIST(QANCollection_ListFunc,QANCollection_BaseColFunc,ItemType) |
67 | |
68 | #include <NCollection_DefineSequence.hxx> |
69 | #include <NCollection_DefineHSequence.hxx> |
70 | ////////////////////////////////DEFINE_SEQUENCE(QANCollection_Sequence,QANCollection_BaseCol,ItemType) |
71 | ////////////////////////////////DEFINE_HSEQUENCE(QANCollection_HSequence,QANCollection_Sequence) |
72 | DEFINE_SEQUENCE(QANCollection_SequenceFunc,QANCollection_BaseColFunc,ItemType) |
73 | DEFINE_HSEQUENCE(QANCollection_HSequenceFunc,QANCollection_SequenceFunc) |
74 | IMPLEMENT_HSEQUENCE(QANCollection_HSequenceFunc) |
75 | |
76 | // HashCode and IsEquel must be defined for key types of maps |
77 | Standard_Integer HashCode(const gp_Pnt thePnt, int theUpper) |
78 | { |
79 | return HashCode(thePnt.X(),theUpper); |
80 | } |
81 | |
82 | Standard_Boolean IsEqual(const gp_Pnt& theP1, const gp_Pnt& theP2) |
83 | { |
84 | return theP1.IsEqual(theP2,gp::Resolution()); |
85 | } |
86 | |
87 | ////////////////////////////////void printCollection (QANCollection_Key1BaseCol& aColl, |
88 | template <class Coll> |
89 | void printCollection (Coll& aColl, const char * str) |
90 | { |
91 | printf ("%s:\n",str); |
92 | Standard_Integer iSize = aColl.Size(); |
93 | ////////////////////////////////QANCollection_Key1BaseCol::Iterator& anIter = aColl.CreateIterator(); |
94 | typename Coll::Iterator anIter (aColl); |
95 | if (!anIter.More()) |
96 | { |
97 | if (iSize==0) |
98 | printf (" <Empty collection>\n"); |
99 | else |
100 | printf ("Error : empty collection has size==%d",iSize); |
101 | } |
102 | else |
103 | { |
104 | printf (" Size==%d\n",iSize); |
105 | for (; anIter.More(); anIter.Next()) |
106 | PrintItem(anIter.Value()); |
107 | } |
108 | } |
109 | |
110 | ////////////////////////////////void AssignCollection (QANCollection_BaseCol& aCollSrc, |
111 | //////////////////////////////// QANCollection_BaseCol& aCollDst) |
112 | template <class Coll> |
113 | void AssignCollection (Coll& aCollSrc, Coll& aCollDst) |
114 | { |
115 | printCollection (aCollSrc,"Source collection"); |
116 | aCollDst.Assign(aCollSrc); |
117 | printCollection (aCollDst,"Target collection"); |
118 | } |
119 | |
120 | // ===================== Test methods of Array1 type ========================== |
121 | ////////////////////////////////void TestArray1 (QANCollection_Array1& theA1) |
122 | static void TestArray1 (QANCollection_Array1Func& theA1) |
123 | { |
124 | // Bounds |
125 | Standard_Integer iLow=theA1.Lower(); |
126 | Standard_Integer iUpp=theA1.Upper(); |
127 | Standard_Integer i; |
128 | |
129 | printf ("Info: testing Array1(%d,%d), %s\n", |
130 | iLow, iUpp, (theA1.IsDeletable()?"deletable":"frozen")); |
131 | // C-array constructor, Length, Init |
132 | ItemType anItem; |
133 | Random(anItem); |
134 | theA1.Init (anItem); |
135 | ItemType * rBlock = new ItemType[theA1.Length()]; |
136 | ////////////////////////////////QANCollection_Array1 aCArr(*rBlock, iLow-100, iUpp-100); |
137 | QANCollection_Array1Func aCArr(*rBlock, iLow-100, iUpp-100); |
138 | printf (" created the same sized preallocated array (%d,%d), %s\n", |
139 | aCArr.Lower(),aCArr.Upper(),(aCArr.IsDeletable()?"deletable":"frozen")); |
140 | // *Value, operator() |
141 | for (i=iLow+1; i<iUpp; i++) |
142 | { |
143 | Random (aCArr.ChangeValue (i-101)); |
144 | aCArr.SetValue (i-100, ItemType(aCArr.Value(i-101))); |
145 | aCArr(i-99) = aCArr(i-100) = aCArr(i-101); |
146 | } |
147 | // Handle, copy constructor (including operator=) |
148 | ////////////////////////////////Handle(QANCollection_HArray1) aHa = new QANCollection_HArray1(aCArr); |
149 | Handle(QANCollection_HArray1Func) aHa = new QANCollection_HArray1Func(aCArr); |
150 | // Assign |
151 | AssignCollection (aHa->ChangeArray1(), theA1); |
152 | } |
153 | |
154 | // ===================== Test methods of Array2 type ========================== |
155 | ////////////////////////////////void TestArray2 (QANCollection_Array2& theA2) |
156 | static void TestArray2 (QANCollection_Array2Func& theA2) |
157 | { |
158 | // Bounds |
159 | Standard_Integer iLR=theA2.LowerRow(), iLC=theA2.LowerCol(); |
160 | Standard_Integer iUR=theA2.UpperRow(), iUC=theA2.UpperCol(); |
161 | Standard_Integer i,j; |
162 | |
163 | printf ("Info: testing Array2 (%d,%d)(%d,%d), %s\n", |
164 | iLR, iUR, iLC, iUC, (theA2.IsDeletable()?"deletable":"frozen")); |
165 | // C-array constructor, Length, Init, RowLength, ColLength |
166 | ItemType anItem; |
167 | Random(anItem); |
168 | theA2.Init (anItem); |
169 | ItemType * rBlock = new ItemType[theA2.Length()]; |
170 | ////////////////////////////////QANCollection_Array2 aCArr(*rBlock, iLR-100, iUR-100, iLC, iUC); |
171 | QANCollection_Array2Func aCArr(*rBlock, iLR-100, iUR-100, iLC, iUC); |
172 | printf (" created the same sized preallocated array (%d*%d), %s\n", |
173 | aCArr.RowLength(), aCArr.ColLength(), |
174 | (aCArr.IsDeletable()?"deletable":"frozen")); |
175 | // *Value, operator() |
176 | for (i=iLR+1; i<iUR; i++) |
177 | { |
178 | for (j=iLC; j<=iUC; j++) |
179 | { |
180 | Random (aCArr.ChangeValue (i-101, j)); |
181 | aCArr.SetValue (i-100, j, |
182 | ItemType(aCArr.Value(i-101,j))); |
183 | aCArr(i-99,j) = aCArr(i-100,j) = aCArr(i-101,j); |
184 | } |
185 | } |
186 | // Handle, copy constructor (including operator=) |
187 | ////////////////////////////////Handle(QANCollection_HArray2) aHa = new QANCollection_HArray2(aCArr); |
188 | Handle(QANCollection_HArray2Func) aHa = new QANCollection_HArray2Func(aCArr); |
189 | // Assign |
190 | AssignCollection (aHa->ChangeArray2(), theA2); |
191 | } |
192 | |
193 | // ===================== Test methods of List type ========================== |
194 | ////////////////////////////////void TestList (QANCollection_List& theL) |
195 | static void TestList (QANCollection_ListFunc& theL) |
196 | { |
197 | // Extent |
198 | Standard_Integer iExt=theL.Extent(); |
199 | Standard_Integer i; |
200 | |
201 | printf ("Info: testing List(%d)\n", iExt); |
202 | // Append(2), Prepend(2), InsertBefore(2), InsertAfter(2), |
203 | // Remove, RemoveFirst, First, Last |
204 | ItemType anItem; |
205 | ////////////////////////////////QANCollection_List aL, aL1; |
206 | QANCollection_ListFunc aL, aL1; |
207 | for (i=0; i<4; i++) |
208 | { |
209 | Random (anItem); |
210 | aL.Append (anItem); // #1 |
211 | aL.Append (aL1); // #2 |
212 | Random (anItem); |
213 | aL1.Prepend (anItem); // #3 |
214 | aL1.Prepend (aL); // #4 |
215 | ////////////////////////////////QANCollection_List::Iterator anI(theL); |
216 | QANCollection_ListFunc::Iterator anI(theL); |
217 | if (anI.More()) |
218 | { |
219 | Random (anItem); |
220 | theL.InsertBefore (anItem, anI); // #5 |
221 | theL.InsertBefore (aL1, anI); // #6 |
222 | Random (anItem); |
223 | theL.InsertAfter (anItem, anI); // #7 |
224 | theL.InsertAfter (aL, anI); // #8 |
225 | theL.Remove (anI); // #9 |
226 | if (theL.Extent() > 0) |
227 | theL.RemoveFirst(); // #10 |
228 | } |
229 | else |
230 | { |
231 | theL.Prepend (anItem); |
232 | PrintItem(theL.First()); |
233 | PrintItem(theL.Last()); |
234 | } |
235 | } |
236 | // Copy constructor + operator= |
237 | ////////////////////////////////aL = QANCollection_List(theL); |
238 | aL = QANCollection_ListFunc(theL); |
239 | |
240 | // Assign |
241 | AssignCollection (theL, aL); |
242 | |
243 | // Clear |
244 | aL.Clear(); |
245 | } |
246 | |
247 | // ===================== Test methods of Sequence type ======================== |
248 | ////////////////////////////////void TestSequence (QANCollection_Sequence& theS) |
249 | static void TestSequence (QANCollection_SequenceFunc& theS) |
250 | { |
251 | Standard_Integer i; |
252 | |
253 | printf ("Info: testing Sequence\n"); |
254 | // Append(2) |
255 | ItemType anItem; |
256 | ////////////////////////////////QANCollection_Sequence aS, aS1; |
257 | QANCollection_SequenceFunc aS, aS1; |
258 | // Append(2), Prepend(2), InsertBefore(2), InsertAfter(2), |
259 | // Remove, RemoveFirst, First, Last |
260 | for (i=0; i<4; i++) |
261 | { |
262 | Random (anItem); |
263 | aS.Append (anItem); // #1 |
264 | aS.Append (aS1); // #2 |
265 | Random (anItem); |
266 | aS1.Prepend (anItem); // #3 |
267 | aS1.Prepend (aS); // #4 |
268 | if (theS.Length() > 0) |
269 | { |
270 | Random (anItem); |
271 | theS.InsertBefore (1, anItem); // #5 |
272 | theS.InsertBefore (2, aS1); // #6 |
273 | Random (anItem); |
274 | theS.InsertAfter (1, anItem); // #7 |
275 | theS.InsertAfter (2, aS); // #8 |
276 | theS.Remove (1); // #9 |
277 | if (theS.Length() > 0) |
278 | theS.Remove(1); // #10 |
279 | } |
280 | else |
281 | { |
282 | theS.Prepend (anItem); |
283 | PrintItem(theS.First()); |
284 | PrintItem(theS.Last()); |
285 | } |
286 | } |
287 | |
288 | // () |
289 | PrintItem(theS(1)); |
290 | |
291 | // Handle, Split |
292 | ////////////////////////////////Handle(QANCollection_HSequence) aHS = new QANCollection_HSequence(aS1); |
293 | Handle(QANCollection_HSequenceFunc) aHS = new QANCollection_HSequenceFunc(aS1); |
294 | theS.Split (3, aHS->ChangeSequence()); |
295 | |
296 | // Assign |
297 | AssignCollection (theS, aS); |
298 | |
299 | // Clear |
300 | aS.Clear(); |
301 | } |
302 | |
303 | // ===================== Test methods of Map type ============================= |
304 | ////////////////////////////////void TestMap (QANCollection_Map& theM) |
305 | static void TestMap (QANCollection_MapFunc& theM) |
306 | { |
307 | // Extent |
308 | Standard_Integer iExt=theM.Extent(); |
309 | Standard_Integer i; |
310 | |
311 | printf ("Info: testing Map(l=%d)\n", iExt); |
312 | theM.Statistics(cout); |
313 | // Resize |
314 | theM.ReSize(8); |
315 | theM.Statistics(cout); |
316 | cout.flush(); |
317 | // Constructor |
318 | ////////////////////////////////QANCollection_Map aM; |
319 | QANCollection_MapFunc aM; |
320 | // Add |
321 | Key1Type aKey; |
322 | for (i=0; i<8; i++) |
323 | { |
324 | Random (aKey); |
325 | aM.Add (aKey); |
326 | } |
327 | // Contains, Remove |
328 | if (!aM.Contains(aKey)) |
329 | { |
330 | printf("Error : map says that it does not contain its key "); |
331 | PrintItem(aKey); |
332 | } |
333 | else |
334 | { |
335 | aM.Remove(aKey); |
336 | printf(" successfully removed item, l=%d\n", aM.Size()); |
337 | } |
338 | // Copy constructor (including operator=) |
339 | ////////////////////////////////QANCollection_Map aM2 = QANCollection_Map(aM); |
340 | QANCollection_MapFunc aM2 = QANCollection_MapFunc(aM); |
341 | // Assign |
342 | AssignCollection (aM2,theM); |
343 | |
344 | // Clear |
345 | aM.Clear(); |
346 | } |
347 | |
348 | // ===================== Test methods of DataMap type ========================= |
349 | ////////////////////////////////void TestDataMap (QANCollection_DataMap& theM) |
350 | static void TestDataMap (QANCollection_DataMapFunc& theM) |
351 | { |
352 | // Extent |
353 | Standard_Integer iExt=theM.Extent(); |
354 | Standard_Integer i; |
355 | |
356 | printf ("Info: testing DataMap(l=%d)\n", iExt); |
357 | theM.Statistics(cout); |
358 | // Resize |
359 | theM.ReSize(8); |
360 | theM.Statistics(cout); |
361 | cout.flush(); |
362 | // Constructor |
363 | ////////////////////////////////QANCollection_DataMap aM; |
364 | QANCollection_DataMapFunc aM; |
365 | // Bind, Find, ChangeFind, () |
366 | Key1Type aKey; |
367 | ItemType anItem; |
368 | for (i=0; i<8; i++) |
369 | { |
370 | Random (aKey); |
371 | Random (anItem); |
372 | aM.Bind (aKey, anItem); |
373 | PrintItem(aM.Find(aKey)); |
374 | Random(aM(aKey)); |
375 | } |
376 | // IsBound, UnBind |
377 | if (!aM.IsBound(aKey)) |
378 | { |
379 | printf("Error : map says that it does not contain its key "); |
380 | PrintItem(aKey); |
381 | } |
382 | else |
383 | { |
384 | aM.UnBind(aKey); |
385 | printf(" successfully unbound the key, l=%d\n", aM.Size()); |
386 | } |
387 | // Copy constructor (including operator=) |
388 | ////////////////////////////////theM = QANCollection_DataMap(aM); |
389 | theM = QANCollection_DataMapFunc(aM); |
390 | // Assign - prohibited |
391 | // AssignCollection (aM2,theM); |
392 | printCollection (theM, "DataMap:"); |
393 | |
394 | // Clear |
395 | aM.Clear(); |
396 | } |
397 | |
398 | |
399 | // ===================== Test methods of DoubleMap type ======================= |
400 | ////////////////////////////////void TestDoubleMap (QANCollection_DoubleMap& theM) |
401 | static void TestDoubleMap (QANCollection_DoubleMapFunc& theM) |
402 | { |
403 | // Extent |
404 | Standard_Integer iExt=theM.Extent(); |
405 | Standard_Integer i; |
406 | |
407 | printf ("Info: testing DoubleMap(l=%d)\n", iExt); |
408 | theM.Statistics(cout); |
409 | // Resize |
410 | theM.ReSize(8); |
411 | theM.Statistics(cout); |
412 | cout.flush(); |
413 | // Constructor |
414 | ////////////////////////////////QANCollection_DoubleMap aM; |
415 | QANCollection_DoubleMapFunc aM; |
416 | // Bind, Find?, |
417 | Key1Type aKey1; |
418 | Key2Type aKey2; |
419 | for (i=0; i<8; i++) |
420 | { |
421 | Random (aKey1); |
422 | Random (aKey2); |
423 | aM.Bind (aKey1, aKey2); |
424 | PrintItem(aM.Find1(aKey1)); |
425 | if (!aM.IsBound1(aKey1)) |
426 | { |
427 | printf("Error : map says that it does not contain its key "); |
428 | PrintItem(aKey1); |
429 | } |
430 | PrintItem(aM.Find2(aKey2)); |
431 | if (!aM.IsBound2(aKey2)) |
432 | { |
433 | printf("Error : map says that it does not contain its key "); |
434 | PrintItem(aKey2); |
435 | } |
436 | } |
437 | // AreBound, UnBind |
438 | if (!aM.AreBound(aKey1,aKey2)) |
439 | { |
440 | printf("Error : map says that it does not contain its keys "); |
441 | PrintItem(aKey1); |
442 | PrintItem(aKey2); |
443 | } |
444 | else |
445 | { |
446 | if (aM.UnBind2(aKey2)) |
447 | printf(" successfully unbound the key, l=%d\n", aM.Size()); |
448 | if (aM.UnBind1(aKey1)) |
449 | printf("Error : unbound both keys?!\n"); |
450 | } |
451 | // Copy constructor (including operator=) |
452 | ////////////////////////////////theM = QANCollection_DoubleMap(aM); |
453 | theM = QANCollection_DoubleMapFunc(aM); |
454 | // Assign - prohibited |
455 | // AssignCollection (aM2,theM); |
456 | printCollection (theM, "DoubleMap:"); |
457 | |
458 | // Clear |
459 | aM.Clear(); |
460 | } |
461 | |
462 | // ===================== Test methods of IndexedMap type ====================== |
463 | ////////////////////////////////void TestIndexedMap (QANCollection_IndexedMap& theM) |
464 | static void TestIndexedMap (QANCollection_IndexedMapFunc& theM) |
465 | { |
466 | // Extent |
467 | Standard_Integer iExt=theM.Extent(); |
468 | Standard_Integer i; |
469 | |
470 | printf ("Info: testing IndexedMap(l=%d)\n", iExt); |
471 | theM.Statistics(cout); |
472 | // Resize |
473 | theM.ReSize(8); |
474 | theM.Statistics(cout); |
475 | cout.flush(); |
476 | // Constructor |
477 | ////////////////////////////////QANCollection_IndexedMap aM; |
478 | QANCollection_IndexedMapFunc aM; |
479 | // Add, FindKey, FindIndex |
480 | Key1Type aKey; |
481 | for (i=0; i<8; i++) |
482 | { |
483 | Random (aKey); |
484 | aM.Add (aKey); |
485 | Standard_Integer iIndex=aM.FindIndex(aKey); |
486 | printf (" added a key, i=%d, k=",iIndex); |
487 | PrintItem(aM(iIndex)); |
488 | } |
489 | // Contains, Remove |
490 | if (!aM.Contains(aM.FindKey(aM.FindIndex(aKey)))) |
491 | { |
492 | printf("Error : map says that it does not contain its key "); |
493 | PrintItem(aKey); |
494 | } |
495 | else |
496 | { |
497 | aM.RemoveLast(); |
498 | printf(" successfully removed item, l=%d\n", aM.Size()); |
499 | } |
500 | // Substitute |
501 | Random(aKey); |
502 | aM.Substitute(1,aKey); |
985aed12 |
503 | if (!aM.Contains (aKey) || aM.FindIndex (aKey) != 1) |
504 | { |
505 | printf("Error : map does not contain valid key after substitute"); |
506 | } |
507 | // Invoke substitute with the same key |
508 | aM.Substitute(1,aKey); |
509 | if (!aM.Contains (aKey) || aM.FindIndex (aKey) != 1) |
510 | { |
511 | printf("Error : map does not contain valid key after substitute"); |
512 | } |
3a01a933 |
513 | // Copy constructor (including operator=) |
514 | ////////////////////////////////QANCollection_IndexedMap aM2 = QANCollection_IndexedMap(aM); |
515 | QANCollection_IndexedMapFunc aM2 = QANCollection_IndexedMapFunc(aM); |
516 | // Assign |
517 | AssignCollection (aM2,theM); |
518 | |
519 | // Clear |
520 | aM.Clear(); |
521 | } |
522 | |
523 | // ===================== Test methods of IndexedDataMap type ================== |
524 | ////////////////////////////////void TestIndexedDataMap (QANCollection_IDMap& theM) |
525 | static void TestIndexedDataMap (QANCollection_IDMapFunc& theM) |
526 | { |
527 | // Extent |
528 | Standard_Integer iExt=theM.Extent(); |
529 | Standard_Integer i; |
530 | |
531 | printf ("Info: testing IndexedDataMap(l=%d)\n", iExt); |
532 | theM.Statistics(cout); |
533 | // Resize |
534 | theM.ReSize(8); |
535 | theM.Statistics(cout); |
536 | cout.flush(); |
537 | // Constructor |
538 | ////////////////////////////////QANCollection_IDMap aM; |
539 | QANCollection_IDMapFunc aM; |
540 | // Add, FindKey, FindIndex, FindFromIndex, Change..., () |
541 | Key1Type aKey; |
542 | ItemType anItem; |
543 | for (i=0; i<8; i++) |
544 | { |
545 | Random (aKey); |
546 | Random (anItem); |
547 | aM.Add (aKey, anItem); |
548 | Standard_Integer iIndex=aM.FindIndex(aKey); |
549 | printf (" added a key, i=%d, k=",iIndex); |
550 | PrintItem(aM.FindKey(iIndex)); |
551 | PrintItem(aM(iIndex)); |
552 | Random(aM.ChangeFromIndex(iIndex)); |
553 | } |
554 | // Contains, Remove, FindFromKey |
555 | if (!aM.Contains(aM.FindKey(aM.FindIndex(aKey)))) |
556 | { |
557 | printf("Error : map says that it does not contain its key "); |
558 | PrintItem(aKey); |
559 | } |
560 | else |
561 | { |
562 | anItem = aM.FindFromKey(aKey); |
563 | aM.RemoveLast(); |
564 | printf(" successfully removed item, l=%d\n", aM.Size()); |
565 | } |
985aed12 |
566 | // Substitute with different keys |
3a01a933 |
567 | Random(aKey); |
568 | aM.Substitute (1, aKey, anItem); |
985aed12 |
569 | if (!aM.Contains (aKey) || aM.FindIndex (aKey) != 1 || !aM.FindFromKey (aKey).IsEqual (anItem, Precision::Confusion())) |
570 | { |
571 | printf("Error : map does not contain valid key and item after substitute"); |
572 | } |
573 | // Substitute with equal keys |
574 | Random(anItem); |
575 | aM.Substitute (1, aKey, anItem); |
576 | if (!aM.Contains (aKey) || aM.FindIndex (aKey) != 1 || !aM.FindFromKey (aKey).IsEqual (anItem, Precision::Confusion())) |
577 | { |
578 | printf("Error : map does not contain valid key and item after substitute"); |
579 | } |
3a01a933 |
580 | // Copy constructor (including operator=) |
581 | ////////////////////////////////theM = QANCollection_IDMap(aM); |
582 | theM = QANCollection_IDMapFunc(aM); |
583 | // Assign - prohibited |
584 | // AssignCollection (aM2,theM); |
585 | printCollection (theM, "DoubleMap:"); |
586 | |
587 | // Clear |
588 | aM.Clear(); |
589 | } |
590 | |
591 | //======================================================================= |
592 | //function : CheckArguments1 |
593 | //purpose : |
594 | //======================================================================= |
595 | Standard_Integer CheckArguments1(Draw_Interpretor& di, Standard_Integer argc, const char ** argv, Standard_Integer& Lower, Standard_Integer& Upper) |
596 | { |
597 | if ( argc != 3) { |
598 | di << "Usage : " << argv[0] << " Lower Upper" << "\n"; |
599 | return 1; |
600 | } |
601 | Lower = Draw::Atoi(argv[1]); |
602 | Upper = Draw::Atoi(argv[2]); |
603 | if ( Lower > Upper ) { |
604 | di << "Lower > Upper" << "\n"; |
605 | return 1; |
606 | } |
607 | return 0; |
608 | } |
609 | |
610 | //======================================================================= |
611 | //function : CheckArguments2 |
612 | //purpose : |
613 | //======================================================================= |
614 | Standard_Integer CheckArguments2(Draw_Interpretor& di, Standard_Integer argc, const char ** argv, Standard_Integer& LowerRow, Standard_Integer& UpperRow, Standard_Integer& LowerCol, Standard_Integer& UpperCol) |
615 | { |
616 | if ( argc != 5) { |
617 | di << "Usage : " << argv[0] << " LowerRow UpperRow LowerCol UpperCol" << "\n"; |
618 | return 1; |
619 | } |
620 | LowerRow = Draw::Atoi(argv[1]); |
621 | UpperRow = Draw::Atoi(argv[2]); |
622 | LowerCol = Draw::Atoi(argv[3]); |
623 | UpperCol = Draw::Atoi(argv[4]); |
624 | if ( LowerRow > UpperRow ) { |
625 | di << "LowerRow > UpperRow" << "\n"; |
626 | return 1; |
627 | } |
628 | if ( LowerCol > UpperCol ) { |
629 | di << "LowerCol UpperCol> " << "\n"; |
630 | return 1; |
631 | } |
632 | return 0; |
633 | } |
634 | |
635 | |
636 | //======================================================================= |
637 | //function : QANColTestArray1 |
638 | //purpose : |
639 | //======================================================================= |
640 | static Standard_Integer QANColTestArray1(Draw_Interpretor& di, Standard_Integer argc, const char ** argv) |
641 | { |
642 | Standard_Integer Lower, Upper; |
643 | if ( CheckArguments1(di, argc, argv, Lower, Upper) ) { |
644 | return 1; |
645 | } |
646 | QANCollection_Array1Func anArr1(Lower, Upper); |
647 | TestArray1(anArr1); |
648 | return 0; |
649 | } |
650 | |
651 | //======================================================================= |
652 | //function : QANColTestArray2 |
653 | //purpose : |
654 | //======================================================================= |
655 | static Standard_Integer QANColTestArray2(Draw_Interpretor& di, Standard_Integer argc, const char ** argv) |
656 | { |
657 | Standard_Integer LowerRow, UpperRow, LowerCol, UpperCol; |
658 | if ( CheckArguments2(di, argc, argv, LowerRow, UpperRow, LowerCol, UpperCol) ) { |
659 | return 1; |
660 | } |
661 | QANCollection_Array2Func anArr2(LowerRow, UpperRow, LowerCol, UpperCol); |
662 | TestArray2(anArr2); |
663 | return 0; |
664 | } |
665 | |
666 | //======================================================================= |
667 | //function : QANColTestMap |
668 | //purpose : |
669 | //======================================================================= |
670 | static Standard_Integer QANColTestMap(Draw_Interpretor& di, Standard_Integer argc, const char ** argv) |
671 | { |
672 | if ( argc != 1) { |
673 | di << "Usage : " << argv[0] << "\n"; |
674 | return 1; |
675 | } |
676 | QANCollection_MapFunc aMap; |
677 | TestMap(aMap); |
678 | return 0; |
679 | } |
680 | |
681 | //======================================================================= |
682 | //function : QANColTestDataMap |
683 | //purpose : |
684 | //======================================================================= |
685 | static Standard_Integer QANColTestDataMap(Draw_Interpretor& di, Standard_Integer argc, const char ** argv) |
686 | { |
687 | if ( argc != 1) { |
688 | di << "Usage : " << argv[0] << "\n"; |
689 | return 1; |
690 | } |
691 | QANCollection_DataMapFunc aDataMap; |
692 | TestDataMap(aDataMap); |
693 | return 0; |
694 | } |
695 | |
696 | //======================================================================= |
697 | //function : QANColTestDoubleMap |
698 | //purpose : |
699 | //======================================================================= |
700 | static Standard_Integer QANColTestDoubleMap(Draw_Interpretor& di, Standard_Integer argc, const char ** argv) |
701 | { |
702 | if ( argc != 1) { |
703 | di << "Usage : " << argv[0] << "\n"; |
704 | return 1; |
705 | } |
706 | QANCollection_DoubleMapFunc aDoubleMap; |
707 | TestDoubleMap(aDoubleMap); |
708 | return 0; |
709 | } |
710 | |
711 | //======================================================================= |
712 | //function : QANColTestIndexedMap |
713 | //purpose : |
714 | //======================================================================= |
715 | static Standard_Integer QANColTestIndexedMap(Draw_Interpretor& di, Standard_Integer argc, const char ** argv) |
716 | { |
717 | if ( argc != 1) { |
718 | di << "Usage : " << argv[0] << "\n"; |
719 | return 1; |
720 | } |
721 | QANCollection_IndexedMapFunc aIndexedMap; |
722 | TestIndexedMap(aIndexedMap); |
723 | return 0; |
724 | } |
725 | |
726 | //======================================================================= |
727 | //function : QANColTestIndexedDataMap |
728 | //purpose : |
729 | //======================================================================= |
730 | static Standard_Integer QANColTestIndexedDataMap(Draw_Interpretor& di, Standard_Integer argc, const char ** argv) |
731 | { |
732 | if ( argc != 1) { |
733 | di << "Usage : " << argv[0] << "\n"; |
734 | return 1; |
735 | } |
736 | QANCollection_IDMapFunc aIDMap; |
737 | TestIndexedDataMap(aIDMap); |
738 | return 0; |
739 | } |
740 | |
741 | //======================================================================= |
742 | //function : QANColTestList |
743 | //purpose : |
744 | //======================================================================= |
745 | static Standard_Integer QANColTestList(Draw_Interpretor& di, Standard_Integer argc, const char ** argv) |
746 | { |
747 | if ( argc != 1) { |
748 | di << "Usage : " << argv[0] << "\n"; |
749 | return 1; |
750 | } |
751 | QANCollection_ListFunc aList; |
752 | TestList(aList); |
753 | return 0; |
754 | } |
755 | |
e3a6386d |
756 | //======================================================================= |
757 | //function : QANColTestVector |
758 | //purpose : |
759 | //======================================================================= |
760 | static Standard_Integer QANColTestVector (Draw_Interpretor&, Standard_Integer, const char**) |
761 | { |
762 | // test method Append and copying of empty vector |
763 | NCollection_Vector<int> aVec; |
764 | NCollection_Vector<int> aVec2 (aVec); |
765 | NCollection_Vector<int> aVec3; |
766 | aVec3 = aVec; |
767 | |
768 | aVec.Append(5); |
769 | if (aVec(0) != 5) |
770 | std::cout << "Error: wrong value in original vector!" << endl; |
771 | aVec2.Append(5); |
772 | if (aVec2(0) != 5) |
773 | std::cout << "Error: wrong value in copy-constructed vector!" << endl; |
774 | aVec3.Append(5); |
775 | if (aVec3(0) != 5) |
776 | std::cout << "Error: wrong value in copied vector!" << endl; |
777 | std::cout << "Test OK" << endl; |
778 | |
779 | return 0; |
780 | } |
781 | |
3a01a933 |
782 | //======================================================================= |
783 | //function : QANColTestSequence |
784 | //purpose : |
785 | //======================================================================= |
786 | static Standard_Integer QANColTestSequence(Draw_Interpretor& di, Standard_Integer argc, const char ** argv) |
787 | { |
788 | if ( argc != 1) { |
789 | di << "Usage : " << argv[0] << "\n"; |
790 | return 1; |
791 | } |
792 | QANCollection_SequenceFunc aSeq; |
793 | TestSequence(aSeq); |
794 | return 0; |
795 | } |
796 | |
797 | void QANCollection::CommandsTest(Draw_Interpretor& theCommands) { |
798 | const char *group = "QANCollection"; |
799 | |
800 | // from agvCollTest/src/CollectionEXE/FuncTestEXE.cxx |
801 | theCommands.Add("QANColTestArray1", "QANColTestArray1", __FILE__, QANColTestArray1, group); |
802 | theCommands.Add("QANColTestArray2", "QANColTestArray2", __FILE__, QANColTestArray2, group); |
803 | theCommands.Add("QANColTestMap", "QANColTestMap", __FILE__, QANColTestMap, group); |
804 | theCommands.Add("QANColTestDataMap", "QANColTestDataMap", __FILE__, QANColTestDataMap, group); |
805 | theCommands.Add("QANColTestDoubleMap", "QANColTestDoubleMap", __FILE__, QANColTestDoubleMap, group); |
806 | theCommands.Add("QANColTestIndexedMap", "QANColTestIndexedMap", __FILE__, QANColTestIndexedMap, group); |
807 | theCommands.Add("QANColTestIndexedDataMap", "QANColTestIndexedDataMap", __FILE__, QANColTestIndexedDataMap, group); |
808 | theCommands.Add("QANColTestList", "QANColTestList", __FILE__, QANColTestList, group); |
809 | theCommands.Add("QANColTestSequence", "QANColTestSequence", __FILE__, QANColTestSequence, group); |
e3a6386d |
810 | theCommands.Add("QANColTestVector", "QANColTestVector", __FILE__, QANColTestVector, group); |
3a01a933 |
811 | } |