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