42f2d345f5ad6bc7156c6e489af26ced761b10b6
[occt.git] / src / QANCollection / QANCollection_Handle.cxx
1 // Copyright (c) 2014 OPEN CASCADE SAS
2 //
3 // This file is part of Open CASCADE Technology software library.
4 //
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
10 //
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
13
14 #include <QANCollection.hxx>
15
16 #include <Draw.hxx>
17 #include <Draw_Interpretor.hxx>
18
19 #include <Message_Status.hxx>
20 #include <NCollection_StdAllocator.hxx>
21 #include <NCollection_IncAllocator.hxx>
22 #include <NCollection_HeapAllocator.hxx>
23 #include <OSD_Timer.hxx>
24 #include <Standard_Assert.hxx>
25 #include <Standard_DefineHandle.hxx>
26 #include <Standard_Transient.hxx>
27 #include <TCollection_AsciiString.hxx>
28 #include <Geom_Circle.hxx>
29 #include <Geom_Line.hxx>
30 #include <Geom_BSplineCurve.hxx>
31 #include <Geom_Surface.hxx>
32
33 #include <vector>
34 #include <memory>
35 #include <typeinfo>
36
37 // auxiliary macro to check and report status
38 #define CHECK(di,ok,what) di << "Checking " << what << (ok ? ": OK\n" : ": Error\n")
39
40 //=======================================================================
41 //function : QAHandleOps
42 //purpose  : Test Handle operations (mostly compile-time checks)
43 //=======================================================================
44
45 // set of overloaded functions for checking resolution of arguments
46 inline void f (const Handle(Geom_Curve)&) {}
47 inline void func (const Handle(Geom_Curve)&) {}
48 inline void func (const Handle(Geom_BSplineCurve)&) {}
49 inline void func (const Handle(Geom_Surface)&) {}
50 inline void func (const Handle(gp_Pnt)&) {}
51 inline void func (const Handle(gp_XYZ)&) {}
52 inline void func (const Handle(gp_Trsf)&) {}
53
54 static Standard_Integer QAHandleOps (Draw_Interpretor& theDI,
55                                      Standard_Integer  /*theArgNb*/,
56                                      const char**      /*theArgVec*/)
57 {
58   // ===============================================================
59   // Part 1: classes inheriting transient
60   // ===============================================================
61
62   Handle(Geom_Line) aLine = new Geom_Line (gp::Origin(), gp::DZ());
63   CHECK(theDI, ! aLine.IsNull(), "handle for non-null");
64
65   const Handle(Geom_Line)& cLine = aLine; // cast to self const ref
66   const Handle(Geom_Curve)& cCurve = aLine; // cast to base const ref
67   Geom_Line* pLine = aLine.get();
68   const Geom_Line* cpLine = aLine.get();
69   Geom_Line& rLine = *aLine;
70   const Geom_Line& crLine = *cLine;
71   Handle(Geom_Curve) aCurve = aLine; // copy from handle to derived type
72   aCurve = cLine; // assignment to handle of derived type
73   Handle(Geom_Line) dLine (cpLine); // copy from handle to derived type
74
75   aLine = Handle(Geom_Line)::DownCast (cCurve);
76   CHECK(theDI, ! aLine.IsNull(), "down cast");
77
78   // comparison operators
79   CHECK(theDI, aLine == aLine, "equality of handle to itself");
80   CHECK(theDI, cLine == cLine, "equality of const handle to itself");
81   CHECK(theDI, aLine == cLine, "equality of const and non-const handle");
82   CHECK(theDI, aLine == cCurve, "equality of handle and base handle");
83   CHECK(theDI, aLine == pLine,  "equality of handle and pointer");
84   CHECK(theDI, pLine == aLine,  "equality of pointer and handle");
85   CHECK(theDI, aLine == cpLine,  "equality of handle and const pointer");
86   CHECK(theDI, cpLine == aLine,  "equality of const pointer and handle");
87   CHECK(theDI, &rLine == aLine,  "equality of reference and handle");
88   CHECK(theDI, &crLine == aLine,  "equality of reference and handle");
89   CHECK(theDI, aLine, "cast to bool");
90
91   Handle(Geom_Line) aLin2;
92   CHECK(theDI, aLine != aLin2, "inequality of handle to the same type handle");
93   CHECK(theDI, aLin2 != cLine, "inequality of const and non-const handle");
94   CHECK(theDI, aLin2 != cCurve, "inequality of handle and base handle");
95   CHECK(theDI, aLin2 != pLine,  "inequality of handle and pointer");
96   CHECK(theDI, pLine != aLin2,  "inequality of pointer and handle");
97   CHECK(theDI, aLin2 != cpLine,  "inequality of handle and const pointer");
98   CHECK(theDI, cpLine != aLin2,  "inequality of const pointer and handle");
99
100   Handle(Geom_Curve) aCur2;
101   CHECK(theDI, aLine != aCur2, "inequality of handles of different types");
102   CHECK(theDI, aCur2 != cLine, "inequality of const and non-const handle");
103   CHECK(theDI, aCur2 != cCurve, "inequality of handle and base handle");
104   CHECK(theDI, aCur2 != pLine,  "inequality of handle and pointer");
105   CHECK(theDI, pLine != aCur2,  "inequality of pointer and handle");
106   CHECK(theDI, aCur2 != cpLine,  "inequality of handle and const pointer");
107   CHECK(theDI, cpLine != aCur2,  "inequality of const pointer and handle");
108
109   // passing handle as reference to base class
110   f (aLine);
111
112   // passing handle to overloaded function accepting handle to another type
113   // will fail on VC below 12 and GCC below 4.3 due to ambiguity of overloads
114 #if __cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1800) || (defined(__GNUC__) && __GNUC__ >= 4 && __GNUC_MINOR__ >= 3)
115   func (aLine);
116   func (cLine);
117 #endif
118
119   const Handle(Geom_Curve)& aCurve2 = aLine; // cast to base const ref
120
121   Handle(Geom_Line) qLine = cpLine; // constructor from const pointer -- could be made explicit...
122
123   // check whether compiler will destroy reference to temporary handle
124   const Handle(Geom_Curve)& aTmpRef (Handle(Geom_Line)::DownCast (aCurve2));
125   CHECK(theDI, ! aTmpRef.IsNull(),  "local reference of handle to base type to temporary handle object");
126
127   // check operations with Handle_* classes
128   Handle(Geom_Line) hLine = aLine;
129   CHECK(theDI, ! hLine.IsNull(), "hhandle for non-null");
130
131   const Handle_Geom_Line& chLine = aLine; // cast to self const ref
132   const Handle_Geom_Curve& chCurve = aLine; // cast to base const ref
133   const Handle_Geom_Line& hhLine = hLine; // cast to self const ref
134   const Handle_Geom_Curve& hhCurve = hLine; // cast to base const ref
135   Handle_Geom_Curve hCurve = aLine; // copy from handle to derived type
136   Handle_Geom_Line phLine (aLine.get()); // construct from pointer
137
138   hLine = Handle_Geom_Line::DownCast (cCurve); // inheritance of downcast
139   CHECK(theDI, ! hLine.IsNull(), "down cast");
140
141   // comparison operators
142   CHECK(theDI, hLine == hLine, "equality of hhandle to itself");
143   CHECK(theDI, hLine == aLine, "equality of hhandle to handle");
144   CHECK(theDI, hhLine == hLine, "equality of hhandle to const");
145   CHECK(theDI, chLine == hLine, "equality of hhandle to const");
146   CHECK(theDI, hhCurve == hLine, "equality of hhandle to const");
147   CHECK(theDI, chCurve == hLine, "equality of hhandle to const");
148   CHECK(theDI, hLine, "cast to bool");
149
150   // passing hhandle as reference to base class
151   f (hLine);
152
153   // passing handle to overloaded function accepting handle to another type
154   // will fail on VC below 12 and GCC below 4.3 due to ambiguity of overloads
155 #if __cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1800) || (defined(__GNUC__) && __GNUC__ >= 4 && __GNUC_MINOR__ >= 3)
156   func (hLine);
157   func (chLine);
158 #endif
159
160   Handle_Geom_Line qhLine = cpLine; // constructor from const pointer -- could be made explicit...
161
162   // check whether compiler will destroy reference to temporary handle
163   const Handle_Geom_Curve& hTmpRef (Handle(Geom_Line)::DownCast (aCurve2));
164   CHECK(theDI, ! hTmpRef.IsNull(),  "local reference of handle to base type to temporary handle object");
165
166   Handle(Geom_Surface) aSurf;
167   (void)aSurf;
168
169 #if 0
170   // each test in this section must cause compiler error
171   gunc (cLine); // passing const handle as non-const reference to base type
172   pLine = cLine.get(); // getting non-const pointer to contained object from const handle 
173   Handle(Geom_Line) xLine = cCurve; // copy from handle to base type
174   Handle(Geom_BSplineCurve) aBSpl (new Geom_Line (gp::Origin(), gp::DX())); // construction from pointer to incompatible type
175
176   CHECK(theDI, aLine == aSurf,  "equality of handles of incompatible types");
177   CHECK(theDI, aSurf == cLine,  "equality of const and non-const handle");
178   CHECK(theDI, aSurf == cCurve, "equality of handle and base handle");
179   CHECK(theDI, aSurf == pLine,  "equality of handle and pointer");
180   CHECK(theDI, pLine == aSurf,  "equality of pointer and handle");
181   CHECK(theDI, aSurf == cpLine, "equality of handle and const pointer");
182   CHECK(theDI, cpLine != aSurf, "equality of const pointer and handle");
183
184   CHECK(theDI, aLine != aSurf,  "inequality of handles of incompatible types");
185   CHECK(theDI, aSurf != cLine,  "inequality of const and non-const handle");
186   CHECK(theDI, aSurf != cCurve, "inequality of handle and base handle");
187   CHECK(theDI, aSurf != pLine,  "inequality of handle and pointer");
188   CHECK(theDI, pLine != aSurf,  "inequality of pointer and handle");
189   CHECK(theDI, aSurf != cpLine, "inequality of handle and const pointer");
190   CHECK(theDI, cpLine != aSurf, "inequality of const pointer and handle");
191 #endif
192
193   // ===============================================================
194   // Part 2: classes not inheriting transient
195   // ===============================================================
196 /*
197   Handle(gp_Pnt) aPnt = new gp_Pnt (gp::Origin());
198   CHECK(theDI, ! aPnt.IsNull(), "handle for non-null");
199
200   const Handle(gp_Pnt)& cPnt = aPnt; // cast to self const ref
201 //  const Handle(gp_XYZ)& cXYZ = aPnt; // cast to base const ref
202   gp_Pnt* pPnt = aPnt.get();
203   const gp_Pnt* cpPnt = aPnt.get();
204   gp_Pnt& rPnt = *aPnt;
205   const gp_Pnt& crPnt = *cPnt;
206 //  Handle(gp_XYZ) aXYZ = aPnt; // copy from handle to derived type
207 //  aXYZ = cPnt; // assignment to handle of derived type
208
209 //  aPnt = Handle(gp_Pnt)::DownCast (cXYZ);
210 //  CHECK(theDI, ! aPnt.IsNull(), "down cast");
211
212   // comparison operators
213   CHECK(theDI, aPnt == aPnt, "equality of handle to itself");
214   CHECK(theDI, cPnt == cPnt, "equality of const handle to itself");
215   CHECK(theDI, aPnt == cPnt, "equality of const and non-const handle");
216 //  CHECK(theDI, aPnt == cXYZ, "equality of handle and base handle");
217   CHECK(theDI, aPnt == pPnt,  "equality of handle and pointer");
218   CHECK(theDI, pPnt == aPnt,  "equality of pointer and handle");
219   CHECK(theDI, aPnt == cpPnt,  "equality of handle and const pointer");
220   CHECK(theDI, cpPnt == aPnt,  "equality of const pointer and handle");
221   CHECK(theDI, &rPnt == aPnt,  "equality of reference and handle");
222   CHECK(theDI, &crPnt == aPnt,  "equality of reference and handle");
223
224   Handle(gp_Pnt) aPnt2;
225   CHECK(theDI, aPnt != aPnt2, "inequality of handle to the same type handle");
226   CHECK(theDI, aPnt2 != cPnt, "inequality of const and non-const handle");
227 //  CHECK(theDI, aPnt2 != cXYZ, "inequality of handle and base handle");
228   CHECK(theDI, aPnt2 != pPnt,  "inequality of handle and pointer");
229   CHECK(theDI, pPnt != aPnt2,  "inequality of pointer and handle");
230   CHECK(theDI, aPnt2 != cpPnt,  "inequality of handle and const pointer");
231   CHECK(theDI, cpPnt != aPnt2,  "inequality of const pointer and handle");
232
233   Handle(gp_XYZ) aXYZ2;
234   CHECK(theDI, aLine != aPnt2, "inequality of handles of different types");
235   CHECK(theDI, aXYZ2 != cPnt, "inequality of const and non-const handle");
236 //  CHECK(theDI, aXYZ2 != cXYZ, "inequality of handle and base handle");
237 //  CHECK(theDI, aXYZ2 != pPnt,  "inequality of handle and pointer");
238 //  CHECK(theDI, pPnt != aXYZ2,  "inequality of pointer and handle");
239 //  CHECK(theDI, aXYZ2 != cpPnt,  "inequality of handle and const pointer");
240 //  CHECK(theDI, cpPnt != aXYZ2,  "inequality of const pointer and handle");
241
242   // passing handle as reference to base class
243   func (aPnt);
244   func (cPnt);
245 */
246   return 0;
247 }
248
249 //=======================================================================
250 //function : QAHandleBool
251 //purpose  : Test Handle -> bool conversion
252 //=======================================================================
253 static Standard_Integer QAHandleBool (Draw_Interpretor& theDI,
254                                       Standard_Integer  /*theArgNb*/,
255                                       const char**      /*theArgVec*/)
256 {
257   Handle(NCollection_BaseAllocator) aPtr = new NCollection_IncAllocator();
258
259   Handle(NCollection_IncAllocator) anInc = Handle(NCollection_IncAllocator)::DownCast (aPtr);
260   CHECK (theDI, ! anInc.IsNull(), "cast to NCollection_IncAllocator");
261
262   Handle(NCollection_BaseAllocator) anAlloc = aPtr;
263   CHECK (theDI, ! anAlloc.IsNull(), "cast to NCollection_BaseAllocator");
264   
265   Handle(NCollection_HeapAllocator) aHAlloc = Handle(NCollection_HeapAllocator)::DownCast (aPtr);
266   CHECK (theDI, aHAlloc.IsNull(), "cast to NCollection_HeapAllocator");
267
268   return 0;
269 }
270
271 // Auxiliary class to define new virtual methods
272 class Transient_Root : public Standard_Transient
273 {
274 public:
275   virtual const char* Name() const { return "Transient_Root"; }
276   virtual Standard_Transient* CreateParent() const { return new Standard_Transient; }
277   virtual Standard_Transient* Clone()        const { return new Transient_Root; }
278   DEFINE_STANDARD_RTTI_INLINE(Transient_Root,Standard_Transient)
279 };
280 DEFINE_STANDARD_HANDLE(Transient_Root, Standard_Transient)
281
282 // Auxiliary macros to create hierarchy of 50 classes
283 #define QA_DEFINECLASS(theClass, theParent) \
284 class theClass : public theParent \
285 { \
286 public:\
287   virtual const char* Name() const Standard_OVERRIDE { return #theClass; } \
288   virtual Standard_Transient* CreateParent() const Standard_OVERRIDE { return new theParent(); } \
289   virtual Standard_Transient* Clone()        const Standard_OVERRIDE { return new theClass(); } \
290   DEFINE_STANDARD_RTTI_INLINE(theClass,theParent) \
291 };\
292 DEFINE_STANDARD_HANDLE    (theClass, theParent) 
293
294 #define QA_NAME(theNum) qaclass ## theNum ## _ ## 50
295 #define QA_HANDLE_NAME(theNum) Handle(qaclass ## theNum ## _ ## 50)
296
297 #define QA_DEFINECLASS10(theParent, theTens) \
298 QA_DEFINECLASS(QA_NAME(theTens ## 0), theParent) \
299 QA_DEFINECLASS(QA_NAME(theTens ## 1), QA_NAME(theTens ## 0)) \
300 QA_DEFINECLASS(QA_NAME(theTens ## 2), QA_NAME(theTens ## 1)) \
301 QA_DEFINECLASS(QA_NAME(theTens ## 3), QA_NAME(theTens ## 2)) \
302 QA_DEFINECLASS(QA_NAME(theTens ## 4), QA_NAME(theTens ## 3)) \
303 QA_DEFINECLASS(QA_NAME(theTens ## 5), QA_NAME(theTens ## 4)) \
304 QA_DEFINECLASS(QA_NAME(theTens ## 6), QA_NAME(theTens ## 5)) \
305 QA_DEFINECLASS(QA_NAME(theTens ## 7), QA_NAME(theTens ## 6)) \
306 QA_DEFINECLASS(QA_NAME(theTens ## 8), QA_NAME(theTens ## 7)) \
307 QA_DEFINECLASS(QA_NAME(theTens ## 9), QA_NAME(theTens ## 8))
308
309 QA_DEFINECLASS10(Transient_Root,     0)
310 QA_DEFINECLASS10(qaclass09_50,       1)
311 QA_DEFINECLASS10(qaclass19_50,       2)
312 QA_DEFINECLASS10(qaclass29_50,       3)
313 QA_DEFINECLASS10(qaclass39_50,       4)
314 QA_DEFINECLASS  (qaclass50_50, qaclass49_50)
315
316 namespace
317 {
318   class qaclass50_50ANON : public qaclass49_50
319   {
320   public:
321     qaclass50_50ANON() {}
322   };
323 }
324
325 namespace QaNamespace
326 {
327   class qaclass50_50 : public qaclass49_50
328   {
329   public:
330     qaclass50_50() {}
331   };
332 }
333
334 namespace {
335 //! Timer sentry. Prints elapsed time information at destruction time.
336 class QATimer : public OSD_Timer
337 {
338 public:
339   enum TimeFormat
340   {
341     Seconds,
342     Milliseconds,
343     Microseconds,
344     Nanoseconds,
345     s  = Seconds,
346     ms = Milliseconds,
347     ns = Nanoseconds,
348   };
349
350 public:
351   //! Main constructor - automatically starts the timer.
352   QATimer (Draw_Interpretor& theDI,
353            Standard_CString       theTitle,
354            const TimeFormat       theFormat,
355            const Standard_Integer theNbIters = 1,
356            const Standard_Boolean theToPrintFormat = Standard_False)
357   : myDI(&theDI),
358     myTitle         (theTitle),
359     myFormat        (theFormat),
360     myNbIters       (theNbIters),
361     myToPrintFormat (theToPrintFormat)
362   {
363     Start();
364   }
365
366   //! Destructor - stops the timer and prints statistics.
367   ~QATimer()
368   {
369     Stop();
370     if (myTitle != NULL)
371     {
372       (*myDI) << myTitle;
373     }
374     switch (myFormat)
375     {
376       case Seconds:
377         (*myDI) <<  ElapsedTime() / Standard_Real(myNbIters);
378         if (myToPrintFormat)
379         {
380           (*myDI) << " s";
381         }
382         break;
383       case Milliseconds:
384         (*myDI) << (ElapsedTime() / Standard_Real(myNbIters)) * 1000.0;
385         if (myToPrintFormat)
386         {
387           (*myDI) << " ms";
388         }
389         break;
390       case Microseconds:
391         (*myDI) << (ElapsedTime() / Standard_Real(myNbIters)) * 1000000.0;
392         if (myToPrintFormat)
393         {
394           (*myDI) << " microseconds";
395         }
396         break;
397       case Nanoseconds:
398         (*myDI) << (ElapsedTime() / Standard_Real(myNbIters)) * 1000000000.0;
399         if (myToPrintFormat)
400         {
401           (*myDI) << " ns";
402         }
403         break;
404     }
405   }
406
407 private:
408   Draw_Interpretor* myDI;
409   Standard_CString myTitle;         //!< timer description
410   TimeFormat       myFormat;        //!< time format
411   Standard_Integer myNbIters;       //!< iterations number
412   Standard_Boolean myToPrintFormat; //!< add time format
413 };
414 } // anonymous namespace
415
416 //=======================================================================
417 //function : QAHandleInc
418 //purpose  : Estimate the smart-pointer counter incrementing time
419 //=======================================================================
420 static Standard_Integer QAHandleInc (Draw_Interpretor& theDI,
421                                      Standard_Integer  theArgNb,
422                                      const char**      theArgVec)
423 {
424   if (theArgNb > 2)
425   {
426     std::cout << "Error: wrong syntax! See usage:\n";
427     theDI.PrintHelp (theArgVec[0]);
428     return 1;
429   }
430   const Standard_Integer aNbIters = (theArgNb > 1) ? Draw::Atoi (theArgVec[1]) : 10000000;
431   if (aNbIters < 1)
432   {
433     std::cout << "Error: number of iterations should be positive!\n";
434     return 1;
435   }
436
437   Handle(Standard_Transient) aHandle  = new Standard_Transient();
438   opencascade::std::shared_ptr<Standard_Transient> aSharePtr (new Standard_Transient());
439   theDI << "Time of creating and destroying " << aNbIters << " smart pointers to the same object, per item, ns:";
440   {
441     {
442       QATimer aTimer (theDI, "\nOCCT Handle:    ", QATimer::ns, aNbIters);
443       {
444         std::vector<Handle(Standard_Transient)> aHandles (aNbIters);
445         for (Standard_Integer anIter = 0; anIter < aNbIters; ++anIter)
446         {
447           aHandles[anIter] = aHandle;
448         }
449       }
450     }
451     {
452       QATimer aTimer (theDI, "\nC++ shared_ptr: ", QATimer::ns, aNbIters);
453       {
454         std::vector< opencascade::std::shared_ptr<Standard_Transient> > aSharePointers (aNbIters);
455         for (Standard_Integer anIter = 0; anIter < aNbIters; ++anIter)
456         {
457           aSharePointers[anIter] = aSharePtr;
458         }
459       }
460     }
461   }
462   return 0;
463 }
464
465 //=======================================================================
466 //function : QAHandleKind
467 //purpose  :
468 //=======================================================================
469 static Standard_Integer QAHandleKind (Draw_Interpretor& /*theDI*/,
470                                       Standard_Integer  /*theArgNb*/,
471                                       const char**      /*theArgVec*/)
472 {
473   Handle(Standard_Type) aType00 = STANDARD_TYPE(qaclass00_50);
474   Handle(Standard_Type) aType10 = STANDARD_TYPE(qaclass10_50);
475   Handle(Standard_Type) aType20 = STANDARD_TYPE(qaclass20_50);
476   Handle(Standard_Type) aType30 = STANDARD_TYPE(qaclass30_50);
477   Handle(Standard_Type) aType40 = STANDARD_TYPE(qaclass40_50);
478   Handle(Standard_Type) aType50 = STANDARD_TYPE(qaclass50_50);
479
480   Handle(qaclass00_50) aHandle = new qaclass40_50();
481
482   #define QA_CHECK(theDesc, theExpr, theValue) \
483     {\
484       const bool isTrue = !!(theExpr); \
485       std::cout << theDesc << (isTrue ? " TRUE  " : " FALSE ") << (isTrue == theValue ? " is OK\n" : " is Error\n"); \
486     }
487
488   std::cout << "Check instance of " << aHandle->DynamicType()->Name() << "\n";
489   for (Handle(Standard_Type) aType = aHandle->DynamicType(); ! aType.IsNull(); aType = aType->Parent())
490   {
491     std::cout << " - " << aType->Name() << "\n";
492   }
493
494   QA_CHECK ("Name == qaclass40_50       : ", TCollection_AsciiString("qaclass40_50") == aHandle->DynamicType()->Name(), true);
495
496   QA_CHECK ("IsKind     (aType00)       : ", aHandle->IsKind (aType00), true);
497   QA_CHECK ("IsKind     (aType10)       : ", aHandle->IsKind (aType10), true);
498   QA_CHECK ("IsKind     (aType20)       : ", aHandle->IsKind (aType20), true);
499   QA_CHECK ("IsKind     (aType30)       : ", aHandle->IsKind (aType30), true);
500   QA_CHECK ("IsKind     (aType40)       : ", aHandle->IsKind (aType40), true);
501   QA_CHECK ("IsKind     (aType50)       : ", aHandle->IsKind (aType50), false);
502
503   QA_CHECK ("IsKind     (\"qaclass00_50\"): ", aHandle->IsKind ("qaclass00_50"), true);
504   QA_CHECK ("IsKind     (\"qaclass10_50\"): ", aHandle->IsKind ("qaclass10_50"), true);
505   QA_CHECK ("IsKind     (\"qaclass20_50\"): ", aHandle->IsKind ("qaclass20_50"), true);
506   QA_CHECK ("IsKind     (\"qaclass30_50\"): ", aHandle->IsKind ("qaclass30_50"), true);
507   QA_CHECK ("IsKind     (\"qaclass40_50\"): ", aHandle->IsKind ("qaclass40_50"), true);
508   QA_CHECK ("IsKind     (\"qaclass50_50\"): ", aHandle->IsKind ("qaclass50_50"), false);
509
510   QA_CHECK ("IsInstance (aType00)       : ", aHandle->IsInstance (aType00), false);
511   QA_CHECK ("IsInstance (aType10)       : ", aHandle->IsInstance (aType10), false);
512   QA_CHECK ("IsInstance (aType20)       : ", aHandle->IsInstance (aType20), false);
513   QA_CHECK ("IsInstance (aType30)       : ", aHandle->IsInstance (aType30), false);
514   QA_CHECK ("IsInstance (aType40)       : ", aHandle->IsInstance (aType40), true);
515   QA_CHECK ("IsInstance (aType50)       : ", aHandle->IsInstance (aType50), false);
516
517 #ifdef HAVE_CPP11
518   std::cout << "\nC++11:\n";
519   std::type_index aCppType     = typeid(*aHandle.operator->());
520   std::cout << "typeid().name()    = '" << typeid(*aHandle.operator->()).name()     << "'\n";
521 #ifdef _MSC_VER
522   std::cout << "typeid().raw_name()= '" << typeid(*aHandle.operator->()).raw_name() << "'\n";
523 #endif
524
525   std::cout << "[ANON]typeid().name()    = '" << typeid(qaclass50_50ANON).name()     << "'\n";
526 #ifdef _MSC_VER
527   std::cout << "[ANON]typeid().raw_name()= '" << typeid(qaclass50_50ANON).raw_name() << "'\n";
528 #endif
529
530   std::cout << "[NS]typeid().name()    = '" << typeid(QaNamespace::qaclass50_50).name()     << "'\n";
531 #ifdef _MSC_VER
532   std::cout << "[NS]typeid().raw_name()= '" << typeid(QaNamespace::qaclass50_50).raw_name() << "'\n";
533 #endif
534
535   QA_CHECK ("is typeid  (aType00)       : ", typeid(*aHandle.operator->()) == typeid(qaclass00_50), false);
536   QA_CHECK ("is typeid  (aType10)       : ", typeid(*aHandle.operator->()) == typeid(qaclass10_50), false);
537   QA_CHECK ("is typeid  (aType20)       : ", typeid(*aHandle.operator->()) == typeid(qaclass20_50), false);
538   QA_CHECK ("is typeid  (aType30)       : ", typeid(*aHandle.operator->()) == typeid(qaclass30_50), false);
539   QA_CHECK ("is typeid  (aType40)       : ", typeid(*aHandle.operator->()) == typeid(qaclass40_50), true);
540   QA_CHECK ("is typeid  (aType50)       : ", typeid(*aHandle.operator->()) == typeid(qaclass50_50), false);
541
542   QA_CHECK ("is type_index (aType00)    : ", aCppType == typeid(qaclass00_50), false);
543   QA_CHECK ("is type_index (aType40)    : ", aCppType == typeid(qaclass40_50), true);
544
545   QA_CHECK ("IsClass(Standard_Transient): ", std::is_class<Standard_Transient>::value == !!STANDARD_TYPE(Standard_Transient)->IsClass(), true);
546   //QA_CHECK ("IsEnum (Message_Status)    : ", std::is_enum<Message_Status>::value == !!STANDARD_TYPE(Message_Status)->IsEnumeration(), true);
547 #endif
548
549   return 0;
550 }
551
552 void QANCollection::CommandsHandle (Draw_Interpretor& theCommands)
553 {
554   const char* THE_GROUP = "QANCollection";
555   theCommands.Add ("QAHandleBool",
556                    "Test handle boolean operator",
557                    __FILE__, QAHandleBool, THE_GROUP);
558   theCommands.Add ("QAHandleInc",
559                    "QAHandleInc nbIter=1000000"
560                    "\n\t\t: Test handle increment performance",
561                    __FILE__, QAHandleInc,  THE_GROUP);
562   theCommands.Add ("QAHandleKind",
563                    "Test handle IsKind",
564                    __FILE__, QAHandleKind, THE_GROUP);
565   theCommands.Add ("QAHandleOps",
566                    "Test handle operations",
567                    __FILE__, QAHandleOps, THE_GROUP);
568   return;
569 }