From 515e1125640138905408d56073ecd64dbef419c4 Mon Sep 17 00:00:00 2001 From: Pasukhin Dmitry Date: Mon, 8 Sep 2025 15:59:34 +0100 Subject: [PATCH] Testing - Migrate QA NCollection to GTests (#709) - Complete removal of old Draw Harness test infrastructure for NCollection classes - Addition of new GTest files testing STL algorithm compatibility (min, max, replace, sort, reverse) - Migration of OSD_Path and Handle operation tests to GTest format --- src/Draw/TKQADraw/QANCollection/FILES.cmake | 5 - .../TKQADraw/QANCollection/QANCollection.cxx | 8 +- .../TKQADraw/QANCollection/QANCollection.hxx | 10 - .../QANCollection/QANCollection_Alloc.cxx | 156 -- .../QANCollection/QANCollection_Handle.cxx | 658 -------- .../QANCollection/QANCollection_Perf.cxx | 1046 ------------ .../QANCollection/QANCollection_Stl.cxx | 1438 ---------------- .../QANCollection/QANCollection_Test.cxx | 1477 ----------------- .../TKernel/GTests/FILES.cmake | 5 + .../TKernel/GTests/Handle_Advanced_Test.cxx | 413 +++++ .../TKernel/GTests/Handle_Operations_Test.cxx | 236 +++ .../GTests/NCollection_Array1_Test.cxx | 73 + .../GTests/NCollection_DataMap_Test.cxx | 43 + .../NCollection_IndexedDataMap_Test.cxx | 42 + .../GTests/NCollection_IndexedMap_Test.cxx | 51 + .../TKernel/GTests/NCollection_List_Test.cxx | 50 + .../GTests/NCollection_OccAllocator_Test.cxx | 164 ++ .../GTests/NCollection_Sequence_Test.cxx | 67 + .../TKernel/GTests/NCollection_Vec4_Test.cxx | 131 ++ .../GTests/NCollection_Vector_Test.cxx | 87 + .../TKernel/GTests/OSD_Path_Test.cxx | 246 +++ tests/bugs/fclasses/bug23569_1 | 11 - tests/bugs/fclasses/bug23569_2 | 11 - tests/bugs/fclasses/bug24831 | 5 - tests/collections/grids.list | 1 - tests/collections/n/array1 | 3 - tests/collections/n/array2 | 3 - tests/collections/n/arrayMove | 4 - tests/collections/n/begin | 1 - tests/collections/n/dblmap | 3 - tests/collections/n/dmap | 3 - tests/collections/n/end | 1 - tests/collections/n/idmap | 3 - tests/collections/n/imap | 3 - tests/collections/n/list | 3 - tests/collections/n/map | 3 - tests/collections/n/osdpath | 48 - tests/collections/n/seq | 3 - tests/collections/n/vec4 | 3 - tests/collections/n/vector | 3 - tests/perf/fclasses/handle | 14 - tests/perf/fclasses/strtod | 50 - tests/perf/ncollection/A1 | 53 - tests/perf/ncollection/A2 | 41 - tests/perf/ncollection/A3 | 41 - 45 files changed, 1611 insertions(+), 5109 deletions(-) delete mode 100644 src/Draw/TKQADraw/QANCollection/QANCollection_Alloc.cxx delete mode 100644 src/Draw/TKQADraw/QANCollection/QANCollection_Handle.cxx delete mode 100644 src/Draw/TKQADraw/QANCollection/QANCollection_Perf.cxx delete mode 100644 src/Draw/TKQADraw/QANCollection/QANCollection_Stl.cxx delete mode 100644 src/Draw/TKQADraw/QANCollection/QANCollection_Test.cxx create mode 100644 src/FoundationClasses/TKernel/GTests/Handle_Advanced_Test.cxx create mode 100644 src/FoundationClasses/TKernel/GTests/Handle_Operations_Test.cxx create mode 100644 src/FoundationClasses/TKernel/GTests/NCollection_OccAllocator_Test.cxx create mode 100644 src/FoundationClasses/TKernel/GTests/NCollection_Vec4_Test.cxx create mode 100644 src/FoundationClasses/TKernel/GTests/OSD_Path_Test.cxx delete mode 100755 tests/bugs/fclasses/bug23569_1 delete mode 100755 tests/bugs/fclasses/bug23569_2 delete mode 100644 tests/bugs/fclasses/bug24831 delete mode 100755 tests/collections/grids.list delete mode 100644 tests/collections/n/array1 delete mode 100644 tests/collections/n/array2 delete mode 100644 tests/collections/n/arrayMove delete mode 100644 tests/collections/n/begin delete mode 100644 tests/collections/n/dblmap delete mode 100644 tests/collections/n/dmap delete mode 100644 tests/collections/n/end delete mode 100644 tests/collections/n/idmap delete mode 100644 tests/collections/n/imap delete mode 100644 tests/collections/n/list delete mode 100644 tests/collections/n/map delete mode 100644 tests/collections/n/osdpath delete mode 100644 tests/collections/n/seq delete mode 100644 tests/collections/n/vec4 delete mode 100644 tests/collections/n/vector delete mode 100644 tests/perf/fclasses/handle delete mode 100644 tests/perf/fclasses/strtod delete mode 100644 tests/perf/ncollection/A1 delete mode 100644 tests/perf/ncollection/A2 delete mode 100644 tests/perf/ncollection/A3 diff --git a/src/Draw/TKQADraw/QANCollection/FILES.cmake b/src/Draw/TKQADraw/QANCollection/FILES.cmake index 428163929b..5d65ef6ad5 100644 --- a/src/Draw/TKQADraw/QANCollection/FILES.cmake +++ b/src/Draw/TKQADraw/QANCollection/FILES.cmake @@ -5,8 +5,6 @@ set(OCCT_QANCollection_FILES FILES QANCollection.cxx QANCollection.hxx - QANCollection_Alloc.cxx - QANCollection_Handle.cxx QANCollection_Common.cxx QANCollection_Common.hxx QANCollection_DataMapIteratorOfDataMapOfRealPnt.hxx @@ -16,7 +14,4 @@ set(OCCT_QANCollection_FILES QANCollection_IndexedDataMapOfRealPnt.hxx QANCollection_ListIteratorOfListOfPnt.hxx QANCollection_ListOfPnt.hxx - QANCollection_Perf.cxx - QANCollection_Stl.cxx - QANCollection_Test.cxx ) diff --git a/src/Draw/TKQADraw/QANCollection/QANCollection.cxx b/src/Draw/TKQADraw/QANCollection/QANCollection.cxx index f640c8cb85..d2abbd2257 100644 --- a/src/Draw/TKQADraw/QANCollection/QANCollection.cxx +++ b/src/Draw/TKQADraw/QANCollection/QANCollection.cxx @@ -18,9 +18,7 @@ void QANCollection::Commands(Draw_Interpretor& theCommands) { - QANCollection::CommandsTest(theCommands); - QANCollection::CommandsPerf(theCommands); - QANCollection::CommandsAlloc(theCommands); - QANCollection::CommandsHandle(theCommands); - QANCollection::CommandsStl(theCommands); + // All QANCollection commands have been migrated to GTest format + // This function is kept for compatibility but does nothing + (void)theCommands; // Avoid unused parameter warning } diff --git a/src/Draw/TKQADraw/QANCollection/QANCollection.hxx b/src/Draw/TKQADraw/QANCollection/QANCollection.hxx index 2c03859bba..2268a073cf 100644 --- a/src/Draw/TKQADraw/QANCollection/QANCollection.hxx +++ b/src/Draw/TKQADraw/QANCollection/QANCollection.hxx @@ -28,16 +28,6 @@ public: DEFINE_STANDARD_ALLOC Standard_EXPORT static void Commands(Draw_Interpretor& DI); - - Standard_EXPORT static void CommandsTest(Draw_Interpretor& DI); - - Standard_EXPORT static void CommandsPerf(Draw_Interpretor& DI); - - Standard_EXPORT static void CommandsAlloc(Draw_Interpretor& DI); - - Standard_EXPORT static void CommandsStl(Draw_Interpretor& DI); - - Standard_EXPORT static void CommandsHandle(Draw_Interpretor& DI); }; #endif // _QANCollection_HeaderFile diff --git a/src/Draw/TKQADraw/QANCollection/QANCollection_Alloc.cxx b/src/Draw/TKQADraw/QANCollection/QANCollection_Alloc.cxx deleted file mode 100644 index e80b16d709..0000000000 --- a/src/Draw/TKQADraw/QANCollection/QANCollection_Alloc.cxx +++ /dev/null @@ -1,156 +0,0 @@ -// Created on: 2004-03-05 -// Created by: Mikhail KUZMITCHEV -// Copyright (c) 2004-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#include -#include - -#include -#include -#include - -#include -#include - -//================================================================================================= - -static Standard_Integer QANColStdAllocator1(Draw_Interpretor& di, - Standard_Integer argc, - const char** argv) -{ - if (argc != 1) - { - di << "Usage : " << argv[0] << "\n"; - return 1; - } - - // type definitions - typedef Handle(Standard_Transient) elem_type; - typedef NCollection_OccAllocator allocator_type; - Standard_STATIC_ASSERT(sizeof(allocator_type::value_type) == sizeof(elem_type)); - Standard_STATIC_ASSERT(sizeof(allocator_type::pointer) == sizeof(void*)); - Standard_STATIC_ASSERT(sizeof(allocator_type::const_pointer) == sizeof(void*)); - - elem_type aDummy; - allocator_type::reference aRef = aDummy; - (void)aRef; // avoid compiler warning on unused - allocator_type::const_reference aConstRef = aDummy; - (void)aConstRef; // avoid compiler warning on unused - Standard_STATIC_ASSERT(sizeof(allocator_type::size_type) == sizeof(size_t)); - Standard_STATIC_ASSERT(sizeof(allocator_type::difference_type) == sizeof(ptrdiff_t)); - - typedef int other_elem_type; - Standard_STATIC_ASSERT(sizeof(allocator_type::rebind::other::value_type) - == sizeof(other_elem_type)); - - return 0; -} - -//================================================================================================= - -static Standard_Integer QANColStdAllocator2(Draw_Interpretor& di, - Standard_Integer argc, - const char** argv) -{ - if (argc != 1) - { - di << "Usage : " << argv[0] << "\n"; - return 1; - } - - // create incremental allocator outside the scope of objects it will manage - Handle(NCollection_IncAllocator) anIncAlloc = new NCollection_IncAllocator(); - - { - // typed allocator - NCollection_OccAllocator aSAlloc(anIncAlloc); - std::list> aL(aSAlloc); - aL.push_back(2); - if (aL.size() == size_t(1)) - { - di << "Test1 : OK\n"; - } - else - { - di << "Test1 : Error\n"; - } - - // type cast - NCollection_OccAllocator aCAlloc; - std::vector> aV(aCAlloc); - aV.push_back(1); - if (aV.size() == size_t(1)) - { - di << "Test2 : OK\n"; - } - else - { - di << "Test2 : Error\n"; - } - - // using void-specialization allocator - NCollection_OccAllocator aVAlloc; - std::vector> aV2(aVAlloc); - - aV2.resize(10); - aV2.push_back(-1); - if (aV2.size() == size_t(11)) - { - di << "Test3 : OK\n"; - } - else - { - di << "Test3 : Error\n"; - } - - // equality of allocators - if (aSAlloc != aCAlloc) - { - di << "Test4 : OK\n"; - } - else - { - di << "Test4 : Error\n"; - } - NCollection_OccAllocator anIAlloc(anIncAlloc); - if (aSAlloc == anIAlloc) - { - di << "Test5 : OK\n"; - } - else - { - di << "Test5 : Error\n"; - } - } - - return 0; -} - -void QANCollection::CommandsAlloc(Draw_Interpretor& theCommands) -{ - const char* group = "QANCollection"; - - theCommands.Add("QANColStdAllocator1", - "QANColStdAllocator1", - __FILE__, - QANColStdAllocator1, - group); - theCommands.Add("QANColStdAllocator2", - "QANColStdAllocator2", - __FILE__, - QANColStdAllocator2, - group); - - return; -} diff --git a/src/Draw/TKQADraw/QANCollection/QANCollection_Handle.cxx b/src/Draw/TKQADraw/QANCollection/QANCollection_Handle.cxx deleted file mode 100644 index be57e9f7cc..0000000000 --- a/src/Draw/TKQADraw/QANCollection/QANCollection_Handle.cxx +++ /dev/null @@ -1,658 +0,0 @@ -// Copyright (c) 2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#include - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -// Auxiliary macro to check and report status. -// Note that if() is used to ensure that condition is -// evaluated before calls to stream output functions, to -// prevent side effects from such calls in cases when condition -// may contain references to freed objects in the stack. -#define CHECK(di, ok, what) \ - if (ok) \ - di << "Checking " << what << ": OK\n"; \ - else \ - di << "Checking " << what << ": Error\n" - -//======================================================================= -// function : QAHandleOps -// purpose : Test Handle operations (mostly compile-time checks) -//======================================================================= - -// set of overloaded functions for checking resolution of arguments -inline void f(const Handle(Geom_Curve)&) {} - -inline void func(const Handle(Geom_Curve)&) {} - -inline void func(const Handle(Geom_BSplineCurve)&) {} - -inline void func(const Handle(Geom_Surface)&) {} - -inline void func(const Handle(gp_Pnt)&) {} - -inline void func(const Handle(gp_XYZ)&) {} - -inline void func(const Handle(gp_Trsf)&) {} - -static Standard_Integer QAHandleOps(Draw_Interpretor& theDI, - Standard_Integer /*theArgNb*/, - const char** /*theArgVec*/) -{ - // =============================================================== - // Part 1: classes inheriting transient - // =============================================================== - - Handle(Geom_Line) aLine = new Geom_Line(gp::Origin(), gp::DZ()); - CHECK(theDI, !aLine.IsNull(), "handle for non-null"); - - const Handle(Geom_Line)& cLine = aLine; // cast to self const ref - const Handle(Geom_Curve)& cCurve = aLine; // cast to base const ref - Geom_Line* pLine = aLine.get(); - const Geom_Line* cpLine = aLine.get(); - Geom_Line& rLine = *aLine; - const Geom_Line& crLine = *cLine; - Handle(Geom_Curve) aCurve = aLine; // copy from handle to derived type - aCurve = cLine; // assignment to handle of derived type - Handle(Geom_Line) dLine(cpLine); // copy from handle to derived type - - aLine = Handle(Geom_Line)::DownCast(cCurve); - CHECK(theDI, !aLine.IsNull(), "down cast"); - - // comparison operators - CHECK(theDI, aLine == aLine, "equality of handle to itself"); - CHECK(theDI, cLine == cLine, "equality of const handle to itself"); - CHECK(theDI, aLine == cLine, "equality of const and non-const handle"); - CHECK(theDI, aLine == cCurve, "equality of handle and base handle"); - CHECK(theDI, aLine == pLine, "equality of handle and pointer"); - CHECK(theDI, pLine == aLine, "equality of pointer and handle"); - CHECK(theDI, aLine == cpLine, "equality of handle and const pointer"); - CHECK(theDI, cpLine == aLine, "equality of const pointer and handle"); - CHECK(theDI, &rLine == aLine, "equality of reference and handle"); - CHECK(theDI, &crLine == aLine, "equality of reference and handle"); - CHECK(theDI, aLine, "cast to bool"); - - Handle(Geom_Line) aLin2; - CHECK(theDI, aLine != aLin2, "inequality of handle to the same type handle"); - CHECK(theDI, aLin2 != cLine, "inequality of const and non-const handle"); - CHECK(theDI, aLin2 != cCurve, "inequality of handle and base handle"); - CHECK(theDI, aLin2 != pLine, "inequality of handle and pointer"); - CHECK(theDI, pLine != aLin2, "inequality of pointer and handle"); - CHECK(theDI, aLin2 != cpLine, "inequality of handle and const pointer"); - CHECK(theDI, cpLine != aLin2, "inequality of const pointer and handle"); - - Handle(Geom_Curve) aCur2; - CHECK(theDI, aLine != aCur2, "inequality of handles of different types"); - CHECK(theDI, aCur2 != cLine, "inequality of const and non-const handle"); - CHECK(theDI, aCur2 != cCurve, "inequality of handle and base handle"); - CHECK(theDI, aCur2 != pLine, "inequality of handle and pointer"); - CHECK(theDI, pLine != aCur2, "inequality of pointer and handle"); - CHECK(theDI, aCur2 != cpLine, "inequality of handle and const pointer"); - CHECK(theDI, cpLine != aCur2, "inequality of const pointer and handle"); - - // passing handle as reference to base class - f(aLine); - - // passing handle to overloaded function accepting handle to another type - // will fail on VC below 12 and GCC below 4.3 due to ambiguity of overloads -#if __cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1800) \ - || (defined(__GNUC__) && __GNUC__ >= 4 && __GNUC_MINOR__ >= 3) - func(aLine); - func(cLine); -#endif - - const Handle(Geom_Curve)& aCurve2 = aLine; // cast to base const ref - CHECK(theDI, !aCurve2.IsNull(), "cast to base class const reference"); - - Handle(Geom_Line) qLine = cpLine; // constructor from const pointer -- could be made explicit... - - // check that compiler keeps temporary object referenced by local variable - const Handle(Geom_Line)& aTmpRef(Handle(Geom_Line)::DownCast(aCurve2)); - // note that here and in similar checks below we use comparison of pointers instead - // of checking handle for Null, since such check may fail if temporary object is - // destroyed prematurely and its location is used for other object. - CHECK(theDI, aTmpRef.get() == aCurve2.get(), "local reference of to temporary handle object"); - - // check undesired but logical situation: - // compiler does not keep temporary object referenced by local variable of base type; - // here compiler does not recognize that it should keep the temporary object because handle - // classes do not inherit each other and they use hard cast for references to simulate inheritance -#if defined(__GNUC__) && (__GNUC__ > 12) - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wdangling-reference" -#endif - const Handle(Geom_Curve)& aTmpRefBase(Handle(Geom_Line)::DownCast(aCurve2)); - CHECK(theDI, - aTmpRefBase.get() != aCurve2.get(), - "local reference to temporary handle object (base type)"); -#if defined(__GNUC__) && (__GNUC__ > 12) - #pragma GCC diagnostic pop -#endif - - // check operations with Handle_* classes - Handle(Geom_Line) hLine = aLine; - CHECK(theDI, !hLine.IsNull(), "hhandle for non-null"); -#include - const Handle_Geom_Line& chLine = aLine; // cast to self const ref - const Handle_Geom_Curve& chCurve = aLine; // cast to base const ref - const Handle_Geom_Line& hhLine = hLine; // cast to self const ref - const Handle_Geom_Curve& hhCurve = hLine; // cast to base const ref - Handle_Geom_Curve hCurve = aLine; // copy from handle to derived type - Handle_Geom_Line phLine(aLine.get()); // construct from pointer - - hLine = Handle_Geom_Line::DownCast(cCurve); // inheritance of downcast - CHECK(theDI, !hLine.IsNull(), "down cast"); - - // comparison operators - CHECK(theDI, hLine == hLine, "equality of hhandle to itself"); - CHECK(theDI, hLine == aLine, "equality of hhandle to handle"); - CHECK(theDI, hhLine == hLine, "equality of hhandle to const"); - CHECK(theDI, chLine == hLine, "equality of hhandle to const"); - CHECK(theDI, hhCurve == hLine, "equality of hhandle to const"); - CHECK(theDI, chCurve == hLine, "equality of hhandle to const"); - CHECK(theDI, hLine, "cast to bool"); - - // passing hhandle as reference to base class - f(hLine); - - // passing handle to overloaded function accepting handle to another type - // will fail on VC below 12 and GCC below 4.3 due to ambiguity of overloads -#if __cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1800) \ - || (defined(__GNUC__) && __GNUC__ >= 4 && __GNUC_MINOR__ >= 3) - func(hLine); - func(chLine); -#endif - - Handle_Geom_Line qhLine = cpLine; // constructor from const pointer -- could be made explicit... - - // check that compiler keeps temporary object referenced by local variable -#if defined(__GNUC__) && (__GNUC__ > 12) - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wdangling-reference" -#endif - const Handle_Geom_Line& hTmpRef(Handle(Geom_Line)::DownCast(aCurve2)); - CHECK(theDI, hTmpRef.get() == aCurve2.get(), "local reference to temporary object (Handle_)"); - - // check lifetime of temporary object referenced by local variable (base type) - const Handle_Geom_Curve& hTmpRefBase(Handle(Geom_Line)::DownCast(aCurve2)); -#if defined(__GNUC__) && (__GNUC__ > 11) - #pragma GCC diagnostic pop -#endif - // here we have different behavior for MSVC 2013+ where Handle_ is a class - // (compiler creates temporary object of approprtiate type and keeps it living - // until the reference is valid) and other compilers where Handle_ is - // typedef to handle<> (compiler does not know that the reference that is being - // assigned is pointing to temporary object, due to involved type cast operation) -#if (defined(_MSC_VER) && _MSC_VER >= 1800) - CHECK(theDI, - hTmpRefBase.get() == aCurve2.get(), - "local reference to temporary handle object (Handle_ to base type)"); -#else - CHECK(theDI, - hTmpRefBase.get() != aCurve2.get(), - "local reference to temporary handle object (Handle_ to base type)"); -#endif -#include - Handle(Geom_Surface) aSurf; - (void)aSurf; - -#if 0 - // each test in this section must cause compiler error - gunc (cLine); // passing const handle as non-const reference to base type - pLine = cLine.get(); // getting non-const pointer to contained object from const handle - Handle(Geom_Line) xLine = cCurve; // copy from handle to base type -// clang-format off - Handle(Geom_BSplineCurve) aBSpl (new Geom_Line (gp::Origin(), gp::DX())); // construction from pointer to incompatible type -// clang-format on - - CHECK(theDI, aLine == aSurf, "equality of handles of incompatible types"); - CHECK(theDI, aSurf == cLine, "equality of const and non-const handle"); - CHECK(theDI, aSurf == cCurve, "equality of handle and base handle"); - CHECK(theDI, aSurf == pLine, "equality of handle and pointer"); - CHECK(theDI, pLine == aSurf, "equality of pointer and handle"); - CHECK(theDI, aSurf == cpLine, "equality of handle and const pointer"); - CHECK(theDI, cpLine != aSurf, "equality of const pointer and handle"); - - CHECK(theDI, aLine != aSurf, "inequality of handles of incompatible types"); - CHECK(theDI, aSurf != cLine, "inequality of const and non-const handle"); - CHECK(theDI, aSurf != cCurve, "inequality of handle and base handle"); - CHECK(theDI, aSurf != pLine, "inequality of handle and pointer"); - CHECK(theDI, pLine != aSurf, "inequality of pointer and handle"); - CHECK(theDI, aSurf != cpLine, "inequality of handle and const pointer"); - CHECK(theDI, cpLine != aSurf, "inequality of const pointer and handle"); -#endif - - // =============================================================== - // Part 2: classes not inheriting transient - // =============================================================== - /* - Handle(gp_Pnt) aPnt = new gp_Pnt (gp::Origin()); - CHECK(theDI, ! aPnt.IsNull(), "handle for non-null"); - - const Handle(gp_Pnt)& cPnt = aPnt; // cast to self const ref - // const Handle(gp_XYZ)& cXYZ = aPnt; // cast to base const ref - gp_Pnt* pPnt = aPnt.get(); - const gp_Pnt* cpPnt = aPnt.get(); - gp_Pnt& rPnt = *aPnt; - const gp_Pnt& crPnt = *cPnt; - // Handle(gp_XYZ) aXYZ = aPnt; // copy from handle to derived type - // aXYZ = cPnt; // assignment to handle of derived type - - // aPnt = Handle(gp_Pnt)::DownCast (cXYZ); - // CHECK(theDI, ! aPnt.IsNull(), "down cast"); - - // comparison operators - CHECK(theDI, aPnt == aPnt, "equality of handle to itself"); - CHECK(theDI, cPnt == cPnt, "equality of const handle to itself"); - CHECK(theDI, aPnt == cPnt, "equality of const and non-const handle"); - // CHECK(theDI, aPnt == cXYZ, "equality of handle and base handle"); - CHECK(theDI, aPnt == pPnt, "equality of handle and pointer"); - CHECK(theDI, pPnt == aPnt, "equality of pointer and handle"); - CHECK(theDI, aPnt == cpPnt, "equality of handle and const pointer"); - CHECK(theDI, cpPnt == aPnt, "equality of const pointer and handle"); - CHECK(theDI, &rPnt == aPnt, "equality of reference and handle"); - CHECK(theDI, &crPnt == aPnt, "equality of reference and handle"); - - Handle(gp_Pnt) aPnt2; - CHECK(theDI, aPnt != aPnt2, "inequality of handle to the same type handle"); - CHECK(theDI, aPnt2 != cPnt, "inequality of const and non-const handle"); - // CHECK(theDI, aPnt2 != cXYZ, "inequality of handle and base handle"); - CHECK(theDI, aPnt2 != pPnt, "inequality of handle and pointer"); - CHECK(theDI, pPnt != aPnt2, "inequality of pointer and handle"); - CHECK(theDI, aPnt2 != cpPnt, "inequality of handle and const pointer"); - CHECK(theDI, cpPnt != aPnt2, "inequality of const pointer and handle"); - - Handle(gp_XYZ) aXYZ2; - CHECK(theDI, aLine != aPnt2, "inequality of handles of different types"); - CHECK(theDI, aXYZ2 != cPnt, "inequality of const and non-const handle"); - // CHECK(theDI, aXYZ2 != cXYZ, "inequality of handle and base handle"); - // CHECK(theDI, aXYZ2 != pPnt, "inequality of handle and pointer"); - // CHECK(theDI, pPnt != aXYZ2, "inequality of pointer and handle"); - // CHECK(theDI, aXYZ2 != cpPnt, "inequality of handle and const pointer"); - // CHECK(theDI, cpPnt != aXYZ2, "inequality of const pointer and handle"); - - // passing handle as reference to base class - func (aPnt); - func (cPnt); - */ - return 0; -} - -//======================================================================= -// function : QAHandleBool -// purpose : Test Handle -> bool conversion -//======================================================================= -static Standard_Integer QAHandleBool(Draw_Interpretor& theDI, - Standard_Integer /*theArgNb*/, - const char** /*theArgVec*/) -{ - Handle(NCollection_BaseAllocator) aPtr = new NCollection_IncAllocator(); - - Handle(NCollection_IncAllocator) anInc = Handle(NCollection_IncAllocator)::DownCast(aPtr); - CHECK(theDI, !anInc.IsNull(), "cast to NCollection_IncAllocator"); - - Handle(NCollection_BaseAllocator) anAlloc = aPtr; - CHECK(theDI, !anAlloc.IsNull(), "cast to NCollection_BaseAllocator"); - - Handle(NCollection_HeapAllocator) aHAlloc = Handle(NCollection_HeapAllocator)::DownCast(aPtr); - CHECK(theDI, aHAlloc.IsNull(), "cast to NCollection_HeapAllocator"); - - return 0; -} - -// Auxiliary class to define new virtual methods -class Transient_Root : public Standard_Transient -{ -public: - virtual const char* Name() const { return "Transient_Root"; } - - virtual Standard_Transient* CreateParent() const { return new Standard_Transient; } - - virtual Standard_Transient* Clone() const { return new Transient_Root; } - DEFINE_STANDARD_RTTI_INLINE(Transient_Root, Standard_Transient) -}; -DEFINE_STANDARD_HANDLE(Transient_Root, Standard_Transient) - -// Auxiliary macros to create hierarchy of 50 classes -#define QA_DEFINECLASS(theClass, theParent) \ - class theClass : public theParent \ - { \ - public: \ - virtual const char* Name() const Standard_OVERRIDE \ - { \ - return #theClass; \ - } \ - virtual Standard_Transient* CreateParent() const Standard_OVERRIDE \ - { \ - return new theParent(); \ - } \ - virtual Standard_Transient* Clone() const Standard_OVERRIDE \ - { \ - return new theClass(); \ - } \ - DEFINE_STANDARD_RTTI_INLINE(theClass, theParent) \ - }; \ - DEFINE_STANDARD_HANDLE(theClass, theParent) - -#define QA_NAME(theNum) qaclass##theNum##_##50 -#define QA_HANDLE_NAME(theNum) Handle(qaclass##theNum##_##50) - -#define QA_DEFINECLASS10(theParent, theTens) \ - QA_DEFINECLASS(QA_NAME(theTens##0), theParent) \ - QA_DEFINECLASS(QA_NAME(theTens##1), QA_NAME(theTens##0)) \ - QA_DEFINECLASS(QA_NAME(theTens##2), QA_NAME(theTens##1)) \ - QA_DEFINECLASS(QA_NAME(theTens##3), QA_NAME(theTens##2)) \ - QA_DEFINECLASS(QA_NAME(theTens##4), QA_NAME(theTens##3)) \ - QA_DEFINECLASS(QA_NAME(theTens##5), QA_NAME(theTens##4)) \ - QA_DEFINECLASS(QA_NAME(theTens##6), QA_NAME(theTens##5)) \ - QA_DEFINECLASS(QA_NAME(theTens##7), QA_NAME(theTens##6)) \ - QA_DEFINECLASS(QA_NAME(theTens##8), QA_NAME(theTens##7)) \ - QA_DEFINECLASS(QA_NAME(theTens##9), QA_NAME(theTens##8)) - -QA_DEFINECLASS10(Transient_Root, 0) -QA_DEFINECLASS10(qaclass09_50, 1) -QA_DEFINECLASS10(qaclass19_50, 2) -QA_DEFINECLASS10(qaclass29_50, 3) -QA_DEFINECLASS10(qaclass39_50, 4) -QA_DEFINECLASS(qaclass50_50, qaclass49_50) - -namespace -{ -class qaclass50_50ANON : public qaclass49_50 -{ -}; -} // namespace - -namespace QaNamespace -{ -class qaclass50_50 : public qaclass49_50 -{ -public: - qaclass50_50() {} -}; -} // namespace QaNamespace - -namespace -{ -//! Timer sentry. Prints elapsed time information at destruction time. -class QATimer : public OSD_Timer -{ -public: - enum TimeFormat - { - Seconds, - Milliseconds, - Microseconds, - Nanoseconds, - s = Seconds, - ms = Milliseconds, - ns = Nanoseconds, - }; - -public: - //! Main constructor - automatically starts the timer. - QATimer(Draw_Interpretor& theDI, - Standard_CString theTitle, - const TimeFormat theFormat, - const Standard_Integer theNbIters = 1, - const Standard_Boolean theToPrintFormat = Standard_False) - : myDI(&theDI), - myTitle(theTitle), - myFormat(theFormat), - myNbIters(theNbIters), - myToPrintFormat(theToPrintFormat) - { - Start(); - } - - //! Destructor - stops the timer and prints statistics. - ~QATimer() - { - Stop(); - if (myTitle != NULL) - { - (*myDI) << myTitle; - } - switch (myFormat) - { - case Seconds: - (*myDI) << ElapsedTime() / Standard_Real(myNbIters); - if (myToPrintFormat) - { - (*myDI) << " s"; - } - break; - case Milliseconds: - (*myDI) << (ElapsedTime() / Standard_Real(myNbIters)) * 1000.0; - if (myToPrintFormat) - { - (*myDI) << " ms"; - } - break; - case Microseconds: - (*myDI) << (ElapsedTime() / Standard_Real(myNbIters)) * 1000000.0; - if (myToPrintFormat) - { - (*myDI) << " microseconds"; - } - break; - case Nanoseconds: - (*myDI) << (ElapsedTime() / Standard_Real(myNbIters)) * 1000000000.0; - if (myToPrintFormat) - { - (*myDI) << " ns"; - } - break; - } - } - -private: - Draw_Interpretor* myDI; - Standard_CString myTitle; //!< timer description - TimeFormat myFormat; //!< time format - Standard_Integer myNbIters; //!< iterations number - Standard_Boolean myToPrintFormat; //!< add time format -}; -} // anonymous namespace - -//======================================================================= -// function : QAHandleInc -// purpose : Estimate the smart-pointer counter incrementing time -//======================================================================= -static Standard_Integer QAHandleInc(Draw_Interpretor& theDI, - Standard_Integer theArgNb, - const char** theArgVec) -{ - if (theArgNb > 2) - { - std::cout << "Error: wrong syntax! See usage:\n"; - theDI.PrintHelp(theArgVec[0]); - return 1; - } - const Standard_Integer aNbIters = (theArgNb > 1) ? Draw::Atoi(theArgVec[1]) : 10000000; - if (aNbIters < 1) - { - std::cout << "Error: number of iterations should be positive!\n"; - return 1; - } - - Handle(Standard_Transient) aHandle = new Standard_Transient(); - std::shared_ptr aSharePtr(new Standard_Transient()); - theDI << "Time of creating and destroying " << aNbIters - << " smart pointers to the same object, per item, ns:"; - { - { - QATimer aTimer(theDI, "\nOCCT Handle: ", QATimer::ns, aNbIters); - { - std::vector aHandles(aNbIters); - for (Standard_Integer anIter = 0; anIter < aNbIters; ++anIter) - { - aHandles[anIter] = aHandle; - } - } - } - { - QATimer aTimer(theDI, "\nC++ shared_ptr: ", QATimer::ns, aNbIters); - { - std::vector> aSharePointers(aNbIters); - for (Standard_Integer anIter = 0; anIter < aNbIters; ++anIter) - { - aSharePointers[anIter] = aSharePtr; - } - } - } - } - return 0; -} - -//================================================================================================= - -static Standard_Integer QAHandleKind(Draw_Interpretor& /*theDI*/, - Standard_Integer /*theArgNb*/, - const char** /*theArgVec*/) -{ - Handle(Standard_Type) aType00 = STANDARD_TYPE(qaclass00_50); - Handle(Standard_Type) aType10 = STANDARD_TYPE(qaclass10_50); - Handle(Standard_Type) aType20 = STANDARD_TYPE(qaclass20_50); - Handle(Standard_Type) aType30 = STANDARD_TYPE(qaclass30_50); - Handle(Standard_Type) aType40 = STANDARD_TYPE(qaclass40_50); - Handle(Standard_Type) aType50 = STANDARD_TYPE(qaclass50_50); - - Handle(qaclass00_50) aHandle = new qaclass40_50(); - -#define QA_CHECK(theDesc, theExpr, theValue) \ - { \ - const bool isTrue = !!(theExpr); \ - std::cout << theDesc << (isTrue ? " TRUE " : " FALSE ") \ - << (isTrue == theValue ? " is OK\n" : " is Error\n"); \ - } - - std::cout << "Check instance of " << aHandle->DynamicType()->Name() << "\n"; - for (Handle(Standard_Type) aType = aHandle->DynamicType(); !aType.IsNull(); - aType = aType->Parent()) - { - std::cout << " - " << aType->Name() << "\n"; - } - - QA_CHECK("Name == qaclass40_50 : ", - TCollection_AsciiString("qaclass40_50") == aHandle->DynamicType()->Name(), - true); - - QA_CHECK("IsKind (aType00) : ", aHandle->IsKind(aType00), true); - QA_CHECK("IsKind (aType10) : ", aHandle->IsKind(aType10), true); - QA_CHECK("IsKind (aType20) : ", aHandle->IsKind(aType20), true); - QA_CHECK("IsKind (aType30) : ", aHandle->IsKind(aType30), true); - QA_CHECK("IsKind (aType40) : ", aHandle->IsKind(aType40), true); - QA_CHECK("IsKind (aType50) : ", aHandle->IsKind(aType50), false); - - QA_CHECK("IsKind (\"qaclass00_50\"): ", aHandle->IsKind("qaclass00_50"), true); - QA_CHECK("IsKind (\"qaclass10_50\"): ", aHandle->IsKind("qaclass10_50"), true); - QA_CHECK("IsKind (\"qaclass20_50\"): ", aHandle->IsKind("qaclass20_50"), true); - QA_CHECK("IsKind (\"qaclass30_50\"): ", aHandle->IsKind("qaclass30_50"), true); - QA_CHECK("IsKind (\"qaclass40_50\"): ", aHandle->IsKind("qaclass40_50"), true); - QA_CHECK("IsKind (\"qaclass50_50\"): ", aHandle->IsKind("qaclass50_50"), false); - - QA_CHECK("IsInstance (aType00) : ", aHandle->IsInstance(aType00), false); - QA_CHECK("IsInstance (aType10) : ", aHandle->IsInstance(aType10), false); - QA_CHECK("IsInstance (aType20) : ", aHandle->IsInstance(aType20), false); - QA_CHECK("IsInstance (aType30) : ", aHandle->IsInstance(aType30), false); - QA_CHECK("IsInstance (aType40) : ", aHandle->IsInstance(aType40), true); - QA_CHECK("IsInstance (aType50) : ", aHandle->IsInstance(aType50), false); - -#ifdef HAVE_CPP11 - std::cout << "\nC++11:\n"; - std::type_index aCppType = typeid(*aHandle.operator->()); - std::cout << "typeid().name() = '" << typeid(*aHandle.operator->()).name() << "'\n"; - #ifdef _MSC_VER - std::cout << "typeid().raw_name()= '" << typeid(*aHandle.operator->()).raw_name() << "'\n"; - #endif - - std::cout << "[ANON]typeid().name() = '" << typeid(qaclass50_50ANON).name() << "'\n"; - #ifdef _MSC_VER - std::cout << "[ANON]typeid().raw_name()= '" << typeid(qaclass50_50ANON).raw_name() << "'\n"; - #endif - - std::cout << "[NS]typeid().name() = '" << typeid(QaNamespace::qaclass50_50).name() << "'\n"; - #ifdef _MSC_VER - std::cout << "[NS]typeid().raw_name()= '" << typeid(QaNamespace::qaclass50_50).raw_name() - << "'\n"; - #endif - - QA_CHECK("is typeid (aType00) : ", - typeid(*aHandle.operator->()) == typeid(qaclass00_50), - false); - QA_CHECK("is typeid (aType10) : ", - typeid(*aHandle.operator->()) == typeid(qaclass10_50), - false); - QA_CHECK("is typeid (aType20) : ", - typeid(*aHandle.operator->()) == typeid(qaclass20_50), - false); - QA_CHECK("is typeid (aType30) : ", - typeid(*aHandle.operator->()) == typeid(qaclass30_50), - false); - QA_CHECK("is typeid (aType40) : ", - typeid(*aHandle.operator->()) == typeid(qaclass40_50), - true); - QA_CHECK("is typeid (aType50) : ", - typeid(*aHandle.operator->()) == typeid(qaclass50_50), - false); - - QA_CHECK("is type_index (aType00) : ", aCppType == typeid(qaclass00_50), false); - QA_CHECK("is type_index (aType40) : ", aCppType == typeid(qaclass40_50), true); - - QA_CHECK("IsClass(Standard_Transient): ", - std::is_class::value - == !!STANDARD_TYPE(Standard_Transient)->IsClass(), - true); - // QA_CHECK ("IsEnum (Message_Status) : ", std::is_enum::value == - // !!STANDARD_TYPE(Message_Status)->IsEnumeration(), true); -#endif - - return 0; -} - -void QANCollection::CommandsHandle(Draw_Interpretor& theCommands) -{ - const char* THE_GROUP = "QANCollection"; - theCommands.Add("QAHandleBool", - "Test handle boolean operator", - __FILE__, - QAHandleBool, - THE_GROUP); - theCommands.Add("QAHandleInc", - "QAHandleInc nbIter=1000000" - "\n\t\t: Test handle increment performance", - __FILE__, - QAHandleInc, - THE_GROUP); - theCommands.Add("QAHandleKind", "Test handle IsKind", __FILE__, QAHandleKind, THE_GROUP); - theCommands.Add("QAHandleOps", "Test handle operations", __FILE__, QAHandleOps, THE_GROUP); - return; -} diff --git a/src/Draw/TKQADraw/QANCollection/QANCollection_Perf.cxx b/src/Draw/TKQADraw/QANCollection/QANCollection_Perf.cxx deleted file mode 100644 index 657b82489d..0000000000 --- a/src/Draw/TKQADraw/QANCollection/QANCollection_Perf.cxx +++ /dev/null @@ -1,1046 +0,0 @@ -// Created on: 2004-03-05 -// Created by: Mikhail KUZMITCHEV -// Copyright (c) 2004-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#include -#include - -#include -#include - -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#include -#include - -#define PERF_ENABLE_METERS -#include - -#define ItemType gp_Pnt -#define Key1Type Standard_Real -#define Key2Type Standard_Integer - -// ===================== INSTANTIATIONS =========== -// ===================== The Types must be defined before this line =========== -// These are: TheItemType, TheKey1Type, TheKey2Type -// So must be defined ::HashCode and ::IsEqual too - -#include -#define DEFINE_ARRAY1(_ClassName_, _BaseCollection_, TheItemType) \ - typedef NCollection_Array1 _ClassName_; - -////////////////////////////////DEFINE_ARRAY1(QANCollection_Array1,QANCollection_BaseCol,ItemType) -////////////////////////////////DEFINE_HARRAY1(QANCollection_HArray1,QANCollection_Array1) -DEFINE_ARRAY1(QANCollection_Array1Perf, QANCollection_BaseColPerf, ItemType) -DEFINE_HARRAY1(QANCollection_HArray1Perf, QANCollection_Array1Perf) - -#include -#define DEFINE_ARRAY2(_ClassName_, _BaseCollection_, TheItemType) \ - typedef NCollection_Array2 _ClassName_; -////////////////////////////////DEFINE_ARRAY2(QANCollection_Array2,QANCollection_BaseCol,ItemType) -////////////////////////////////DEFINE_HARRAY2(QANCollection_HArray2,QANCollection_Array2) -DEFINE_ARRAY2(QANCollection_Array2Perf, QANCollection_BaseColPerf, ItemType) -DEFINE_HARRAY2(QANCollection_HArray2Perf, QANCollection_Array2Perf) -////////////////////////////////DEFINE_MAP(QANCollection_Map,QANCollection_Key1BaseCol,Key1Type) -////////////////////////////////DEFINE_DATAMAP(QANCollection_DataMap,QANCollection_BaseCol,Key1Type,ItemType) -////////////////////////////////DEFINE_DOUBLEMAP(QANCollection_DoubleMap,QANCollection_Key2BaseCol,Key1Type,Key2Type) -////////////////////////////////DEFINE_INDEXEDMAP(QANCollection_IndexedMap,QANCollection_Key1BaseCol,Key1Type) -////////////////////////////////DEFINE_INDEXEDDATAMAP(QANCollection_IDMap,QANCollection_BaseCol,Key1Type,ItemType) -#define DEFINE_DATAMAP(_ClassName_, _BaseCollection_, TheKeyType, TheItemType) \ - typedef NCollection_DataMap _ClassName_; -#define DEFINE_DOUBLEMAP(_ClassName_, _BaseCollection_, TheKey1Type, TheKey2Type) \ - typedef NCollection_DoubleMap _ClassName_; -#define DEFINE_INDEXEDDATAMAP(_ClassName_, _BaseCollection_, TheKeyType, TheItemType) \ - typedef NCollection_IndexedDataMap _ClassName_; -#define DEFINE_INDEXEDMAP(_ClassName_, _BaseCollection_, TheKeyType) \ - typedef NCollection_IndexedMap _ClassName_; -#define DEFINE_MAP(_ClassName_, _BaseCollection_, TheKeyType) \ - typedef NCollection_Map _ClassName_; -DEFINE_MAP(QANCollection_MapPerf, QANCollection_Key1BaseColPerf, Key1Type) -DEFINE_DATAMAP(QANCollection_DataMapPerf, QANCollection_BaseColPerf, Key1Type, ItemType) -DEFINE_DOUBLEMAP(QANCollection_DoubleMapPerf, QANCollection_Key2BaseColPerf, Key1Type, Key2Type) -DEFINE_INDEXEDMAP(QANCollection_IndexedMapPerf, QANCollection_Key1BaseColPerf, Key1Type) -DEFINE_INDEXEDDATAMAP(QANCollection_IDMapPerf, QANCollection_BaseColPerf, Key1Type, ItemType) - -////////////////////////////////DEFINE_LIST(QANCollection_List,QANCollection_BaseCol,ItemType) -#define DEFINE_LIST(_ClassName_, _BaseCollection_, TheItemType) \ - typedef NCollection_List _ClassName_; -DEFINE_LIST(QANCollection_ListPerf, QANCollection_BaseColPerf, ItemType) - -#include -#define DEFINE_SEQUENCE(_ClassName_, _BaseCollection_, TheItemType) \ - typedef NCollection_Sequence _ClassName_; -////////////////////////////////DEFINE_SEQUENCE(QANCollection_Sequence,QANCollection_BaseCol,ItemType) -////////////////////////////////DEFINE_HSEQUENCE(QANCollection_HSequence,QANCollection_Sequence) -DEFINE_SEQUENCE(QANCollection_SequencePerf, QANCollection_BaseColPerf, ItemType) -DEFINE_HSEQUENCE(QANCollection_HSequencePerf, QANCollection_SequencePerf) - -static void printAllMeters(Draw_Interpretor& theDI) -{ - const TCollection_AsciiString aStr = OSD_PerfMeter::PrintALL(); - theDI << aStr << "\n"; - OSD_PerfMeter::ResetALL(); -} - -// ===================== Test perform of Array1 type ========================== -static void CompArray1(Draw_Interpretor& theDI, - const Standard_Integer theRep, - const Standard_Integer theSize) -{ - Standard_Integer i, j; - - for (i = 0; i < theRep; i++) - { - OSD_PerfMeter aCreationMeter("NCollection_Array1 creation"); - QANCollection_Array1Perf a1(1, theSize), a2(1, theSize); - aCreationMeter.Stop(); - - OSD_PerfMeter aFillingMeter("NCollection_Array1 filling"); - for (j = 1; j <= theSize; j++) - Random(a1(j)); - aFillingMeter.Stop(); - - OSD_PerfMeter aFindingMeter("NCollection_Array1 finding"); - for (j = 1; j <= theSize; j++) - { - Standard_Integer iIndex; - Random(iIndex, theSize); - a1.Value(iIndex + 1); - } - aFindingMeter.Stop(); - - OSD_PerfMeter aAssignOperMeter("NCollection_Array1 operator="); - a2 = a1; - aAssignOperMeter.Stop(); - - OSD_PerfMeter aAssignFnMeter("NCollection_Array1 Assign"); - a2.Assign(a1); - aAssignFnMeter.Stop(); - } - - for (i = 0; i < theRep; i++) - { - OSD_PerfMeter aCreationMeter("TCollection_Array1 creation"); - TColgp_Array1OfPnt a1(1, theSize), a2(1, theSize); - aCreationMeter.Stop(); - - OSD_PerfMeter aFillingMeter("TCollection_Array1 filling"); - for (j = 1; j <= theSize; j++) - { - Random(a1(j)); - } - aFillingMeter.Stop(); - - OSD_PerfMeter aFindingMeter("TCollection_Array1 finding"); - for (j = 1; j <= theSize; j++) - { - Standard_Integer iIndex; - Random(iIndex, theSize); - a1.Value(iIndex + 1); - } - aFindingMeter.Stop(); - - OSD_PerfMeter aAssignOperMeter("TCollection_Array1 operator="); - a2 = a1; - aAssignOperMeter.Stop(); - } - printAllMeters(theDI); -} - -// ===================== Test perform of Array2 type ========================== -static void CompArray2(Draw_Interpretor& theDI, - const Standard_Integer theRep, - const Standard_Integer theSize) -{ - Standard_Integer i, j, k; - for (i = 0; i < theRep; i++) - { - OSD_PerfMeter aCreationMeter("NCollection_Array2 creation"); - QANCollection_Array2Perf a1(1, theSize, 1, theSize), a2(1, theSize, 1, theSize); - aCreationMeter.Stop(); - - OSD_PerfMeter aFillingMeter("NCollection_Array2 filling"); - for (j = 1; j <= theSize; j++) - for (k = 1; k <= theSize; k++) - Random(a1(j, k)); - aFillingMeter.Stop(); - - OSD_PerfMeter aFindingMeter("NCollection_Array2 finding"); - for (j = 1; j <= theSize * theSize; j++) - { - Standard_Integer m, n; - Random(m, theSize); - Random(n, theSize); - a1.Value(m + 1, n + 1); - } - aFindingMeter.Stop(); - - OSD_PerfMeter aAssignOperMeter("NCollection_Array2 operator="); - a2 = a1; - aAssignOperMeter.Stop(); - - OSD_PerfMeter aAssignFnMeter("NCollection_Array2 Assign"); - a2.Assign(a1); - aAssignFnMeter.Stop(); - } - - for (i = 0; i < theRep; i++) - { - OSD_PerfMeter aCreationMeter("TCollection_Array2 creation"); - TColgp_Array2OfPnt a1(1, theSize, 1, theSize), a2(1, theSize, 1, theSize); - aCreationMeter.Stop(); - - OSD_PerfMeter aFillingMeter("TCollection_Array2 filling"); - for (j = 1; j <= theSize; j++) - for (k = 1; k <= theSize; k++) - Random(a1(j, k)); - aFillingMeter.Stop(); - - OSD_PerfMeter aFindingMeter("TCollection_Array2 finding"); - for (j = 1; j <= theSize * theSize; j++) - { - Standard_Integer m, n; - Random(m, theSize); - Random(n, theSize); - a1.Value(m + 1, n + 1); - } - aFindingMeter.Stop(); - - OSD_PerfMeter aAssignOperMeter("TCollection_Array2 operator="); - a2 = a1; - aAssignOperMeter.Stop(); - } - printAllMeters(theDI); -} - -// ===================== Test perform of List type ========================== -static void CompList(Draw_Interpretor& theDI, - const Standard_Integer theRep, - const Standard_Integer theSize) -{ - Standard_Integer i, j; - - for (i = 0; i < theRep; i++) - { - QANCollection_ListPerf a1, a2; - - OSD_PerfMeter aAppendingMeter("NCollection_List appending"); - for (j = 1; j <= theSize; j++) - { - ItemType anItem; - Random(anItem); - a1.Append(anItem); - } - aAppendingMeter.Stop(); - - OSD_PerfMeter aAssignOperMeter("NCollection_List operator="); - a2 = a1; - aAssignOperMeter.Stop(); - - OSD_PerfMeter aAssignFnMeter("NCollection_List Assign"); - a2.Assign(a1); - aAssignFnMeter.Stop(); - - OSD_PerfMeter aClearingMeter("NCollection_List clearing"); - a2.Clear(); - aClearingMeter.Stop(); - } - - for (i = 0; i < theRep; i++) - { - QANCollection_ListOfPnt a1, a2; - - OSD_PerfMeter aAppendingMeter("TCollection_List appending"); - for (j = 1; j <= theSize; j++) - { - ItemType anItem; - Random(anItem); - a1.Append(anItem); - } - aAppendingMeter.Stop(); - - OSD_PerfMeter aAssignOperMeter("TCollection_List operator="); - a2 = a1; - aAssignOperMeter.Stop(); - - OSD_PerfMeter aClearMeter("TCollection_List clearing"); - a2.Clear(); - aClearMeter.Stop(); - } - printAllMeters(theDI); -} - -// ===================== Test perform of Sequence type ========================== -static void CompSequence(Draw_Interpretor& theDI, - const Standard_Integer theRep, - const Standard_Integer theSize) -{ - Standard_Integer i, j; - - for (i = 0; i < theRep; i++) - { - QANCollection_SequencePerf a1, a2; - - OSD_PerfMeter aAppendingMeter("NCollection_Sequence appending"); - for (j = 1; j <= theSize; j++) - { - ItemType anItem; - Random(anItem); - a1.Append(anItem); - } - aAppendingMeter.Stop(); - - OSD_PerfMeter aFindingMeter("NCollection_Sequence finding"); - for (j = 1; j <= theSize; j++) - { - Standard_Integer iIndex; - Random(iIndex, theSize); - a1.Value(iIndex + 1); - } - aFindingMeter.Stop(); - - OSD_PerfMeter aAssignOperMeter("NCollection_Sequence operator="); - a2 = a1; - aAssignOperMeter.Stop(); - - OSD_PerfMeter aAssignFnMeter("NCollection_Sequence Assign"); - a2.Assign(a1); - aAssignFnMeter.Stop(); - - OSD_PerfMeter aClearingMeter("NCollection_Sequence clearing"); - a2.Clear(); - aClearingMeter.Stop(); - } - - for (i = 0; i < theRep; i++) - { - TColgp_SequenceOfPnt a1, a2; - - OSD_PerfMeter aAppendingMeter("TCollection_Sequence appending"); - for (j = 1; j <= theSize; j++) - { - ItemType anItem; - Random(anItem); - a1.Append(anItem); - } - aAppendingMeter.Stop(); - - OSD_PerfMeter aFindingMeter("TCollection_Sequence finding"); - for (j = 1; j <= theSize; j++) - { - Standard_Integer iIndex; - Random(iIndex, theSize); - a1.Value(iIndex + 1); - } - aFindingMeter.Stop(); - - OSD_PerfMeter aAssignOperMeter("TCollection_Sequence operator="); - a2 = a1; - aAssignOperMeter.Stop(); - - OSD_PerfMeter aClearMeter("TCollection_Sequence clearing"); - a2.Clear(); - aClearMeter.Stop(); - } - printAllMeters(theDI); -} - -// ===================== Test perform of Map type ========================== -static void CompMap(Draw_Interpretor& theDI, - const Standard_Integer theRep, - const Standard_Integer theSize) -{ - Standard_Integer i, j; - - for (i = 0; i < theRep; i++) - { - QANCollection_MapPerf a1, a2; - - OSD_PerfMeter aAddingMeter("NCollection_Map adding"); - for (j = 1; j <= theSize; j++) - { - Key1Type aKey1; - Random(aKey1); - a1.Add(aKey1); - } - aAddingMeter.Stop(); - - OSD_PerfMeter aFindingMeter("NCollection_Map finding"); - for (j = 1; j <= theSize; j++) - { - Key1Type aKey1; - Random(aKey1); - a1.Contains(aKey1); - } - aFindingMeter.Stop(); - - OSD_PerfMeter aAssignOperMeter("NCollection_Map operator="); - a2 = a1; - aAssignOperMeter.Stop(); - - OSD_PerfMeter aAssignFnMeter("NCollection_Map Assign"); - a2.Assign(a1); - aAssignFnMeter.Stop(); - - OSD_PerfMeter aClearingMeter("NCollection_Map clearing"); - a2.Clear(); - aClearingMeter.Stop(); - } - - for (i = 0; i < theRep; i++) - { - TColStd_MapOfReal a1, a2; - - OSD_PerfMeter aAddingMeter("TCollection_Map adding"); - for (j = 1; j <= theSize; j++) - { - Key1Type aKey1; - Random(aKey1); - a1.Add(aKey1); - } - aAddingMeter.Stop(); - - OSD_PerfMeter aFindingMeter("TCollection_Map finding"); - for (j = 1; j <= theSize; j++) - { - Key1Type aKey1; - Random(aKey1); - a1.Contains(aKey1); - } - aFindingMeter.Stop(); - - OSD_PerfMeter aAssignOperMeter("TCollection_Map operator="); - a2 = a1; - aAssignOperMeter.Stop(); - - OSD_PerfMeter aClearMeter("TCollection_Map clearing"); - a2.Clear(); - aClearMeter.Stop(); - } - printAllMeters(theDI); -} - -// ===================== Test perform of DataMap type ========================== -static void CompDataMap(Draw_Interpretor& theDI, - const Standard_Integer theRep, - const Standard_Integer theSize) -{ - Standard_Integer i, j; - - for (i = 0; i < theRep; i++) - { - QANCollection_DataMapPerf a1, a2; - - OSD_PerfMeter aBindingMeter("NCollection_DataMap binding"); - for (j = 1; j <= theSize; j++) - { - Key1Type aKey1; - ItemType anItem; - Random(aKey1); - Random(anItem); - a1.Bind(aKey1, anItem); - } - aBindingMeter.Stop(); - - OSD_PerfMeter aFindingMeter("NCollection_DataMap finding"); - for (j = 1; j <= theSize; j++) - { - Key1Type aKey1; - Random(aKey1); - a1.IsBound(aKey1); - } - aFindingMeter.Stop(); - - OSD_PerfMeter aAssignOperMeter("NCollection_DataMap operator="); - a2 = a1; - aAssignOperMeter.Stop(); - - OSD_PerfMeter aClearMeter("NCollection_DataMap clearing"); - a2.Clear(); - aClearMeter.Stop(); - } - - for (i = 0; i < theRep; i++) - { - QANCollection_DataMapOfRealPnt a1, a2; - - OSD_PerfMeter aBindingMeter("TCollection_DataMap binding"); - for (j = 1; j <= theSize; j++) - { - Key1Type aKey1; - ItemType anItem; - Random(aKey1); - Random(anItem); - a1.Bind(aKey1, anItem); - } - aBindingMeter.Stop(); - - OSD_PerfMeter aFindingMeter("TCollection_DataMap finding"); - for (j = 1; j <= theSize; j++) - { - Key1Type aKey1; - Random(aKey1); - a1.IsBound(aKey1); - } - aFindingMeter.Stop(); - - OSD_PerfMeter aAssignOperMeter("TCollection_DataMap operator="); - a2 = a1; - aAssignOperMeter.Stop(); - - OSD_PerfMeter aClearMeter("TCollection_DataMap clearing"); - a2.Clear(); - aClearMeter.Stop(); - } - printAllMeters(theDI); -} - -// ===================== Test perform of DoubleMap type ========================== -static void CompDoubleMap(Draw_Interpretor& theDI, - const Standard_Integer theRep, - const Standard_Integer theSize) -{ - Standard_Integer i, j; - Standard_Integer iFail1 = 0, iFail2 = 0; - - for (i = 0; i < theRep; i++) - { - QANCollection_DoubleMapPerf a1, a2; - - OSD_PerfMeter aBindingMeter("NCollection_DoubleMap binding"); - for (j = 1; j <= theSize; j++) - { - Key1Type aKey1; - Key2Type aKey2; - do - { - Random(aKey1); - Random(aKey2); - iFail1++; - } while (a1.IsBound1(aKey1) || a1.IsBound2(aKey2)); - iFail1--; - a1.Bind(aKey1, aKey2); - } - aBindingMeter.Stop(); - - OSD_PerfMeter aFindingMeter("NCollection_DoubleMap finding"); - for (j = 1; j <= theSize; j++) - { - Key1Type aKey1; - Key2Type aKey2; - Random(aKey1); - Random(aKey2); - a1.AreBound(aKey1, aKey2); - } - aFindingMeter.Stop(); - - OSD_PerfMeter aAssignOperMeter("NCollection_DoubleMap operator="); - a2 = a1; - aAssignOperMeter.Stop(); - - OSD_PerfMeter aClearMeter("NCollection_DoubleMap clearing"); - a2.Clear(); - aClearMeter.Stop(); - } - - for (i = 0; i < theRep; i++) - { - QANCollection_DoubleMapOfRealInteger a1, a2; - - OSD_PerfMeter aBindingMeter("TCollection_DoubleMap binding"); - for (j = 1; j <= theSize; j++) - { - Key1Type aKey1; - Key2Type aKey2; - do - { - Random(aKey1); - Random(aKey2); - iFail2++; - } while (a1.IsBound1(aKey1) || a1.IsBound2(aKey2)); - iFail2--; - a1.Bind(aKey1, aKey2); - } - aBindingMeter.Stop(); - - OSD_PerfMeter aFindingMeter("TCollection_DoubleMap finding"); - for (j = 1; j <= theSize; j++) - { - Key1Type aKey1; - Key2Type aKey2; - Random(aKey1); - Random(aKey2); - a1.AreBound(aKey1, aKey2); - } - aFindingMeter.Stop(); - - OSD_PerfMeter aAssignOperMeter("TCollection_DoubleMap operator="); - a2 = a1; - aAssignOperMeter.Stop(); - - OSD_PerfMeter aClearMeter("TCollection_DoubleMap clearing"); - a2.Clear(); - aClearMeter.Stop(); - } - printAllMeters(theDI); - if (iFail1 || iFail2) - std::cout << "Warning : N map failed " << iFail1 << " times, T map - " << iFail2 << std::endl; -} - -// ===================== Test perform of IndexedMap type ========================== -static void CompIndexedMap(Draw_Interpretor& theDI, - const Standard_Integer theRep, - const Standard_Integer theSize) -{ - Standard_Integer i, j; - - for (i = 0; i < theRep; i++) - { - QANCollection_IndexedMapPerf a1, a2; - - OSD_PerfMeter aAddingMeter("NCollection_IndexedMap adding"); - for (j = 1; j <= theSize; j++) - { - Key1Type aKey1; - Random(aKey1); - a1.Add(aKey1); - } - aAddingMeter.Stop(); - - OSD_PerfMeter aFindingMeter("NCollection_IndexedMap finding"); - for (j = 1; j <= theSize; j++) - { - Key1Type aKey1; - Random(aKey1); - a1.Contains(aKey1); - } - aFindingMeter.Stop(); - - OSD_PerfMeter aAssignOperMeter("NCollection_IndexedMap operator="); - a2 = a1; - aAssignOperMeter.Stop(); - - OSD_PerfMeter aAssignFnMeter("NCollection_IndexedMap Assign"); - a2.Assign(a1); - aAssignFnMeter.Stop(); - - OSD_PerfMeter aClearingMeter("NCollection_IndexedMap clearing"); - a2.Clear(); - aClearingMeter.Stop(); - } - - for (i = 0; i < theRep; i++) - { - TColStd_IndexedMapOfReal a1, a2; - - OSD_PerfMeter aAddingMeter("TCollection_IndexedMap adding"); - for (j = 1; j <= theSize; j++) - { - Key1Type aKey1; - Random(aKey1); - a1.Add(aKey1); - } - aAddingMeter.Stop(); - - OSD_PerfMeter aFindingMeter("TCollection_IndexedMap finding"); - for (j = 1; j <= theSize; j++) - { - Key1Type aKey1; - Random(aKey1); - a1.Contains(aKey1); - } - aFindingMeter.Stop(); - - OSD_PerfMeter aAssignOperMeter("TCollection_IndexedMap operator="); - a2 = a1; - aAssignOperMeter.Stop(); - - OSD_PerfMeter aClearingMeter("TCollection_IndexedMap clearing"); - a2.Clear(); - aClearingMeter.Stop(); - } - printAllMeters(theDI); -} - -// ===================== Test perform of IndexedDataMap type ========================== -static void CompIndexedDataMap(Draw_Interpretor& theDI, - const Standard_Integer theRep, - const Standard_Integer theSize) -{ - Standard_Integer i, j; - - for (i = 0; i < theRep; i++) - { - - QANCollection_IDMapPerf a1, a2; - - OSD_PerfMeter aBindingMeter("NCollection_IndexedDataMap binding"); - for (j = 1; j <= theSize; j++) - { - Key1Type aKey1; - ItemType anItem; - Random(aKey1); - Random(anItem); - a1.Add(aKey1, anItem); - } - aBindingMeter.Stop(); - - OSD_PerfMeter aFindingMeter("NCollection_IndexedDataMap finding"); - for (j = 1; j <= theSize; j++) - { - Key1Type aKey1; - Random(aKey1); - a1.Contains(aKey1); - } - aFindingMeter.Stop(); - - OSD_PerfMeter aAssignOperMeter("NCollection_IndexedDataMap operator="); - a2 = a1; - aAssignOperMeter.Stop(); - - OSD_PerfMeter aClearingMeter("NCollection_IndexedDataMap clearing"); - a2.Clear(); - aClearingMeter.Stop(); - } - - for (i = 0; i < theRep; i++) - { - QANCollection_IndexedDataMapOfRealPnt a1, a2; - - OSD_PerfMeter aBindingMeter("TCollection_IndexedDataMap binding"); - for (j = 1; j <= theSize; j++) - { - Key1Type aKey1; - ItemType anItem; - Random(aKey1); - Random(anItem); - a1.Add(aKey1, anItem); - } - aBindingMeter.Stop(); - - OSD_PerfMeter aFindingMeter("TCollection_IndexedDataMap finding"); - for (j = 1; j <= theSize; j++) - { - Key1Type aKey1; - Random(aKey1); - a1.Contains(aKey1); - } - aFindingMeter.Stop(); - - OSD_PerfMeter aAssignOperMeter("TCollection_IndexedDataMap operator="); - a2 = a1; - aAssignOperMeter.Stop(); - - OSD_PerfMeter aClearingMeter("TCollection_IndexedDataMap clearing"); - a2.Clear(); - aClearingMeter.Stop(); - } - printAllMeters(theDI); -} - -// ===================== Test perform of SparseArray type ========================== -static void CompSparseArray(Draw_Interpretor& theDI, - const Standard_Integer theRep, - const Standard_Integer theSize) -{ - Standard_Integer i, j; - for (i = 0; i < theRep; i++) - { - OSD_PerfMeter aCreationMeter("NCollection_SparseArray creation"); - NCollection_SparseArray a1(theSize), a2(theSize); - aCreationMeter.Stop(); - - OSD_PerfMeter aFillingMeter("NCollection_SparseArray filling"); - for (j = 0; j < theSize; j++) - { - Standard_Integer iIndex; - Random(iIndex, theSize); - a1.SetValue(j, iIndex + 1); - } - aFillingMeter.Stop(); - - OSD_PerfMeter aSizeMeter("NCollection_SparseArray size"); - Standard_Size sizeSparseArray = a1.Size(); - (void)sizeSparseArray; // avoid compiler warning on unused variable - aSizeMeter.Stop(); - - OSD_PerfMeter aAssignFnMeter("NCollection_SparseArray Assign"); - a2.Assign(a1); - aAssignFnMeter.Stop(); - - OSD_PerfMeter aHasValueMeter("NCollection_SparseArray HasValue"); - for (j = 0; j < theSize; j++) - { - Standard_Integer iIndex; - Random(iIndex, theSize); - a2.HasValue(iIndex + 1); - } - aHasValueMeter.Stop(); - - OSD_PerfMeter aUnsetValueMeter("NCollection_SparseArray UnsetValue"); - for (j = 0; j < theSize; j++) - { - Standard_Integer iIndex; - Random(iIndex, theSize); - a1.UnsetValue(iIndex + 1); - } - aUnsetValueMeter.Stop(); - - OSD_PerfMeter aClearMeter("NCollection_SparseArray Clear"); - a1.Clear(); - a2.Clear(); - aClearMeter.Stop(); - } - - printAllMeters(theDI); -} - -//================================================================================================= - -Standard_Integer CheckArguments(Draw_Interpretor& di, - Standard_Integer argc, - const char** argv, - Standard_Integer& Repeat, - Standard_Integer& Size) -{ - if (argc != 3) - { - di << "Usage : " << argv[0] << " Repeat Size\n"; - return 1; - } - Repeat = Draw::Atoi(argv[1]); - Size = Draw::Atoi(argv[2]); - if (Repeat < 1) - { - di << "Repeat > 0\n"; - return 1; - } - if (Size < 1) - { - di << "Size > 0\n"; - return 1; - } - return 0; -} - -//================================================================================================= - -static Standard_Integer QANColPerfArray1(Draw_Interpretor& di, - Standard_Integer argc, - const char** argv) -{ - Standard_Integer Repeat, Size; - if (CheckArguments(di, argc, argv, Repeat, Size)) - { - return 1; - } - CompArray1(di, Repeat, Size); - return 0; -} - -//================================================================================================= - -static Standard_Integer QANColPerfArray2(Draw_Interpretor& di, - Standard_Integer argc, - const char** argv) -{ - Standard_Integer Repeat, Size; - if (CheckArguments(di, argc, argv, Repeat, Size)) - { - return 1; - } - CompArray2(di, Repeat, Size); - return 0; -} - -//================================================================================================= - -static Standard_Integer QANColPerfList(Draw_Interpretor& di, - Standard_Integer argc, - const char** argv) -{ - Standard_Integer Repeat, Size; - if (CheckArguments(di, argc, argv, Repeat, Size)) - { - return 1; - } - CompList(di, Repeat, Size); - return 0; -} - -//================================================================================================= - -static Standard_Integer QANColPerfSequence(Draw_Interpretor& di, - Standard_Integer argc, - const char** argv) -{ - Standard_Integer Repeat, Size; - if (CheckArguments(di, argc, argv, Repeat, Size)) - { - return 1; - } - CompSequence(di, Repeat, Size); - return 0; -} - -//================================================================================================= - -static Standard_Integer QANColPerfMap(Draw_Interpretor& di, - Standard_Integer argc, - const char** argv) -{ - Standard_Integer Repeat, Size; - if (CheckArguments(di, argc, argv, Repeat, Size)) - { - return 1; - } - CompMap(di, Repeat, Size); - return 0; -} - -//================================================================================================= - -static Standard_Integer QANColPerfDataMap(Draw_Interpretor& di, - Standard_Integer argc, - const char** argv) -{ - Standard_Integer Repeat, Size; - if (CheckArguments(di, argc, argv, Repeat, Size)) - { - return 1; - } - CompDataMap(di, Repeat, Size); - return 0; -} - -//================================================================================================= - -static Standard_Integer QANColPerfDoubleMap(Draw_Interpretor& di, - Standard_Integer argc, - const char** argv) -{ - Standard_Integer Repeat, Size; - if (CheckArguments(di, argc, argv, Repeat, Size)) - { - return 1; - } - CompDoubleMap(di, Repeat, Size); - return 0; -} - -//================================================================================================= - -static Standard_Integer QANColPerfIndexedMap(Draw_Interpretor& di, - Standard_Integer argc, - const char** argv) -{ - Standard_Integer Repeat, Size; - if (CheckArguments(di, argc, argv, Repeat, Size)) - { - return 1; - } - CompIndexedMap(di, Repeat, Size); - return 0; -} - -//================================================================================================= - -static Standard_Integer QANColPerfIndexedDataMap(Draw_Interpretor& di, - Standard_Integer argc, - const char** argv) -{ - Standard_Integer Repeat, Size; - if (CheckArguments(di, argc, argv, Repeat, Size)) - { - return 1; - } - CompIndexedDataMap(di, Repeat, Size); - return 0; -} - -//================================================================================================= - -static Standard_Integer QANColCheckSparseArray(Draw_Interpretor& di, - Standard_Integer argc, - const char** argv) -{ - Standard_Integer Repeat, Size; - if (CheckArguments(di, argc, argv, Repeat, Size)) - { - return 1; - } - CompSparseArray(di, Repeat, Size); - return 0; -} - -void QANCollection::CommandsPerf(Draw_Interpretor& theCommands) -{ - const char* group = "QANCollection"; - - // from agvCollTest/src/CollectionEXE/PerfTestEXE.cxx - theCommands.Add("QANColPerfArray1", - "QANColPerfArray1 Repeat Size", - __FILE__, - QANColPerfArray1, - group); - theCommands.Add("QANColPerfArray2", - "QANColPerfArray2 Repeat Size", - __FILE__, - QANColPerfArray2, - group); - theCommands.Add("QANColPerfList", "QANColPerfList Repeat Size", __FILE__, QANColPerfList, group); - theCommands.Add("QANColPerfSequence", - "QANColPerfSequence Repeat Size", - __FILE__, - QANColPerfSequence, - group); - theCommands.Add("QANColPerfMap", "QANColPerfMap Repeat Size", __FILE__, QANColPerfMap, group); - theCommands.Add("QANColPerfDataMap", - "QANColPerfDataMap Repeat Size", - __FILE__, - QANColPerfDataMap, - group); - theCommands.Add("QANColPerfDoubleMap", - "QANColPerfDoubleMap Repeat Size", - __FILE__, - QANColPerfDoubleMap, - group); - theCommands.Add("QANColPerfIndexedMap", - "QANColPerfIndexedMap Repeat Size", - __FILE__, - QANColPerfIndexedMap, - group); - theCommands.Add("QANColPerfIndexedDataMap", - "QANColPerfIndexedDataMap Repeat Size", - __FILE__, - QANColPerfIndexedDataMap, - group); - - theCommands.Add("QANColCheckSparseArray", - "QANColCheckSparseArray Repeat Size", - __FILE__, - QANColCheckSparseArray, - group); - - return; -} diff --git a/src/Draw/TKQADraw/QANCollection/QANCollection_Stl.cxx b/src/Draw/TKQADraw/QANCollection/QANCollection_Stl.cxx deleted file mode 100644 index 5bb35a77f7..0000000000 --- a/src/Draw/TKQADraw/QANCollection/QANCollection_Stl.cxx +++ /dev/null @@ -1,1438 +0,0 @@ -// Created on: 2014-04-16 -// Created by: Denis BOGOLEPOV -// Copyright (c) 2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#if defined(_MSC_VER) && !defined(_SCL_SECURE_NO_WARNINGS) - // suppress "std::Equal1" warning suggesting using msvc "Checked Iterators" - #define _SCL_SECURE_NO_WARNINGS -#endif - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -//! Size of test data sets. -const int THE_TEST_SIZE = 5000; - -template -struct CollectionFiller -{ - static void Perform(CollectionType** theCollec, Standard_Integer theSize = THE_TEST_SIZE) - { - *theCollec = new CollectionType(); - srand(1); - for (Standard_Integer anIdx = 0; anIdx < theSize; ++anIdx) - { - (*theCollec)->Append(rand()); - } - } - - static void Perform(StlType** theVector, - CollectionType** theCollec, - Standard_Integer theSize = THE_TEST_SIZE) - { - CollectionFiller::Perform(theCollec, theSize); - - *theVector = new StlType((*theCollec)->begin(), (*theCollec)->end()); - } -}; - -template -struct CollectionFiller, StlType> -{ - static void Perform(NCollection_Array1** theCollec, Standard_Integer theSize = THE_TEST_SIZE) - { - *theCollec = new NCollection_Array1(0, theSize - 1); - srand(1); - for (Standard_Integer anIdx = 0; anIdx < theSize; ++anIdx) - { - (*theCollec)->ChangeValue(anIdx) = rand(); - } - } - - static void Perform(StlType** theVector, - NCollection_Array1** theCollec, - Standard_Integer theSize = THE_TEST_SIZE) - { - CollectionFiller, StlType>::Perform(theCollec, theSize); - - *theVector = new StlType((*theCollec)->begin(), (*theCollec)->end()); - } -}; - -template -struct MapFiller -{ - static void Perform(CollectionType** theCollec, Standard_Integer theSize = THE_TEST_SIZE) - { - *theCollec = new CollectionType(); - srand(1); - for (Standard_Integer anIdx = 0; anIdx < theSize; ++anIdx) - { - (*theCollec)->Add(rand()); - } - } -}; - -template -struct MapFiller, T> -{ - static void Perform(NCollection_DataMap** theCollec1, - NCollection_DataMap** theCollec2 = NULL, - Standard_Integer theSize = THE_TEST_SIZE) - { - *theCollec1 = new NCollection_DataMap(); - - if (theCollec2 != NULL) - *theCollec2 = new NCollection_DataMap(); - srand(1); - for (Standard_Integer anIdx = 0; anIdx < theSize; ++anIdx) - { - const T aVal1 = rand(); - const T aVal2 = rand(); - - (*theCollec1)->Bind(aVal1, aVal2); - - if (theCollec2 != NULL) - (*theCollec2)->Bind(aVal1, aVal2); - } - } -}; - -template -struct MapFiller, T> -{ - static void Perform(NCollection_IndexedDataMap** theCollec1, - NCollection_IndexedDataMap** theCollec2 = NULL, - Standard_Integer theSize = THE_TEST_SIZE) - { - *theCollec1 = new NCollection_IndexedDataMap(); - - if (theCollec2 != NULL) - *theCollec2 = new NCollection_IndexedDataMap(); - srand(1); - for (Standard_Integer anIdx = 0; anIdx < theSize; ++anIdx) - { - const T aVal1 = rand(); - const T aVal2 = rand(); - - (*theCollec1)->Add(aVal1, aVal2); - - if (theCollec2 != NULL) - (*theCollec2)->Add(aVal1, aVal2); - } - } -}; - -//================================================================================================= - -template -Standard_Boolean TestIteration() -{ - StlType* aVector(NULL); - CollectionType* aCollec(NULL); - - CollectionFiller::Perform(&aVector, &aCollec); - - typename StlType::iterator aVecIter = aVector->begin(); - typename CollectionType::iterator aColIter = aCollec->begin(); - - Standard_Boolean aResult(Standard_True); - - for (; aVecIter != aVector->end(); ++aVecIter, ++aColIter) - { - if (*aVecIter != *aColIter) - aResult = Standard_False; - } - - if (aColIter != aCollec->end()) - { - aResult = Standard_False; - } - - delete aVector; - delete aCollec; - - return aResult; -} - -//================================================================================================= - -template -Standard_Boolean TestMinMax() -{ - StlType* aVector(NULL); - CollectionType* aCollec(NULL); - - CollectionFiller::Perform(&aVector, &aCollec); - - typename StlType::value_type aValue1 = *std::min_element(aVector->begin(), aVector->end()); - typename CollectionType::value_type aValue2 = *std::min_element(aCollec->begin(), aCollec->end()); - - Standard_Boolean aResult(Standard_True); - - if (aValue1 != aValue2) - aResult = Standard_False; - - aValue1 = *std::max_element(aVector->begin(), aVector->end()); - aValue2 = *std::max_element(aCollec->begin(), aCollec->end()); - - if (aValue1 != aValue2) - aResult = Standard_False; - - delete aVector; - delete aCollec; - - return aResult; -} - -//================================================================================================= - -template -Standard_Boolean TestReplace() -{ - StlType* aVector(NULL); - CollectionType* aCollec(NULL); - - CollectionFiller::Perform(&aVector, &aCollec); - - const typename StlType::value_type aValue = aVector->back(); - - std::replace(aVector->begin(), - aVector->end(), - aValue, - static_cast(-1)); - std::replace(aCollec->begin(), - aCollec->end(), - aValue, - static_cast(-1)); - - typename StlType::iterator aVecIter = aVector->begin(); - typename CollectionType::iterator aColIter = aCollec->begin(); - - Standard_Boolean aResult(Standard_True); - - for (; aVecIter != aVector->end(); ++aVecIter, ++aColIter) - { - if (*aVecIter != *aColIter) - aResult = Standard_False; - } - - if (aColIter != aCollec->end()) - { - aResult = Standard_False; - } - - delete aVector; - delete aCollec; - - return aResult; -} - -//================================================================================================= - -template -Standard_Boolean TestReverse() -{ - StlType* aVector(NULL); - CollectionType* aCollec(NULL); - - CollectionFiller::Perform(&aVector, &aCollec); - - std::reverse(aVector->begin(), aVector->end()); - std::reverse(aCollec->begin(), aCollec->end()); - - typename StlType::iterator aVecIter = aVector->begin(); - typename CollectionType::iterator aColIter = aCollec->begin(); - - Standard_Boolean aResult(Standard_True); - - for (; aVecIter != aVector->end(); ++aVecIter, ++aColIter) - { - if (*aVecIter != *aColIter) - aResult = Standard_False; - } - - if (aColIter != aCollec->end()) - { - aResult = Standard_False; - } - - delete aVector; - delete aCollec; - - return aResult; -} - -//================================================================================================= - -template -Standard_Boolean TestSort() -{ - StlType* aVector(NULL); - CollectionType* aCollec(NULL); - - CollectionFiller::Perform(&aVector, &aCollec); - - std::sort(aVector->begin(), aVector->end()); - std::sort(aCollec->begin(), aCollec->end()); - - typename StlType::iterator aVecIter = aVector->begin(); - typename CollectionType::iterator aColIter = aCollec->begin(); - - Standard_Boolean aResult(Standard_True); - - for (; aVecIter != aVector->end(); ++aVecIter, ++aColIter) - { - if (*aVecIter != *aColIter) - aResult = Standard_False; - } - - if (aColIter != aCollec->end()) - { - aResult = Standard_False; - } - - delete aVector; - delete aCollec; - - return aResult; -} - -template -struct Invoker -{ - void operator()(T& theValue) const { theValue *= 2; } -}; - -//================================================================================================= - -template -Standard_Boolean TestParallel() -{ - StlType* aVector(NULL); - CollectionType* aCollec(NULL); - - CollectionFiller::Perform(&aVector, &aCollec); - - OSD_Parallel::ForEach(aVector->begin(), aVector->end(), Invoker()); - OSD_Parallel::ForEach(aCollec->begin(), - aCollec->end(), - Invoker()); - - typename StlType::iterator aVecIter = aVector->begin(); - typename CollectionType::iterator aColIter = aCollec->begin(); - - Standard_Boolean aResult(Standard_True); - - for (; aVecIter != aVector->end(); ++aVecIter, ++aColIter) - { - if (*aVecIter != *aColIter) - aResult = Standard_False; - } - - if (aColIter != aCollec->end()) - { - aResult = Standard_False; - } - - delete aVector; - delete aCollec; - - return aResult; -} - -//================================================================================================= - -template -Standard_Boolean TestDataMapParallel() -{ - CollectionType* aCollec1(NULL); - CollectionType* aCollec2(NULL); - - MapFiller::Perform(&aCollec1, &aCollec2); - - OSD_Parallel::ForEach(aCollec1->begin(), aCollec1->end(), Invoker()); - - // create OCCT-style iterator - typename CollectionType::Iterator aOccIter(*aCollec2); - - // create STL-compatible iterator - typename CollectionType::const_iterator aStlIter = aCollec1->cbegin(); - - Standard_Boolean aResult(Standard_True); - - for (; aStlIter != aCollec1->cend(); ++aStlIter, aOccIter.Next()) - { - if (static_cast(2) * aOccIter.Value() != *aStlIter) - aResult = Standard_False; - } - - if (aOccIter.More()) - { - aResult = Standard_False; - } - - delete aCollec1; - delete aCollec2; - - return aResult; -} - -//================================================================================================= - -template -Standard_Boolean TestMapIteration() -{ - CollectionType* aCollec(NULL); - - MapFiller::Perform(&aCollec); - - // create OCCT-style iterator - typename CollectionType::Iterator aOccIter(*aCollec); - - // create STL-compatible iterator - typename CollectionType::const_iterator aStlIter = aCollec->cbegin(); - - Standard_Boolean aResult(Standard_True); - - for (; aStlIter != aCollec->cend(); ++aStlIter, aOccIter.Next()) - { - if (aOccIter.Value() != *aStlIter) - aResult = Standard_False; - } - - if (aOccIter.More()) - { - aResult = Standard_False; - } - - delete aCollec; - - return aResult; -} - -//======================================================================= -// function : TestForwardIterator -// purpose : test basic features of iterator (forward) -//======================================================================= -template -void TestForwardIterator() -{ - CollectionType* aCollec(NULL); - - CollectionFiller::Perform(&aCollec); - - // test non-const iteration - typename CollectionType::iterator it = aCollec->begin(); // copy construction - typename CollectionType::iterator it2; // default constructor - it2 = it; // assignment - it2 = it++; // postfix increment - if (it2 == it || !(it2 != it)) - std::cout << "Failed " << typeid(it).name() << " equality check" << std::endl; - it2 = ++it; // prefix increment - if (it2 != it || !(it2 == it)) - std::cout << "Failed " << typeid(it).name() << " equality check" << std::endl; - - typename CollectionType::iterator::value_type t = *it; - *it2 = t; - *(it2.operator->()) = t; - - // test const iteration - typename CollectionType::const_iterator cit = aCollec->cbegin(); // copy construction - typename CollectionType::const_iterator cit2; // default constructor - cit2 = cit; // assignment - cit2 = cit++; // postfix increment - if (cit2 == cit || !(cit2 != cit)) - std::cout << "Failed " << typeid(cit).name() << " equality check" << std::endl; - cit2 = ++cit; // prefix increment - if (cit2 != it || !(cit2 == cit)) - std::cout << "Failed " << typeid(cit).name() << " equality check" << std::endl; - - typename CollectionType::const_iterator::value_type ct = *cit; - ct = *cit; - (void)ct; - // *cit2 = ct; - // *(cit2.operator-> ()) = t; - - delete aCollec; -} - -//======================================================================= -// function : TestBidirIterator -// purpose : test features of bidirectional iterator -//======================================================================= -template -void TestBidirIterator() -{ - CollectionType* aCollec(NULL); - - CollectionFiller::Perform(&aCollec); - - // test non-const iteration - typename CollectionType::iterator it = aCollec->end(); // copy construction - typename CollectionType::iterator it2 = it--; // postfix decrement - if (it2 == it || !(it2 != it)) - std::cout << "Failed " << typeid(it).name() << " equality check" << std::endl; - it2 = --it; // prefix decrement - if (it2 != it || !(it2 == it)) - std::cout << "Failed " << typeid(it).name() << " equality check" << std::endl; - - delete aCollec; -} - -//======================================================================= -// function : TestRandomIterator -// purpose : test features of random iterator -//======================================================================= -template -void TestRandomIterator() -{ - CollectionType* aCollec(NULL); - - CollectionFiller::Perform(&aCollec); - - // test non-const iteration - typename CollectionType::iterator it = aCollec->begin(); // copy construction - typename CollectionType::iterator it2 = it + 5; - if ((it2 - it) != 5) - std::cout << "Failed " << typeid(it).name() << " arithmetics" << std::endl; - if (it2 < it || it2 <= it || !(it2 > it) || !(it2 >= it)) - std::cout << "Failed " << typeid(it).name() << " comparison" << std::endl; - it += 5; - if (it2 != it) - std::cout << "Failed " << typeid(it).name() << " arithmetics" << std::endl; - it2 = it - 5; - if ((it2 - it) != -5) - std::cout << "Failed " << typeid(it).name() << " arithmetics" << std::endl; - if (it2 > it || it2 >= it || !(it2 < it) || !(it2 <= it)) - std::cout << "Failed " << typeid(it).name() << " comparison" << std::endl; - it -= 5; - if (it2 != it) - std::cout << "Failed " << typeid(it).name() << " arithmetics" << std::endl; - - typename CollectionType::value_type t = it[5]; // offset dereference - *it = t; - - delete aCollec; -} - -//================================================================================================= - -static Standard_Integer QANListStlIterator(Draw_Interpretor&, Standard_Integer, const char**) -{ - // compile-time tests - TestForwardIterator>(); - - // run-time tests - Standard_Boolean aResult = TestIteration, std::list>(); - std::cout << "NCollection_List Iteration: " << (aResult ? "SUCCESS" : "FAIL") - << std::endl; - - aResult = TestIteration, std::list>(); - std::cout << "NCollection_List Iteration: " << (aResult ? "SUCCESS" : "FAIL") - << std::endl; - - aResult = TestMinMax, std::list>(); - std::cout << "NCollection_List Min-Max: " << (aResult ? "SUCCESS" : "FAIL") - << std::endl; - - aResult = TestMinMax, std::list>(); - std::cout << "NCollection_List Min-Max: " << (aResult ? "SUCCESS" : "FAIL") - << std::endl; - - aResult = TestReplace, std::list>(); - std::cout << "NCollection_List Replace: " << (aResult ? "SUCCESS" : "FAIL") - << std::endl; - - aResult = TestReplace, std::list>(); - std::cout << "NCollection_List Replace: " << (aResult ? "SUCCESS" : "FAIL") - << std::endl; - - aResult = TestParallel, std::list>(); - std::cout << "NCollection_List Parallel: " << (aResult ? "SUCCESS" : "FAIL") - << std::endl; - - aResult = TestParallel, std::list>(); - std::cout << "NCollection_List Parallel: " << (aResult ? "SUCCESS" : "FAIL") - << std::endl; - - return 0; -} - -//================================================================================================= - -static Standard_Integer QANMapStlIterator(Draw_Interpretor&, Standard_Integer, const char**) -{ - // compile-time tests - // TestForwardIterator >(); - - // run-time tests - Standard_Boolean aResult = - TestMapIteration, Standard_Integer>(); - std::cout << "NCollection_Map Iteration: " << (aResult ? "SUCCESS" : "FAIL") - << std::endl; - - aResult = TestMapIteration, Standard_Real>(); - std::cout << "NCollection_Map Iteration: " << (aResult ? "SUCCESS" : "FAIL") - << std::endl; - - return 0; -} - -//================================================================================================= - -static Standard_Integer QANIndexedMapStlIterator(Draw_Interpretor&, Standard_Integer, const char**) -{ - // compile-time tests - // TestForwardIterator >(); - // TestBidirIterator >(); - - // run-time tests - Standard_Boolean aResult = - TestMapIteration, Standard_Integer>(); - std::cout << "NCollection_IndexedMap Iteration: " << (aResult ? "SUCCESS" : "FAIL") - << std::endl; - - aResult = TestMapIteration, Standard_Real>(); - std::cout << "NCollection_IndexedMap Iteration: " << (aResult ? "SUCCESS" : "FAIL") - << std::endl; - - return 0; -} - -//================================================================================================= - -static Standard_Integer QANDataMapStlIterator(Draw_Interpretor&, Standard_Integer, const char**) -{ - // compile-time tests - // TestForwardIterator >(); - // TestBidirIterator >(); - - // run-time tests - Standard_Boolean aResult = - TestMapIteration, Standard_Integer>(); - std::cout << "NCollection_DataMap Iteration: " << (aResult ? "SUCCESS" : "FAIL") - << std::endl; - - aResult = TestMapIteration, Standard_Real>(); - std::cout << "NCollection_DataMap Iteration: " << (aResult ? "SUCCESS" : "FAIL") - << std::endl; - - aResult = TestDataMapParallel, - Standard_Integer>(); - std::cout << "NCollection_DataMap Parallel: " << (aResult ? "SUCCESS" : "FAIL") - << std::endl; - - aResult = TestDataMapParallel, Standard_Real>(); - std::cout << "NCollection_DataMap Parallel: " << (aResult ? "SUCCESS" : "FAIL") - << std::endl; - - return 0; -} - -//================================================================================================= - -static Standard_Integer QANIndexedDataMapStlIterator(Draw_Interpretor&, - Standard_Integer, - const char**) -{ - // compile-time tests - // TestForwardIterator >(); - // TestBidirIterator >(); - - // run-time tests - Standard_Boolean aResult = - TestMapIteration, - Standard_Integer>(); - std::cout << "NCollection_IndexedDataMap Iteration: " << (aResult ? "SUCCESS" : "FAIL") - << std::endl; - - aResult = - TestMapIteration, Standard_Real>(); - std::cout << "NCollection_IndexedDataMap Iteration: " << (aResult ? "SUCCESS" : "FAIL") - << std::endl; - - aResult = TestDataMapParallel, - Standard_Integer>(); - std::cout << "NCollection_IndexedDataMap Parallel: " << (aResult ? "SUCCESS" : "FAIL") - << std::endl; - - aResult = - TestDataMapParallel, Standard_Real>(); - std::cout << "NCollection_IndexedDataMap Parallel: " << (aResult ? "SUCCESS" : "FAIL") - << std::endl; - - return 0; -} - -//================================================================================================= - -static Standard_Integer QANSequenceStlIterator(Draw_Interpretor&, Standard_Integer, const char**) -{ - // compile-time tests - TestForwardIterator>(); - TestBidirIterator>(); - - // run-time tests - Standard_Boolean aResult = TestIteration, std::list>(); - std::cout << "NCollection_Sequence Iteration: " << (aResult ? "SUCCESS" : "FAIL") - << std::endl; - - aResult = TestIteration, std::list>(); - std::cout << "NCollection_Sequence Iteration: " << (aResult ? "SUCCESS" : "FAIL") - << std::endl; - - aResult = TestMinMax, std::list>(); - std::cout << "NCollection_Sequence Min-Max: " << (aResult ? "SUCCESS" : "FAIL") - << std::endl; - - aResult = TestMinMax, std::list>(); - std::cout << "NCollection_Sequence Min-Max: " << (aResult ? "SUCCESS" : "FAIL") - << std::endl; - - aResult = TestReplace, std::list>(); - std::cout << "NCollection_Sequence Replace: " << (aResult ? "SUCCESS" : "FAIL") - << std::endl; - - aResult = TestReplace, std::list>(); - std::cout << "NCollection_Sequence Replace: " << (aResult ? "SUCCESS" : "FAIL") - << std::endl; - - aResult = TestReverse, std::list>(); - std::cout << "NCollection_Sequence Reverse: " << (aResult ? "SUCCESS" : "FAIL") - << std::endl; - - aResult = TestReverse, std::list>(); - std::cout << "NCollection_Sequence Reverse: " << (aResult ? "SUCCESS" : "FAIL") - << std::endl; - - aResult = TestParallel, std::list>(); - std::cout << "NCollection_Sequence Parallel: " << (aResult ? "SUCCESS" : "FAIL") - << std::endl; - - aResult = TestParallel, std::list>(); - std::cout << "NCollection_Sequence Parallel: " << (aResult ? "SUCCESS" : "FAIL") - << std::endl; - - return 0; -} - -//================================================================================================= - -static Standard_Integer QANVectorStlIterator(Draw_Interpretor&, Standard_Integer, const char**) -{ - // compile-time tests - TestForwardIterator>(); - TestBidirIterator>(); - TestRandomIterator>(); - - // run-time tests - Standard_Boolean aResult = TestIteration, std::vector>(); - std::cout << "NCollection_Vector Iteration: " << (aResult ? "SUCCESS" : "FAIL") - << std::endl; - - aResult = TestIteration, std::vector>(); - std::cout << "NCollection_Vector Iteration: " << (aResult ? "SUCCESS" : "FAIL") - << std::endl; - - aResult = TestMinMax, std::vector>(); - std::cout << "NCollection_Vector Min-Max: " << (aResult ? "SUCCESS" : "FAIL") - << std::endl; - - aResult = TestMinMax, std::vector>(); - std::cout << "NCollection_Vector Min-Max: " << (aResult ? "SUCCESS" : "FAIL") - << std::endl; - - aResult = TestReplace, std::vector>(); - std::cout << "NCollection_Vector Replace: " << (aResult ? "SUCCESS" : "FAIL") - << std::endl; - - aResult = TestReplace, std::vector>(); - std::cout << "NCollection_Vector Replace: " << (aResult ? "SUCCESS" : "FAIL") - << std::endl; - - aResult = TestReverse, std::vector>(); - std::cout << "NCollection_Vector Reverse: " << (aResult ? "SUCCESS" : "FAIL") - << std::endl; - - aResult = TestReverse, std::vector>(); - std::cout << "NCollection_Vector Reverse: " << (aResult ? "SUCCESS" : "FAIL") - << std::endl; - - aResult = TestSort, std::vector>(); - std::cout << "NCollection_Vector Sort: " << (aResult ? "SUCCESS" : "FAIL") - << std::endl; - - aResult = TestSort, std::vector>(); - std::cout << "NCollection_Vector Sort: " << (aResult ? "SUCCESS" : "FAIL") - << std::endl; - - aResult = TestParallel, std::vector>(); - std::cout << "NCollection_Vector Parallel: " << (aResult ? "SUCCESS" : "FAIL") - << std::endl; - - aResult = TestParallel, std::vector>(); - std::cout << "NCollection_Vector Parallel: " << (aResult ? "SUCCESS" : "FAIL") - << std::endl; - - { - // Test case for a corner case described in a bug #0027941 - // when vector length matches the increment. - // In this case NCollection_Vector::Iterator::Offset() produced mathematically equal - // but not the same iterator as returned by NCollection_Vector::end() - // so that their comparison was not equal. - // As result, std::stable_sort() crashed due to out-of-range access. - const int THE_INCREMENT = 256; - NCollection_Vector aVector(THE_INCREMENT); - for (int anIter = 0; anIter < THE_INCREMENT; ++anIter) - { - aVector.Append(THE_INCREMENT - anIter); - } - - NCollection_Vector::iterator aBegin = aVector.begin(); - NCollection_Vector::iterator anEnd = aVector.end(); - NCollection_Vector::iterator aShift = aBegin + THE_INCREMENT; - aResult = (aShift == anEnd); - std::cout << "NCollection_Vector Offset: " - << (aResult ? "SUCCESS" : "FAIL") << std::endl; - - std::stable_sort(aVector.begin(), aVector.end()); - } - - return 0; -} - -//================================================================================================= - -static Standard_Integer QANArray1StlIterator(Draw_Interpretor&, Standard_Integer, const char**) -{ - // compile-time tests - TestForwardIterator>(); - TestBidirIterator>(); - TestRandomIterator>(); - - // run-time tests - Standard_Boolean aResult = TestIteration, std::vector>(); - std::cout << "NCollection_Array1 Iteration: " << (aResult ? "SUCCESS" : "FAIL") - << std::endl; - - aResult = TestIteration, std::vector>(); - std::cout << "NCollection_Array1 Iteration: " << (aResult ? "SUCCESS" : "FAIL") - << std::endl; - - aResult = TestMinMax, std::vector>(); - std::cout << "NCollection_Array1 Min-Max: " << (aResult ? "SUCCESS" : "FAIL") - << std::endl; - - aResult = TestMinMax, std::vector>(); - std::cout << "NCollection_Array1 Min-Max: " << (aResult ? "SUCCESS" : "FAIL") - << std::endl; - - aResult = TestReplace, std::vector>(); - std::cout << "NCollection_Array1 Replace: " << (aResult ? "SUCCESS" : "FAIL") - << std::endl; - - aResult = TestReplace, std::vector>(); - std::cout << "NCollection_Array1 Replace: " << (aResult ? "SUCCESS" : "FAIL") - << std::endl; - - aResult = TestReverse, std::vector>(); - std::cout << "NCollection_Array1 Reverse: " << (aResult ? "SUCCESS" : "FAIL") - << std::endl; - - aResult = TestReverse, std::vector>(); - std::cout << "NCollection_Array1 Reverse: " << (aResult ? "SUCCESS" : "FAIL") - << std::endl; - - aResult = TestSort, std::vector>(); - std::cout << "NCollection_Array1 Sort: " << (aResult ? "SUCCESS" : "FAIL") - << std::endl; - - aResult = TestSort, std::vector>(); - std::cout << "NCollection_Array1 Sort: " << (aResult ? "SUCCESS" : "FAIL") - << std::endl; - - aResult = TestParallel, std::vector>(); - std::cout << "NCollection_Array1 Parallel: " << (aResult ? "SUCCESS" : "FAIL") - << std::endl; - - aResult = TestParallel, std::vector>(); - std::cout << "NCollection_Array1 Parallel: " << (aResult ? "SUCCESS" : "FAIL") - << std::endl; - - return 0; -} - -//================================================================================================= - -static Standard_Integer QANTestStlIterators(Draw_Interpretor& theInterpretor, - Standard_Integer, - const char**) -{ - QANListStlIterator(theInterpretor, 0, NULL); - QANArray1StlIterator(theInterpretor, 0, NULL); - QANVectorStlIterator(theInterpretor, 0, NULL); - QANSequenceStlIterator(theInterpretor, 0, NULL); - QANMapStlIterator(theInterpretor, 0, NULL); - QANDataMapStlIterator(theInterpretor, 0, NULL); - QANIndexedMapStlIterator(theInterpretor, 0, NULL); - QANIndexedDataMapStlIterator(theInterpretor, 0, NULL); - - return 0; -} - -//================================================================================================= - -template -void TestPerformanceRandomIterator(Draw_Interpretor& di) -{ - OSD_Timer aTimer; - - StlType* aVector(NULL); - CollectionType* aCollec(NULL); - - for (Standard_Integer aSize = 10000; aSize <= 1280000; aSize *= 2) - { - CollectionFiller::Perform(&aVector, &aCollec, aSize); - - aTimer.Reset(); - aTimer.Start(); - { - std::random_device ran_dev; - std::mt19937 gen(ran_dev()); - gen.seed(0x03ac38f2); - for (Standard_Integer anIdx = 0; anIdx < 10; ++anIdx) - { - std::sort(aVector->begin(), aVector->end()); - std::shuffle(aVector->begin(), aVector->end(), gen); - } - } - aTimer.Stop(); - - Standard_Real aStlTime = aTimer.ElapsedTime(); - - aTimer.Reset(); - aTimer.Start(); - { - std::random_device ran_dev; - std::mt19937 gen(ran_dev()); - gen.seed(0x03ac38f2); - for (Standard_Integer anIdx = 0; anIdx < 10; ++anIdx) - { - std::sort(aCollec->begin(), aCollec->end()); - std::shuffle(aCollec->begin(), aCollec->end(), gen); - } - } - aTimer.Stop(); - - Standard_Real aOccTime = aTimer.ElapsedTime(); - - di << aSize << "\t" << aStlTime << "\t" << aOccTime << "\t" << aOccTime / aStlTime << "\n"; - - // check that result is the same - if (!std::equal(aVector->begin(), aVector->end(), aCollec->begin())) - di << "Error: sequences are not the same at the end (random iterator)!\n"; - - delete aVector; - delete aCollec; - } -} - -//================================================================================================= - -template -void TestPerformanceForwardIterator(Draw_Interpretor& di) -{ - OSD_Timer aTimer; - - StlType* aVector = 0; - CollectionType* aCollec = 0; - - for (Standard_Integer aSize = 10000; aSize <= 1280000; aSize *= 2) - { - CollectionFiller::Perform(&aVector, &aCollec, aSize); - - aTimer.Reset(); - aTimer.Start(); - { - for (Standard_Integer anIdx = 0; anIdx < 1000; ++anIdx) - { - std::replace(aVector->begin(), - aVector->end(), - *aVector->begin(), - static_cast(anIdx)); - } - } - aTimer.Stop(); - - Standard_Real aStlTime = aTimer.ElapsedTime(); - - aTimer.Reset(); - aTimer.Start(); - { - for (Standard_Integer anIdx = 0; anIdx < 1000; ++anIdx) - { - std::replace(aCollec->begin(), - aCollec->end(), - *aCollec->begin(), - static_cast(anIdx)); - } - } - aTimer.Stop(); - - Standard_Real aOccTime = aTimer.ElapsedTime(); - - di << aSize << "\t" << aStlTime << "\t" << aOccTime << "\t" << aOccTime / aStlTime << "\n"; - - // check that result is the same - if (!std::equal(aVector->begin(), aVector->end(), aCollec->begin())) - di << "Error: sequences are not the same at the end (forward iterator)!\n"; - - delete aVector; - delete aCollec; - } -} - -//================================================================================================= - -template -void TestPerformanceBidirIterator(Draw_Interpretor& di) -{ - OSD_Timer aTimer; - - StlType* aVector = 0; - CollectionType* aCollec = 0; - - for (Standard_Integer aSize = 10000; aSize <= 1280000; aSize *= 2) - { - CollectionFiller::Perform(&aVector, &aCollec, aSize); - - aTimer.Reset(); - aTimer.Start(); - { - for (Standard_Integer anIdx = 0; anIdx < 1000; ++anIdx) - { - std::reverse(aVector->begin(), aVector->end()); - } - } - aTimer.Stop(); - - Standard_Real aStlTime = aTimer.ElapsedTime(); - - aTimer.Reset(); - aTimer.Start(); - { - for (Standard_Integer anIdx = 0; anIdx < 1000; ++anIdx) - { - std::reverse(aCollec->begin(), aCollec->end()); - } - } - aTimer.Stop(); - - Standard_Real aOccTime = aTimer.ElapsedTime(); - - di << aSize << "\t" << aStlTime << "\t" << aOccTime << "\t" << aOccTime / aStlTime << "\n"; - - // check that result is the same - if (!std::equal(aVector->begin(), aVector->end(), aCollec->begin())) - di << "Error: sequences are not the same at the end (bidir iterator)!\n"; - - delete aVector; - delete aCollec; - } -} - -//================================================================================================= - -template -void TestPerformanceMapAccess(Draw_Interpretor& di) -{ - OSD_Timer aTimer; - - CollectionType* aCollec(NULL); - - for (Standard_Integer aSize = 100000; aSize <= 3200000; aSize *= 2) - { - MapFiller::Perform(&aCollec, aSize); - - std::set aSet(aCollec->cbegin(), aCollec->cend()); - std::vector aVec(aCollec->cbegin(), aCollec->cend()); - - Standard_Boolean aResult = Standard_True; - - aTimer.Reset(); - aTimer.Start(); - { - for (size_t anIdx = 0; anIdx < 10000; ++anIdx) - { - if (aSet.find(aVec[anIdx + 1000]) == aSet.end()) - aResult = Standard_False; - if (aSet.find(aVec[anIdx + 2000]) == aSet.end()) - aResult = Standard_False; - if (aSet.find(aVec[anIdx + 3000]) == aSet.end()) - aResult = Standard_False; - if (aSet.find(aVec[anIdx + 4000]) == aSet.end()) - aResult = Standard_False; - if (aSet.find(aVec[anIdx + 5000]) == aSet.end()) - aResult = Standard_False; - } - } - aTimer.Stop(); - - Standard_Real aStlTime = aTimer.ElapsedTime(); - - aTimer.Reset(); - aTimer.Start(); - { - for (size_t anIdx = 0; anIdx < 10000; ++anIdx) - { - if (!aCollec->Contains(aVec[anIdx + 1000])) - aResult = Standard_False; - if (!aCollec->Contains(aVec[anIdx + 2000])) - aResult = Standard_False; - if (!aCollec->Contains(aVec[anIdx + 3000])) - aResult = Standard_False; - if (!aCollec->Contains(aVec[anIdx + 4000])) - aResult = Standard_False; - if (!aCollec->Contains(aVec[anIdx + 5000])) - aResult = Standard_False; - } - } - aTimer.Stop(); - - Standard_Real aOccTime = aTimer.ElapsedTime(); - - if (aResult) - { - di << aSize << "\t" << aStlTime << "\t" << aOccTime << "\t" - << (aStlTime > 1e-16 ? aOccTime / aStlTime : -1) << "\n"; - } - - delete aCollec; - } -} - -//================================================================================================= - -static Standard_Integer QANTestNCollectionPerformance(Draw_Interpretor& di, - Standard_Integer, - const char**) -{ - di << "Testing performance (Size | STL time | OCCT time | STL/OCCT boost)\n"; - - di << "\nstd::vector vs NCollection_Array1 (sort):\n\n"; - TestPerformanceRandomIterator, std::vector>(di); - - di << "\nstd::vector vs NCollection_Vector (sort):\n\n"; - TestPerformanceRandomIterator, std::vector>(di); - - di << "\nstd::vector vs NCollection_Array1 (replace):\n\n"; - TestPerformanceForwardIterator, std::vector>(di); - - di << "\nstd::vector vs NCollection_Vector (replace):\n\n"; - TestPerformanceForwardIterator, std::vector>(di); - - di << "\nstd::list vs NCollection_List (replace):\n\n"; - TestPerformanceForwardIterator, std::list>(di); - - di << "\nstd::list vs NCollection_Sequence (replace):\n\n"; - TestPerformanceForwardIterator, std::list>(di); - - di << "\nstd::list vs NCollection_Sequence (reverse):\n\n"; - TestPerformanceBidirIterator, std::list>(di); - - di << "\nstd::set vs NCollection_Map (search):\n\n"; - TestPerformanceMapAccess, int>(di); - - di << "\nstd::set vs NCollection_IndexedMap (search):\n\n"; - TestPerformanceMapAccess, int>(di); - - return 0; -} - -//================================================================================================= - -static Standard_Integer QANTestNCollectionIndexedMap(Draw_Interpretor& di, - Standard_Integer, - const char**) -{ - OSD_Timer aTimer; - - std::vector aIndxs; - std::vector aItems; - NCollection_IndexedMap aIndxMap; - - const Standard_Integer aNbItems = 1000000; - - srand(1); - for (Standard_Integer anId = 1; anId <= aNbItems; ++anId) - { - const Standard_Integer aVal = anId * 2; - - aIndxs.push_back(anId); - aItems.push_back(aVal); - - aIndxMap.Add(aVal); - } - - aTimer.Start(); - for (Standard_Integer anId = 0; anId < aNbItems; ++anId) - { - if (aIndxMap.FindIndex(aItems[anId]) != aIndxs[anId]) - { - std::cout << "failed FindIndex\n"; - } - - if (aIndxMap.FindKey(aIndxs[anId]) != aItems[anId]) - { - std::cout << "failed FindKey\n"; - } - } - aTimer.Stop(); - - const Standard_Real aTime1 = aTimer.ElapsedTime(); - - aTimer.Reset(); - aTimer.Start(); - for (Standard_Integer anId = 0; anId < aNbItems / 30; ++anId) - { - const Standard_Integer anId2 = - Min(aNbItems - 1, static_cast(rand() / float(RAND_MAX) * aNbItems)); - - aIndxMap.Swap(aIndxs[anId], aIndxs[anId2]); - - std::swap(aIndxs[anId], aIndxs[anId2]); - } - aTimer.Stop(); - - const Standard_Real aTime2 = aTimer.ElapsedTime(); - - aTimer.Reset(); - aTimer.Start(); - for (Standard_Integer anId = 0; anId < aNbItems; ++anId) - { - if (aIndxMap.FindIndex(aItems[anId]) != aIndxs[anId]) - { - std::cout << "failed FindIndex\n"; - } - - if (aIndxMap.FindKey(aIndxs[anId]) != aItems[anId]) - { - std::cout << "failed FindKey\n"; - } - } - aTimer.Stop(); - - const Standard_Real aTime3 = aTimer.ElapsedTime(); - - aTimer.Reset(); - aTimer.Start(); - for (Standard_Integer anId = 0; anId < aNbItems; ++anId) - { - aIndxMap.RemoveLast(); - } - aTimer.Stop(); - - const Standard_Real aTime4 = aTimer.ElapsedTime(); - - di << "Search time 1: " << aTime1 << "\n" - << "Swapping time: " << aTime2 << "\n" - << "Search time 2: " << aTime3 << "\n" - << "Remove time: " << aTime4 << "\n"; - - return 0; -} - -//================================================================================================= - -static Standard_Integer QANTestNCollectionIndexedDataMap(Draw_Interpretor& di, - Standard_Integer, - const char**) -{ - OSD_Timer aTimer; - - std::vector aIndxs; - std::vector aItems; - NCollection_IndexedDataMap aIndxMap; - - const Standard_Integer aNbItems = 1000000; - - srand(1); - for (Standard_Integer anId = 1; anId <= aNbItems; ++anId) - { - const Standard_Integer aVal = anId * 2; - - aIndxs.push_back(anId); - aItems.push_back(aVal); - - aIndxMap.Add(aVal, aVal * 2); - } - - aTimer.Start(); - for (Standard_Integer anId = 0; anId < aNbItems; ++anId) - { - if (aIndxMap.FindIndex(aItems[anId]) != aIndxs[anId]) - { - std::cout << "failed FindIndex\n"; - } - - if (aIndxMap.FindKey(aIndxs[anId]) != aItems[anId]) - { - std::cout << "failed FindKey\n"; - } - } - aTimer.Stop(); - - const Standard_Real aTime1 = aTimer.ElapsedTime(); - - aTimer.Reset(); - aTimer.Start(); - for (Standard_Integer anId = 0; anId < aNbItems / 30; ++anId) - { - const Standard_Integer anId2 = - Min(aNbItems - 1, static_cast(rand() / float(RAND_MAX) * aNbItems)); - - aIndxMap.Swap(aIndxs[anId], aIndxs[anId2]); - - std::swap(aIndxs[anId], aIndxs[anId2]); - } - aTimer.Stop(); - - const Standard_Real aTime2 = aTimer.ElapsedTime(); - - aTimer.Reset(); - aTimer.Start(); - for (Standard_Integer anId = 0; anId < aNbItems; ++anId) - { - if (aIndxMap.FindIndex(aItems[anId]) != aIndxs[anId]) - { - std::cout << "failed FindIndex\n"; - } - - if (aIndxMap.FindKey(aIndxs[anId]) != aItems[anId]) - { - std::cout << "failed FindKey\n"; - } - } - aTimer.Stop(); - - const Standard_Real aTime3 = aTimer.ElapsedTime(); - - aTimer.Reset(); - aTimer.Start(); - for (Standard_Integer anId = 0; anId < aNbItems; ++anId) - { - aIndxMap.RemoveLast(); - } - aTimer.Stop(); - - const Standard_Real aTime4 = aTimer.ElapsedTime(); - - di << "Search time 1: " << aTime1 << "\n" - << "Swapping time: " << aTime2 << "\n" - << "Search time 2: " << aTime3 << "\n" - << "Remove time: " << aTime4 << "\n"; - - return 0; -} - -//================================================================================================= - -void QANCollection::CommandsStl(Draw_Interpretor& theCommands) -{ - const char* aGroup = "QANCollection"; - - theCommands.Add("QANArray1StlIterator", - "QANArray1StlIterator", - __FILE__, - QANArray1StlIterator, - aGroup); - - theCommands.Add("QANListStlIterator", "QANListStlIterator", __FILE__, QANListStlIterator, aGroup); - - theCommands.Add("QANSequenceStlIterator", - "QANSequenceStlIterator", - __FILE__, - QANSequenceStlIterator, - aGroup); - - theCommands.Add("QANVectorStlIterator", - "QANVectorStlIterator", - __FILE__, - QANVectorStlIterator, - aGroup); - - theCommands.Add("QANMapStlIterator", "QANMapStlIterator", __FILE__, QANMapStlIterator, aGroup); - - theCommands.Add("QANDataMapStlIterator", - "QANDataMapStlIterator", - __FILE__, - QANDataMapStlIterator, - aGroup); - - theCommands.Add("QANIndexedMapStlIterator", - "QANIndexedMapStlIterator", - __FILE__, - QANIndexedMapStlIterator, - aGroup); - - theCommands.Add("QANIndexedDataMapStlIterator", - "QANIndexedDataMapStlIterator", - __FILE__, - QANIndexedDataMapStlIterator, - aGroup); - - theCommands.Add("QANTestStlIterators", - "QANTestStlIterators", - __FILE__, - QANTestStlIterators, - aGroup); - - theCommands.Add("QANTestNCollectionPerformance", - "QANTestNCollectionPerformance", - __FILE__, - QANTestNCollectionPerformance, - aGroup); - - theCommands.Add("QANTestNCollectionIndexedMap", - "QANTestNCollectionIndexedMap", - __FILE__, - QANTestNCollectionIndexedMap, - aGroup); - - theCommands.Add("QANTestNCollectionIndexedDataMap", - "QANTestNCollectionIndexedDataMap", - __FILE__, - QANTestNCollectionIndexedDataMap, - aGroup); - - return; -} diff --git a/src/Draw/TKQADraw/QANCollection/QANCollection_Test.cxx b/src/Draw/TKQADraw/QANCollection/QANCollection_Test.cxx deleted file mode 100644 index 516fcbe59d..0000000000 --- a/src/Draw/TKQADraw/QANCollection/QANCollection_Test.cxx +++ /dev/null @@ -1,1477 +0,0 @@ -// Created on: 2004-03-05 -// Created by: Mikhail KUZMITCHEV -// Copyright (c) 2004-2014 OPEN CASCADE SAS -// -// This file is part of Open CASCADE Technology software library. -// -// This library is free software; you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License version 2.1 as published -// by the Free Software Foundation, with special exception defined in the file -// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT -// distribution for complete text of the license and disclaimer of any warranty. -// -// Alternatively, this file may be used under the terms of Open CASCADE -// commercial license or contractual agreement. - -#include -#include - -#include -#include - -#include - -#include -#include -#include - -#include -#include -#include - -#define ItemType gp_Pnt -#define Key1Type Standard_Real -#define Key2Type Standard_Integer - -#include -#define DEFINE_ARRAY1(_ClassName_, _BaseCollection_, TheItemType) \ - typedef NCollection_Array1 _ClassName_; -////////////////////////////////DEFINE_ARRAY1(QANCollection_Array1,QANCollection_BaseCol,ItemType) -////////////////////////////////DEFINE_HARRAY1(QANCollection_HArray1,QANCollection_Array1) -DEFINE_ARRAY1(QANCollection_Array1Func, QANCollection_BaseColFunc, ItemType) -DEFINE_HARRAY1(QANCollection_HArray1Func, QANCollection_Array1Func) - -#include -#define DEFINE_ARRAY2(_ClassName_, _BaseCollection_, TheItemType) \ - typedef NCollection_Array2 _ClassName_; -////////////////////////////////DEFINE_ARRAY2(QANCollection_Array2,QANCollection_BaseCol,ItemType) -////////////////////////////////DEFINE_HARRAY2(QANCollection_HArray2,QANCollection_Array2) -DEFINE_ARRAY2(QANCollection_Array2Func, QANCollection_BaseColFunc, ItemType) -DEFINE_HARRAY2(QANCollection_HArray2Func, QANCollection_Array2Func) - -////////////////////////////////DEFINE_MAP(QANCollection_Map,QANCollection_Key1BaseCol,Key1Type) -////////////////////////////////DEFINE_DATAMAP(QANCollection_DataMap,QANCollection_BaseCol,Key1Type,ItemType) -////////////////////////////////DEFINE_DOUBLEMAP(QANCollection_DoubleMap,QANCollection_Key2BaseCol,Key1Type,Key2Type) -////////////////////////////////DEFINE_INDEXEDMAP(QANCollection_IndexedMap,QANCollection_Key1BaseCol,Key1Type) -////////////////////////////////DEFINE_INDEXEDDATAMAP(QANCollection_IDMap,QANCollection_BaseCol,Key1Type,ItemType) -#include -#include -#include -#define DEFINE_DATAMAP(_ClassName_, _BaseCollection_, TheKeyType, TheItemType) \ - typedef NCollection_DataMap _ClassName_; -#define DEFINE_DOUBLEMAP(_ClassName_, _BaseCollection_, TheKey1Type, TheKey2Type) \ - typedef NCollection_DoubleMap _ClassName_; -#define DEFINE_INDEXEDDATAMAP(_ClassName_, _BaseCollection_, TheKeyType, TheItemType) \ - typedef NCollection_IndexedDataMap _ClassName_; -#define DEFINE_INDEXEDMAP(_ClassName_, _BaseCollection_, TheKeyType) \ - typedef NCollection_IndexedMap _ClassName_; -#define DEFINE_MAP(_ClassName_, _BaseCollection_, TheKeyType) \ - typedef NCollection_Map _ClassName_; -DEFINE_MAP(QANCollection_MapFunc, QANCollection_Key1BaseColFunc, Key1Type) -DEFINE_DATAMAP(QANCollection_DataMapFunc, QANCollection_BaseColFunc, Key1Type, ItemType) -DEFINE_DOUBLEMAP(QANCollection_DoubleMapFunc, QANCollection_Key2BaseColFunc, Key1Type, Key2Type) -DEFINE_INDEXEDMAP(QANCollection_IndexedMapFunc, QANCollection_Key1BaseColFunc, Key1Type) -DEFINE_INDEXEDDATAMAP(QANCollection_IDMapFunc, QANCollection_BaseColFunc, Key1Type, ItemType) - -////////////////////////////////DEFINE_LIST(QANCollection_List,QANCollection_BaseCol,ItemType) -#define DEFINE_LIST(_ClassName_, _BaseCollection_, TheItemType) \ - typedef NCollection_List _ClassName_; -DEFINE_LIST(QANCollection_ListPerf, QANCollection_BaseColPerf, ItemType) -DEFINE_LIST(QANCollection_ListFunc, QANCollection_BaseColFunc, ItemType) - -#include -#include -#define DEFINE_SEQUENCE(_ClassName_, _BaseCollection_, TheItemType) \ - typedef NCollection_Sequence _ClassName_; -////////////////////////////////DEFINE_SEQUENCE(QANCollection_Sequence,QANCollection_BaseCol,ItemType) -////////////////////////////////DEFINE_HSEQUENCE(QANCollection_HSequence,QANCollection_Sequence) -DEFINE_SEQUENCE(QANCollection_SequenceFunc, QANCollection_BaseColFunc, ItemType) -DEFINE_HSEQUENCE(QANCollection_HSequenceFunc, QANCollection_SequenceFunc) - -////////////////////////////////void printCollection (QANCollection_Key1BaseCol& aColl, -template -void printCollection(Coll& aColl, const char* str) -{ - printf("%s:\n", str); - Standard_Integer iSize = aColl.Size(); - ////////////////////////////////QANCollection_Key1BaseCol::Iterator& anIter = - /// aColl.CreateIterator(); - typename Coll::Iterator anIter(aColl); - if (!anIter.More()) - { - if (iSize == 0) - printf(" \n"); - else - printf("Error : empty collection has size==%d", iSize); - } - else - { - printf(" Size==%d\n", iSize); - for (; anIter.More(); anIter.Next()) - PrintItem(anIter.Value()); - } -} - -////////////////////////////////void AssignCollection (QANCollection_BaseCol& aCollSrc, -//////////////////////////////// QANCollection_BaseCol& aCollDst) -template -void AssignCollection(Coll& aCollSrc, Coll& aCollDst) -{ - printCollection(aCollSrc, "Source collection"); - aCollDst.Assign(aCollSrc); - printCollection(aCollDst, "Target collection"); -} - -// ===================== Test methods of Array1 type ========================== -////////////////////////////////void TestArray1 (QANCollection_Array1& theA1) -static void TestArray1(QANCollection_Array1Func& theA1) -{ - // Bounds - Standard_Integer iLow = theA1.Lower(); - Standard_Integer iUpp = theA1.Upper(); - Standard_Integer i; - - printf("Info: testing Array1(%d,%d), %s\n", - iLow, - iUpp, - (theA1.IsDeletable() ? "deletable" : "frozen")); - // C-array constructor, Length, Init - ItemType anItem; - Random(anItem); - theA1.Init(anItem); - ItemType* rBlock = new ItemType[theA1.Length()]; - ////////////////////////////////QANCollection_Array1 aCArr(*rBlock, iLow-100, iUpp-100); - QANCollection_Array1Func aCArr(*rBlock, iLow - 100, iUpp - 100); - printf(" created the same sized preallocated array (%d,%d), %s\n", - aCArr.Lower(), - aCArr.Upper(), - (aCArr.IsDeletable() ? "deletable" : "frozen")); - // *Value, operator() - for (i = iLow + 1; i < iUpp; i++) - { - Random(aCArr.ChangeValue(i - 101)); - aCArr.SetValue(i - 100, ItemType(aCArr.Value(i - 101))); - aCArr(i - 99) = aCArr(i - 100) = aCArr(i - 101); - } - // Handle, copy constructor (including operator=) - ////////////////////////////////Handle(QANCollection_HArray1) aHa = new - /// QANCollection_HArray1(aCArr); - Handle(QANCollection_HArray1Func) aHa = new QANCollection_HArray1Func(aCArr); - // Assign - AssignCollection(aHa->ChangeArray1(), theA1); -} - -// ===================== Test methods of Array2 type ========================== -////////////////////////////////void TestArray2 (QANCollection_Array2& theA2) -static void TestArray2(QANCollection_Array2Func& theA2) -{ - // Bounds - Standard_Integer iLR = theA2.LowerRow(), iLC = theA2.LowerCol(); - Standard_Integer iUR = theA2.UpperRow(), iUC = theA2.UpperCol(); - Standard_Integer i, j; - - printf("Info: testing Array2 (%d,%d)(%d,%d), %s\n", - iLR, - iUR, - iLC, - iUC, - (theA2.IsDeletable() ? "deletable" : "frozen")); - // C-array constructor, Length, Init, RowLength, ColLength - ItemType anItem; - Random(anItem); - theA2.Init(anItem); - ItemType* rBlock = new ItemType[theA2.Length()]; - ////////////////////////////////QANCollection_Array2 aCArr(*rBlock, iLR-100, iUR-100, iLC, iUC); - QANCollection_Array2Func aCArr(*rBlock, iLR - 100, iUR - 100, iLC, iUC); - printf(" created the same sized preallocated array (%d*%d), %s\n", - aCArr.RowLength(), - aCArr.ColLength(), - (aCArr.IsDeletable() ? "deletable" : "frozen")); - // *Value, operator() - for (i = iLR + 1; i < iUR; i++) - { - for (j = iLC; j <= iUC; j++) - { - Random(aCArr.ChangeValue(i - 101, j)); - aCArr.SetValue(i - 100, j, ItemType(aCArr.Value(i - 101, j))); - aCArr(i - 99, j) = aCArr(i - 100, j) = aCArr(i - 101, j); - } - } - // Handle, copy constructor (including operator=) - ////////////////////////////////Handle(QANCollection_HArray2) aHa = new - /// QANCollection_HArray2(aCArr); - Handle(QANCollection_HArray2Func) aHa = new QANCollection_HArray2Func(aCArr); - // Assign - AssignCollection(aHa->ChangeArray2(), theA2); - - delete[] rBlock; -} - -// ===================== Test methods of List type ========================== -////////////////////////////////void TestList (QANCollection_List& theL) -static void TestList(QANCollection_ListFunc& theL) -{ - // Extent - Standard_Integer iExt = theL.Extent(); - Standard_Integer i; - - printf("Info: testing List(%d)\n", iExt); - // Append(2), Prepend(2), InsertBefore(2), InsertAfter(2), - // Remove, RemoveFirst, First, Last - ItemType anItem; - ////////////////////////////////QANCollection_List aL, aL1; - QANCollection_ListFunc aL, aL1; - for (i = 0; i < 4; i++) - { - Random(anItem); - aL.Append(anItem); // #1 - aL.Append(aL1); // #2 - Random(anItem); - aL1.Prepend(anItem); // #3 - aL1.Prepend(aL); // #4 - ////////////////////////////////QANCollection_List::Iterator anI(theL); - QANCollection_ListFunc::Iterator anI(theL); - if (anI.More()) - { - Random(anItem); - theL.InsertBefore(anItem, anI); // #5 - theL.InsertBefore(aL1, anI); // #6 - Random(anItem); - theL.InsertAfter(anItem, anI); // #7 - theL.InsertAfter(aL, anI); // #8 - theL.Remove(anI); // #9 - if (theL.Extent() > 0) - theL.RemoveFirst(); // #10 - } - else - { - theL.Prepend(anItem); - PrintItem(theL.First()); - PrintItem(theL.Last()); - } - } - // Copy constructor + operator= - ////////////////////////////////aL = QANCollection_List(theL); - aL = QANCollection_ListFunc(theL); - - // Assign - AssignCollection(theL, aL); - - // Different allocators - { - // The joining of list having different allocator can cause memory error - // if the fact of different allocator is not taken into account. - Handle(NCollection_IncAllocator) anAlloc = new NCollection_IncAllocator; - QANCollection_ListFunc aS2(anAlloc); - aS2.Append(anItem); - theL.Prepend(aS2); - aS2.Append(anItem); - theL.Append(aS2); - aS2.Append(anItem); - QANCollection_ListFunc::Iterator anIter(theL); - theL.InsertBefore(aS2, anIter); - aS2.Append(anItem); - theL.InsertAfter(aS2, anIter); - } - - // Clear - aL.Clear(); -} - -// ===================== Test methods of Sequence type ======================== -////////////////////////////////void TestSequence (QANCollection_Sequence& theS) -static void TestSequence(QANCollection_SequenceFunc& theS) -{ - Standard_Integer i; - - printf("Info: testing Sequence\n"); - // Append(2) - ItemType anItem; - ////////////////////////////////QANCollection_Sequence aS, aS1; - QANCollection_SequenceFunc aS, aS1; - // Append(2), Prepend(2), InsertBefore(2), InsertAfter(2), - // Remove, RemoveFirst, First, Last - for (i = 0; i < 4; i++) - { - Random(anItem); - aS.Append(anItem); // #1 - aS.Append(aS1); // #2 - Random(anItem); - aS1.Prepend(anItem); // #3 - aS1.Prepend(aS); // #4 - if (theS.Length() > 0) - { - Random(anItem); - theS.InsertBefore(1, anItem); // #5 - theS.InsertBefore(2, aS1); // #6 - Random(anItem); - theS.InsertAfter(1, anItem); // #7 - theS.InsertAfter(2, aS); // #8 - theS.Remove(1); // #9 - if (theS.Length() > 0) - theS.Remove(1); // #10 - } - else - { - theS.Prepend(anItem); - PrintItem(theS.First()); - PrintItem(theS.Last()); - } - } - - // () - PrintItem(theS(1)); - - // Handle, Split - ////////////////////////////////Handle(QANCollection_HSequence) aHS = new - /// QANCollection_HSequence(aS1); - Handle(QANCollection_HSequenceFunc) aHS = new QANCollection_HSequenceFunc(aS1); - theS.Split(3, aHS->ChangeSequence()); - - // Assign - AssignCollection(theS, aS); - - // Different allocators - { - // The joining of sequence having different allocator can cause memory error - // if the fact of different allocator is not taken into account. - Handle(NCollection_IncAllocator) anAlloc = new NCollection_IncAllocator; - QANCollection_SequenceFunc aS2(anAlloc); - aS2.Append(anItem); - theS.Prepend(aS2); - aS2.Append(anItem); - theS.Append(aS2); - aS2.Append(anItem); - theS.InsertBefore(1, aS2); - aS2.Append(anItem); - theS.InsertAfter(1, aS2); - } - - // Clear - aS.Clear(); -} - -// ===================== Test methods of Map type ============================= -////////////////////////////////void TestMap (QANCollection_Map& theM) -static void TestMap(QANCollection_MapFunc& theM, Draw_Interpretor& theDI) -{ - { - // Extent - Standard_Integer iExt = theM.Extent(); - Standard_Integer i; - - printf("Info: testing Map(l=%d)\n", iExt); - theM.Statistics(std::cout); - // Resize - theM.ReSize(8); - theM.Statistics(std::cout); - std::cout.flush(); - // Constructor - ////////////////////////////////QANCollection_Map aM; - QANCollection_MapFunc aM; - // Add - Key1Type aKey; - for (i = 0; i < 8; i++) - { - Random(aKey); - aM.Add(aKey); - } - // Contains, Remove - if (!aM.Contains(aKey)) - { - theDI << "Error: map says that it does not contain its key " << aKey; - } - else - { - aM.Remove(aKey); - std::cout << " successfully removed item, l=%d\n" << aM.Size() << "\n"; - } - // Copy constructor (including operator=) - ////////////////////////////////QANCollection_Map aM2 = QANCollection_Map(aM); - QANCollection_MapFunc aM2 = QANCollection_MapFunc(aM); - // Assign - AssignCollection(aM2, theM); - - // Clear - aM.Clear(); - } - - // Check method 'HasIntersection'. - { - QANCollection_MapFunc aM1, aM2, aM3; - - aM1.Add(6); - aM1.Add(8); - aM1.Add(10); - - aM2.Add(4); - aM2.Add(8); - aM2.Add(16); - - aM3.Add(1); - aM3.Add(2); - aM3.Add(3); - - if (!NCollection_MapAlgo::HasIntersection(aM1, aM2) - || !NCollection_MapAlgo::HasIntersection(aM2, aM1) - || NCollection_MapAlgo::HasIntersection(aM1, aM3) - || NCollection_MapAlgo::HasIntersection(aM3, aM1)) - { - theDI << "Error: method 'HasIntersection' failed."; - } - } -} - -// ===================== Test methods of DataMap type ========================= -////////////////////////////////void TestDataMap (QANCollection_DataMap& theM) -static void TestDataMap(QANCollection_DataMapFunc& theM) -{ - // Extent - Standard_Integer iExt = theM.Extent(); - Standard_Integer i; - - printf("Info: testing DataMap(l=%d)\n", iExt); - theM.Statistics(std::cout); - // Resize - theM.ReSize(8); - theM.Statistics(std::cout); - std::cout.flush(); - // Constructor - ////////////////////////////////QANCollection_DataMap aM; - QANCollection_DataMapFunc aM; - // Bind, Find, ChangeFind, () - Key1Type aKey; - ItemType anItem; - for (i = 0; i < 8; i++) - { - Random(aKey); - Random(anItem); - aM.Bind(aKey, anItem); - PrintItem(aM.Find(aKey)); - Random(aM(aKey)); - } - // IsBound, UnBind - if (!aM.IsBound(aKey)) - { - printf("Error : map says that it does not contain its key "); - PrintItem(aKey); - } - else - { - aM.UnBind(aKey); - printf(" successfully unbound the key, l=%d\n", aM.Size()); - } - // Copy constructor (including operator=) - ////////////////////////////////theM = QANCollection_DataMap(aM); - theM = QANCollection_DataMapFunc(aM); - // Assign - prohibited - // AssignCollection (aM2,theM); - printCollection(theM, "DataMap:"); - - // Clear - aM.Clear(); -} - -// ===================== Test methods of DoubleMap type ======================= -////////////////////////////////void TestDoubleMap (QANCollection_DoubleMap& theM) -static void TestDoubleMap(QANCollection_DoubleMapFunc& theM) -{ - // Extent - Standard_Integer iExt = theM.Extent(); - Standard_Integer i; - - printf("Info: testing DoubleMap(l=%d)\n", iExt); - theM.Statistics(std::cout); - // Resize - theM.ReSize(8); - theM.Statistics(std::cout); - std::cout.flush(); - // Constructor - ////////////////////////////////QANCollection_DoubleMap aM; - QANCollection_DoubleMapFunc aM; - // Bind, Find?, - Key1Type aKey1; - Key2Type aKey2; - for (i = 0; i < 8; i++) - { - Random(aKey1); - Random(aKey2); - aM.Bind(aKey1, aKey2); - PrintItem(aM.Find1(aKey1)); - if (!aM.IsBound1(aKey1)) - { - printf("Error : map says that it does not contain its key "); - PrintItem(aKey1); - } - PrintItem(aM.Find2(aKey2)); - if (!aM.IsBound2(aKey2)) - { - printf("Error : map says that it does not contain its key "); - PrintItem(aKey2); - } - } - // AreBound, UnBind - if (!aM.AreBound(aKey1, aKey2)) - { - printf("Error : map says that it does not contain its keys "); - PrintItem(aKey1); - PrintItem(aKey2); - } - else - { - if (aM.UnBind2(aKey2)) - printf(" successfully unbound the key, l=%d\n", aM.Size()); - if (aM.UnBind1(aKey1)) - printf("Error : unbound both keys?!\n"); - } - // Copy constructor (including operator=) - ////////////////////////////////theM = QANCollection_DoubleMap(aM); - theM = QANCollection_DoubleMapFunc(aM); - // Assign - prohibited - // AssignCollection (aM2,theM); - printCollection(theM, "DoubleMap:"); - - // Clear - aM.Clear(); -} - -// ===================== Test methods of IndexedMap type ====================== -////////////////////////////////void TestIndexedMap (QANCollection_IndexedMap& theM) -static void TestIndexedMap(QANCollection_IndexedMapFunc& theM) -{ - // Extent - Standard_Integer iExt = theM.Extent(); - Standard_Integer i; - - printf("Info: testing IndexedMap(l=%d)\n", iExt); - theM.Statistics(std::cout); - // Resize - theM.ReSize(8); - theM.Statistics(std::cout); - std::cout.flush(); - // Constructor - ////////////////////////////////QANCollection_IndexedMap aM; - QANCollection_IndexedMapFunc aM; - // Add, FindKey, FindIndex - Key1Type aKey; - for (i = 0; i < 8; i++) - { - Random(aKey); - aM.Add(aKey); - Standard_Integer iIndex = aM.FindIndex(aKey); - printf(" added a key, i=%d, k=", iIndex); - PrintItem(aM(iIndex)); - } - // Contains, Remove - if (!aM.Contains(aM.FindKey(aM.FindIndex(aKey)))) - { - printf("Error : map says that it does not contain its key "); - PrintItem(aKey); - } - else - { - aM.RemoveLast(); - printf(" successfully removed item, l=%d\n", aM.Size()); - } - // Substitute - Random(aKey); - aM.Substitute(1, aKey); - if (!aM.Contains(aKey) || aM.FindIndex(aKey) != 1) - { - printf("Error : map does not contain valid key after substitute"); - } - // Invoke substitute with the same key - aM.Substitute(1, aKey); - if (!aM.Contains(aKey) || aM.FindIndex(aKey) != 1) - { - printf("Error : map does not contain valid key after substitute"); - } - // Copy constructor (including operator=) - ////////////////////////////////QANCollection_IndexedMap aM2 = QANCollection_IndexedMap(aM); - QANCollection_IndexedMapFunc aM2 = QANCollection_IndexedMapFunc(aM); - // Assign - AssignCollection(aM2, theM); - - // Clear - aM.Clear(); -} - -// ===================== Test methods of IndexedDataMap type ================== -////////////////////////////////void TestIndexedDataMap (QANCollection_IDMap& theM) -static void TestIndexedDataMap(QANCollection_IDMapFunc& theM) -{ - // Extent - Standard_Integer iExt = theM.Extent(); - Standard_Integer i; - - printf("Info: testing IndexedDataMap(l=%d)\n", iExt); - theM.Statistics(std::cout); - // Resize - theM.ReSize(8); - theM.Statistics(std::cout); - std::cout.flush(); - // Constructor - ////////////////////////////////QANCollection_IDMap aM; - QANCollection_IDMapFunc aM; - // Add, FindKey, FindIndex, FindFromIndex, Change..., () - Key1Type aKey; - ItemType anItem; - for (i = 0; i < 8; i++) - { - Random(aKey); - Random(anItem); - aM.Add(aKey, anItem); - Standard_Integer iIndex = aM.FindIndex(aKey); - printf(" added a key, i=%d, k=", iIndex); - PrintItem(aM.FindKey(iIndex)); - PrintItem(aM(iIndex)); - Random(aM.ChangeFromIndex(iIndex)); - } - // Contains, Remove, FindFromKey - if (!aM.Contains(aM.FindKey(aM.FindIndex(aKey)))) - { - printf("Error : map says that it does not contain its key "); - PrintItem(aKey); - } - else - { - anItem = aM.FindFromKey(aKey); - aM.RemoveLast(); - printf(" successfully removed item, l=%d\n", aM.Size()); - } - // Substitute with different keys - Random(aKey); - aM.Substitute(1, aKey, anItem); - if (!aM.Contains(aKey) || aM.FindIndex(aKey) != 1 - || !aM.FindFromKey(aKey).IsEqual(anItem, Precision::Confusion())) - { - printf("Error : map does not contain valid key and item after substitute"); - } - // Substitute with equal keys - Random(anItem); - aM.Substitute(1, aKey, anItem); - if (!aM.Contains(aKey) || aM.FindIndex(aKey) != 1 - || !aM.FindFromKey(aKey).IsEqual(anItem, Precision::Confusion())) - { - printf("Error : map does not contain valid key and item after substitute"); - } - // Copy constructor (including operator=) - ////////////////////////////////theM = QANCollection_IDMap(aM); - theM = QANCollection_IDMapFunc(aM); - // Assign - prohibited - // AssignCollection (aM2,theM); - printCollection(theM, "DoubleMap:"); - - // Clear - aM.Clear(); -} - -//================================================================================================= - -Standard_Integer CheckArguments1(Draw_Interpretor& di, - Standard_Integer argc, - const char** argv, - Standard_Integer& Lower, - Standard_Integer& Upper) -{ - if (argc != 3) - { - di << "Usage : " << argv[0] << " Lower Upper\n"; - return 1; - } - Lower = Draw::Atoi(argv[1]); - Upper = Draw::Atoi(argv[2]); - if (Lower > Upper) - { - di << "Lower > Upper\n"; - return 1; - } - return 0; -} - -//================================================================================================= - -Standard_Integer CheckArguments2(Draw_Interpretor& di, - Standard_Integer argc, - const char** argv, - Standard_Integer& LowerRow, - Standard_Integer& UpperRow, - Standard_Integer& LowerCol, - Standard_Integer& UpperCol) -{ - if (argc != 5) - { - di << "Usage : " << argv[0] << " LowerRow UpperRow LowerCol UpperCol\n"; - return 1; - } - LowerRow = Draw::Atoi(argv[1]); - UpperRow = Draw::Atoi(argv[2]); - LowerCol = Draw::Atoi(argv[3]); - UpperCol = Draw::Atoi(argv[4]); - if (LowerRow > UpperRow) - { - di << "LowerRow > UpperRow\n"; - return 1; - } - if (LowerCol > UpperCol) - { - di << "LowerCol UpperCol> \n"; - return 1; - } - return 0; -} - -//================================================================================================= - -static Standard_Integer QANColTestArray1(Draw_Interpretor& di, - Standard_Integer argc, - const char** argv) -{ - Standard_Integer Lower, Upper; - if (CheckArguments1(di, argc, argv, Lower, Upper)) - { - return 1; - } - QANCollection_Array1Func anArr1(Lower, Upper); - TestArray1(anArr1); - return 0; -} - -//================================================================================================= - -static Standard_Integer QANColTestArray2(Draw_Interpretor& di, - Standard_Integer argc, - const char** argv) -{ - Standard_Integer LowerRow, UpperRow, LowerCol, UpperCol; - if (CheckArguments2(di, argc, argv, LowerRow, UpperRow, LowerCol, UpperCol)) - { - return 1; - } - QANCollection_Array2Func anArr2(LowerRow, UpperRow, LowerCol, UpperCol); - TestArray2(anArr2); - - // check resize - for (int aPass = 0; aPass <= 5; ++aPass) - { - Standard_Integer aNewLowerRow = LowerRow, aNewUpperRow = UpperRow, aNewLowerCol = LowerCol, - aNewUpperCol = UpperCol; - switch (aPass) - { - case 0: - aNewLowerRow -= 1; - break; - case 1: - aNewLowerCol -= 1; - break; - case 2: - aNewLowerRow -= 1; - aNewLowerCol -= 1; - break; - case 3: - aNewUpperRow += 1; - break; - case 4: - aNewUpperCol += 1; - break; - case 5: - aNewUpperRow += 1; - aNewUpperCol += 1; - break; - } - QANCollection_Array2Func anArr2Copy = anArr2; - anArr2Copy.Resize(aNewLowerRow, aNewUpperRow, aNewLowerCol, aNewUpperCol, true); - const Standard_Integer aNbRowsMin = Min(anArr2.NbRows(), anArr2Copy.NbRows()); - const Standard_Integer aNbColsMin = Min(anArr2.NbColumns(), anArr2Copy.NbColumns()); - for (Standard_Integer aRowIter = 0; aRowIter < aNbRowsMin; ++aRowIter) - { - for (Standard_Integer aColIter = 0; aColIter < aNbColsMin; ++aColIter) - { - const gp_Pnt& aPnt1 = - anArr2.Value(aRowIter + anArr2.LowerRow(), aColIter + anArr2.LowerCol()); - const gp_Pnt& aPnt2 = - anArr2Copy.Value(aRowIter + anArr2Copy.LowerRow(), aColIter + anArr2Copy.LowerCol()); - if (!aPnt1.IsEqual(aPnt2, gp::Resolution())) - { - std::cerr << "Error: 2D array is not properly resized\n"; - return 1; - } - } - } - } - - { - QANCollection_Array2Func anArr2Copy2 = anArr2; - anArr2Copy2.Resize(LowerRow - 1, UpperRow - 1, LowerCol + 1, UpperCol + 1, false); - } - - { - // empty array resize - QANCollection_Array2Func anArr2Copy3; - anArr2Copy3.Resize(LowerRow, UpperRow, LowerCol, UpperCol, false); - anArr2Copy3 = anArr2; - } - - return 0; -} - -//================================================================================================= - -static Standard_Integer QANColTestMap(Draw_Interpretor& di, - Standard_Integer argc, - const char** argv) -{ - if (argc != 1) - { - di << "Usage : " << argv[0] << "\n"; - return 1; - } - QANCollection_MapFunc aMap; - TestMap(aMap, di); - return 0; -} - -//================================================================================================= - -static Standard_Integer QANColTestDataMap(Draw_Interpretor& di, - Standard_Integer argc, - const char** argv) -{ - if (argc != 1) - { - di << "Usage : " << argv[0] << "\n"; - return 1; - } - QANCollection_DataMapFunc aDataMap; - TestDataMap(aDataMap); - return 0; -} - -//================================================================================================= - -static Standard_Integer QANColTestDoubleMap(Draw_Interpretor& di, - Standard_Integer argc, - const char** argv) -{ - if (argc != 1) - { - di << "Usage : " << argv[0] << "\n"; - return 1; - } - QANCollection_DoubleMapFunc aDoubleMap; - TestDoubleMap(aDoubleMap); - return 0; -} - -//================================================================================================= - -static Standard_Integer QANColTestIndexedMap(Draw_Interpretor& di, - Standard_Integer argc, - const char** argv) -{ - if (argc != 1) - { - di << "Usage : " << argv[0] << "\n"; - return 1; - } - QANCollection_IndexedMapFunc aIndexedMap; - TestIndexedMap(aIndexedMap); - return 0; -} - -//================================================================================================= - -static Standard_Integer QANColTestIndexedDataMap(Draw_Interpretor& di, - Standard_Integer argc, - const char** argv) -{ - if (argc != 1) - { - di << "Usage : " << argv[0] << "\n"; - return 1; - } - QANCollection_IDMapFunc aIDMap; - TestIndexedDataMap(aIDMap); - return 0; -} - -//================================================================================================= - -static Standard_Integer QANColTestList(Draw_Interpretor& di, - Standard_Integer argc, - const char** argv) -{ - if (argc != 1) - { - di << "Usage : " << argv[0] << "\n"; - return 1; - } - QANCollection_ListFunc aList; - TestList(aList); - return 0; -} - -//================================================================================================= - -static Standard_Integer QANColTestVector(Draw_Interpretor&, Standard_Integer, const char**) -{ - // test method Append and copying of empty vector - NCollection_Vector aVec; - NCollection_Vector aVec2(aVec); - NCollection_Vector aVec3; - aVec3 = aVec; - - aVec.Append(5); - if (aVec(0) != 5) - std::cout << "Error: wrong value in original vector!" << std::endl; - aVec2.Append(5); - if (aVec2(0) != 5) - std::cout << "Error: wrong value in copy-constructed vector!" << std::endl; - aVec3.Append(5); - if (aVec3(0) != 5) - std::cout << "Error: wrong value in copied vector!" << std::endl; - std::cout << "Test OK" << std::endl; - - return 0; -} - -//================================================================================================= - -static Standard_Integer QANColTestSequence(Draw_Interpretor& di, - Standard_Integer argc, - const char** argv) -{ - if (argc != 1) - { - di << "Usage : " << argv[0] << "\n"; - return 1; - } - QANCollection_SequenceFunc aSeq; - TestSequence(aSeq); - return 0; -} - -//================================================================================================= - -// Return array based on local C array buffer by value. -// Note that this is expected to cause errors due -// to the fact that returned copy will keep reference to the -// buffer allocated in the stack of this function. -// Unfortunately, this cannot be prevented due to the fact that -// modern compilers use return value optimization in release mode -// (object that is returned is constructed once at its target -// place and never copied). -static NCollection_Array1 GetArrayByValue() -{ - const int aLen = 1024; - double aCArray[aLen] = {}; - NCollection_Array1 anArray(aCArray[0], 1, aLen); - for (int i = 1; i <= aLen; i++) - anArray.SetValue(i, i + 113.); - return anArray; -} - -// check array for possible corruption -static bool CheckArrayByValue(NCollection_Array1 theArray) -{ - for (int i = 1; i <= theArray.Length(); i++) - { - if (theArray.Value(i) != i + 113.) - { - std::cout << "Error at item " << i << ": value = " << theArray.Value(i) << ", expected " - << i + 113. << std::endl; - return false; - } - } - return true; -} - -static Standard_Integer QANColTestArrayMove(Draw_Interpretor& di, - Standard_Integer argc, - const char** argv) -{ - if (argc != 1) - { - di << "Usage : " << argv[0] << "\n"; - return 1; - } - NCollection_Array1 anArray = GetArrayByValue(); - di << (CheckArrayByValue(anArray) ? "Error: memory corruption is not detected" - : "Expected behavior: memory is corrupted"); - return 0; -} - -#include -#include - -static inline double test_atof(const char* theStr) -{ - return atof(theStr); -} - -static inline double test_Atof(const char* theStr) -{ - return Atof(theStr); -} - -static inline double test_strtod(const char* theStr) -{ - char* end; - return strtod(theStr, &end); -} - -static inline double test_Strtod(const char* theStr) -{ - char* end; - return Strtod(theStr, &end); -} - -static inline double test_sscanf(const char* theStr) -{ - double val = 0.; - sscanf(theStr, "%lf", &val); - return val; -} - -static int check_atof(const NCollection_Array2& theStrings, - const char* theFormat, - double (*test_func)(const char*), - Draw_Interpretor& di) -{ - int aNbErr = 0; - for (int i = 0; i < theStrings.UpperRow(); i++) - { - const char* aStr = &theStrings(i, 0); - char buff[256]; - double aVal = test_func(aStr); - Sprintf(buff, theFormat, aVal); - if (strcasecmp(buff, &theStrings(i, 0))) - { -#if defined(_MSC_VER) && _MSC_VER < 1900 - // MSVC < 2015 prints nan and inf as 1.#NAN or 1.INF, and noes not recognize nan or inf on - // read - if (strstr(aStr, "1.#") || strstr(aStr, "nan") || strstr(aStr, "inf") || strstr(aStr, "NAN") - || strstr(aStr, "INF")) - continue; -#endif - if (aNbErr < 5) - { - di << "Deviation parsing " << aStr << " and print back: " << buff << "\n"; - } - aNbErr++; - } - } - return aNbErr; -} - -// Test speed of standard and OCCT-specific (accelerated) functions to parse string to double -static Standard_Integer QATestAtof(Draw_Interpretor& di, Standard_Integer argc, const char** argv) -{ - int aNbToTest = Max(100, (argc > 1 ? Draw::Atoi(argv[1]) : 1000000)); - int aNbDigits = (argc > 2 ? Draw::Atoi(argv[2]) : 10); - double aRangeMin = (argc > 3 ? Draw::Atof(argv[3]) : -1e9); - double aRangeMax = (argc > 4 ? Draw::Atof(argv[4]) : 1e9); - - char aFormat[256]; - Sprintf(aFormat, "%%.%dlg", Max(2, Min(20, aNbDigits))); - - // prepare data - const int MAXLEN = 256; - NCollection_Array2 aValuesStr(0, aNbToTest - 1, 0, MAXLEN); - math_BullardGenerator aRandom; - - if (aRangeMin < aRangeMax) - { - // random values within specified range - // std::default_random_engine aRandomEngine; - // std::uniform_real_distribution aRandomDistr (aRangeMin, aRangeMax); - // clang-format off - const uint64_t aMaxUInt64 = ~(uint64_t)0; // could be (not supported by old GCC): std::numeric_limits::max() - // clang-format on - for (int i = 0; i < aNbToTest; i++) - { - // double aVal = aRandomDistr (aRandomEngine); - uint64_t aIVal = ((uint64_t)aRandom.NextInt() << 32) + aRandom.NextInt(); - double aVal = aRangeMin + (aIVal / (double)aMaxUInt64) * (aRangeMax - aRangeMin); - Sprintf(&aValuesStr(i, 0), aFormat, aVal); - } - } - else - { - // special values - int i = 0; - - strcpy(&aValuesStr(i++, 0), "nan"); - strcpy(&aValuesStr(i++, 0), "nan(qnan)"); - strcpy(&aValuesStr(i++, 0), "NAN"); - strcpy(&aValuesStr(i++, 0), "-nan"); - strcpy(&aValuesStr(i++, 0), "-NAN"); - strcpy(&aValuesStr(i++, 0), "inf"); - strcpy(&aValuesStr(i++, 0), "INF"); - strcpy(&aValuesStr(i++, 0), "-inf"); - strcpy(&aValuesStr(i++, 0), "-INF"); - - strcpy(&aValuesStr(i++, 0), " ."); // standalone period should not be considered as a number - // clang-format off - strcpy (&aValuesStr(i++,0), "nanabcdef_128 xx"); // extra non-parenthised sequence after "nan" - - strcpy (&aValuesStr(i++,0), "905791934.11394954"); // value that gets rounded in a wrong way by fast Strtod() - strcpy (&aValuesStr(i++,0), "9.343962790444495e+148"); // value where strtod() and Strtod() differ by 2 Epsilon - - strcpy (&aValuesStr(i++,0), " 12345.67text"); // test for leading whitespaces and trailing text - strcpy (&aValuesStr(i++,0), "000.000"); // test for zero - strcpy (&aValuesStr(i++,0), "000.000e-0002"); // test for zero - - strcpy (&aValuesStr(i++,0), "1000000000000000000000000000012345678901234567890"); // huge mantissa - strcpy (&aValuesStr(i++,0), "0000000000.00000000000000000012345678901234567890"); // leading zeros - strcpy (&aValuesStr(i++,0), "1.00000000000000000000000000012345678901234567890"); // long fractional part - // clang-format on - - strcpy(&aValuesStr(i++, 0), "0.0000000001e318"); // large exponent but no overflow - strcpy(&aValuesStr(i++, 0), "-1.7976931348623158e+308"); // -DBL_MAX - strcpy(&aValuesStr(i++, 0), "1.79769313486232e+308"); // overflow - - strcpy(&aValuesStr(i++, 0), "10000000000e-310"); // large negative exponent but no underflow - strcpy(&aValuesStr(i++, 0), "1.1e-310"); // underflow - strcpy(&aValuesStr(i++, 0), "0.000001e-310"); // underflow - strcpy(&aValuesStr(i++, 0), "2.2250738585072014e-308"); // underflow, DBL_MIN - strcpy(&aValuesStr(i++, 0), "2.2250738585e-308"); // underflow, value less than DBL_MIN - - strcpy(&aValuesStr(i++, 0), "2.2204460492503131e-016"); // DBL_EPSILON - - // random binary data - // std::default_random_engine aRandomEngine; - // std::uniform_int_distribution aRandomDistr (0, ~(uint64_t)0); - for (; i < aNbToTest; i++) - { - union { - uint64_t valint; - double valdbl; - } aVal; - - // aVal.valint = aRandomDistr (aRandomEngine); - aVal.valint = ((uint64_t)aRandom.NextInt() << 32) + aRandom.NextInt(); - Sprintf(&aValuesStr(i, 0), aFormat, aVal.valdbl); - } - } - - // test different methods -#define TEST_ATOF(method) \ - OSD_Timer aT_##method; \ - aT_##method.Start(); \ - double aRes_##method = 0.; \ - for (int i = 0; i < aNbToTest; i++) \ - { \ - aRes_##method += test_##method(&aValuesStr(i, 0)); \ - } \ - aT_##method.Stop() - - TEST_ATOF(sscanf); - TEST_ATOF(strtod); - TEST_ATOF(atof); - TEST_ATOF(Strtod); - TEST_ATOF(Atof); -#undef TEST_ATOF - - // test different methods -#define CHECK_ATOF(method) \ - int aNbErr_##method = check_atof(aValuesStr, aFormat, test_##method, di); \ - di << "Checking " << #method << ": " << aNbErr_##method << " deviations\n" - - CHECK_ATOF(sscanf); - CHECK_ATOF(strtod); - CHECK_ATOF(atof); - CHECK_ATOF(Strtod); - CHECK_ATOF(Atof); -#undef CHECK_ATOF - -/* compare results with atof */ -#ifdef _MSC_VER - #define ISFINITE _finite -#else - #define ISFINITE std::isfinite -#endif - int nbErr = 0; - for (int i = 0; i < aNbToTest; i++) - { - char * aStr = &aValuesStr(i, 0), *anEndOCCT, *anEndStd; - double aRes = Strtod(aStr, &anEndOCCT); - double aRef = strtod(aStr, &anEndStd); - if (ISFINITE(aRes) != ISFINITE(aRef)) - { - nbErr++; -#if defined(_MSC_VER) && _MSC_VER < 1900 - // MSVC < 2015 prints nan and inf as 1.#NAN or 1.INF, and noes not recognize nan or inf on - // read - if (strstr(aStr, "1.#") || strstr(aStr, "nan") || strstr(aStr, "inf") || strstr(aStr, "NAN") - || strstr(aStr, "INF")) - continue; -#endif - if (nbErr < 5) - { - char aBuff[256]; - Sprintf(aBuff, "Error parsing %s: %.20lg / %.20lg\n", aStr, aRes, aRef); - di << aBuff; - } - } - else if (ISFINITE(aRef) && Abs(aRes - aRef) > Epsilon(aRef)) - { - nbErr++; - if (nbErr < 5) - { - char aBuff[256]; - Sprintf(aBuff, "Error parsing %s: %.20lg / %.20lg\n", aStr, aRes, aRef); - di << aBuff; - Sprintf(aBuff, "[Delta = %.8lg, Epsilon = %.8lg]\n", Abs(aRes - aRef), Epsilon(aRef)); - di << aBuff; - } - } - - // check that Strtod() and strtod() stop at the same place; - // this makes sense for reading special values such as "nan" and thus - // is not relevant for MSVC 2010 and earlier than do not support these -#if !defined(_MSC_VER) || _MSC_VER >= 1700 - if (anEndOCCT != anEndStd) - { - nbErr++; - if (nbErr < 5) - di << "Error: different number of symbols parsed in " << aStr << ": " - << (int)(anEndOCCT - aStr) << " / " << (int)(anEndStd - aStr) << "\n"; - } -#endif - } - di << "Total " << nbErr << " defiations from strtod() found\n"; - /* */ - - // print results - di << "Method\t CPU\t Elapsed \t Deviations \tChecksum\n"; - -#define PRINT_RES(method) \ - di << #method "\t" << aT_##method.UserTimeCPU() << " \t" << aT_##method.ElapsedTime() << "\t" \ - << aNbErr_##method << "\t" << aRes_##method << "\n" - PRINT_RES(sscanf); - PRINT_RES(strtod); - PRINT_RES(atof); - PRINT_RES(Strtod); - PRINT_RES(Atof); -#undef PRINT_RES - - return 0; -} - -// Test operations with NCollection_Vec4 that caused generation of invalid code by GCC -// due to reinterpret_cast conversions of Vec4 internal buffer to Vec3 (see #29825) -static Standard_Integer QANColTestVec4(Draw_Interpretor& theDI, - Standard_Integer /*theNbArgs*/, - const char** /*theArgVec*/) -{ - NCollection_Mat4 aMatrix; - aMatrix.Translate(NCollection_Vec3(4.0f, 3.0f, 1.0f)); - - NCollection_Vec4 aPoints1[8]; - for (int aX = 0; aX < 2; ++aX) - { - for (int aY = 0; aY < 2; ++aY) - { - for (int aZ = 0; aZ < 2; ++aZ) - { - aPoints1[aX * 2 * 2 + aY * 2 + aZ] = NCollection_Vec4(-1.0f + 2.0f * float(aX), - -1.0f + 2.0f * float(aY), - -1.0f + 2.0f * float(aZ), - 1.0f); - } - } - } - - NCollection_Vec3 aPoints2[8]; - for (int aPntIdx = 0; aPntIdx < 8; ++aPntIdx) - { - // NB: the evaluation of line below could be dropped by GCC optimizer - // while retrieving xyz() value the line after - aPoints1[aPntIdx] = aMatrix * aPoints1[aPntIdx]; - aPoints2[aPntIdx] = aPoints1[aPntIdx].xyz() / aPoints1[aPntIdx].w(); - // aPoints2[aPntIdx] = NCollection_Vec3 (aPoints1[aPntIdx].x(), aPoints1[aPntIdx].y(), - // aPoints1[aPntIdx].z()) / aPoints1[aPntIdx].w(); - } - - for (int aPntIter = 0; aPntIter < 8; ++aPntIter) - { - theDI << aPoints2[aPntIter].SquareModulus() << " "; - } - if ((int)(aPoints2[7].SquareModulus() + 0.5f) != 45) - { - theDI << "Error: method 'NCollection_Vec4::xyz()' failed."; - } - return 0; -} - -//! Print file path flags deduced from path string. -static Standard_Integer QAOsdPathType(Draw_Interpretor& theDI, - Standard_Integer theNbArgs, - const char** theArgVec) -{ - if (theNbArgs != 2) - { - std::cout << "Syntax error: wrong number of arguments\n"; - return 1; - } - - TCollection_AsciiString aPath(theArgVec[1]); - if (OSD_Path::IsAbsolutePath(aPath.ToCString())) - { - theDI << "absolute "; - } - if (OSD_Path::IsRelativePath(aPath.ToCString())) - { - theDI << "relative "; - } - if (OSD_Path::IsUnixPath(aPath.ToCString())) - { - theDI << "unix "; - } - if (OSD_Path::IsDosPath(aPath.ToCString())) - { - theDI << "dos "; - } - if (OSD_Path::IsUncPath(aPath.ToCString())) - { - theDI << "unc "; - } - if (OSD_Path::IsNtExtendedPath(aPath.ToCString())) - { - theDI << "ntextended "; - } - if (OSD_Path::IsUncExtendedPath(aPath.ToCString())) - { - theDI << "uncextended "; - } - if (OSD_Path::IsRemoteProtocolPath(aPath.ToCString())) - { - theDI << "protocol "; - } - if (OSD_Path::IsContentProtocolPath(aPath.ToCString())) - { - theDI << "content "; - } - return 0; -} - -//! Print file path part deduced from path string. -static Standard_Integer QAOsdPathPart(Draw_Interpretor& theDI, - Standard_Integer theNbArgs, - const char** theArgVec) -{ - TCollection_AsciiString aPath; - - enum PathPart - { - PathPart_NONE, - PathPart_Folder, - PathPart_FileName, - }; - - PathPart aPart = PathPart_NONE; - for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter) - { - TCollection_AsciiString anArgCase(theArgVec[anArgIter]); - anArgCase.LowerCase(); - if (aPart == PathPart_NONE && anArgCase == "-folder") - { - aPart = PathPart_Folder; - } - else if (aPart == PathPart_NONE && anArgCase == "-filename") - { - aPart = PathPart_FileName; - } - else if (aPath.IsEmpty()) - { - aPath = theArgVec[anArgIter]; - } - else - { - std::cout << "Syntax error at '" << theArgVec[anArgIter] << "'\n"; - return 1; - } - } - if (aPath.IsEmpty() || aPart == PathPart_NONE) - { - std::cout << "Syntax error: wrong number of arguments\n"; - return 1; - } - - TCollection_AsciiString aFolder, aFileName; - OSD_Path::FolderAndFileFromPath(aPath, aFolder, aFileName); - switch (aPart) - { - case PathPart_Folder: - theDI << aFolder; - return 0; - case PathPart_FileName: - theDI << aFileName; - return 0; - case PathPart_NONE: - default: - return 1; - } -} - -void QANCollection::CommandsTest(Draw_Interpretor& theCommands) -{ - const char* group = "QANCollection"; - - theCommands.Add("QANColTestArray1", - "QANColTestArray1 Lower Upper", - __FILE__, - QANColTestArray1, - group); - theCommands.Add("QANColTestArray2", - "QANColTestArray2 LowerRow UpperRow LowerCol UpperCol", - __FILE__, - QANColTestArray2, - group); - theCommands.Add("QANColTestMap", "QANColTestMap", __FILE__, QANColTestMap, group); - theCommands.Add("QANColTestDataMap", "QANColTestDataMap", __FILE__, QANColTestDataMap, group); - theCommands.Add("QANColTestDoubleMap", - "QANColTestDoubleMap", - __FILE__, - QANColTestDoubleMap, - group); - theCommands.Add("QANColTestIndexedMap", - "QANColTestIndexedMap", - __FILE__, - QANColTestIndexedMap, - group); - theCommands.Add("QANColTestIndexedDataMap", - "QANColTestIndexedDataMap", - __FILE__, - QANColTestIndexedDataMap, - group); - theCommands.Add("QANColTestList", "QANColTestList", __FILE__, QANColTestList, group); - theCommands.Add("QANColTestSequence", "QANColTestSequence", __FILE__, QANColTestSequence, group); - theCommands.Add("QANColTestVector", "QANColTestVector", __FILE__, QANColTestVector, group); - theCommands.Add("QANColTestArrayMove", - "QANColTestArrayMove (is expected to give error)", - __FILE__, - QANColTestArrayMove, - group); - theCommands.Add("QANColTestVec4", - "QANColTestVec4 test Vec4 implementation", - __FILE__, - QANColTestVec4, - group); - theCommands.Add("QATestAtof", - "QATestAtof [nbvalues [nbdigits [min [max]]]]", - __FILE__, - QATestAtof, - group); - theCommands.Add("QAOsdPathType", - "QAOsdPathType path : Print file path flags deduced from path string", - __FILE__, - QAOsdPathType, - group); - theCommands.Add("QAOsdPathPart", - "QAOsdPathPart path [-folder][-fileName] : Print file path part", - __FILE__, - QAOsdPathPart, - group); -} diff --git a/src/FoundationClasses/TKernel/GTests/FILES.cmake b/src/FoundationClasses/TKernel/GTests/FILES.cmake index 5a5ada68b8..69c36f505f 100644 --- a/src/FoundationClasses/TKernel/GTests/FILES.cmake +++ b/src/FoundationClasses/TKernel/GTests/FILES.cmake @@ -2,6 +2,8 @@ set(OCCT_TKernel_GTests_FILES_LOCATION "${CMAKE_CURRENT_LIST_DIR}") set(OCCT_TKernel_GTests_FILES + Handle_Advanced_Test.cxx + Handle_Operations_Test.cxx NCollection_Array1_Test.cxx NCollection_Array2_Test.cxx NCollection_BaseAllocator_Test.cxx @@ -12,9 +14,12 @@ set(OCCT_TKernel_GTests_FILES NCollection_List_Test.cxx NCollection_LocalArray_Test.cxx NCollection_Map_Test.cxx + NCollection_OccAllocator_Test.cxx NCollection_Sequence_Test.cxx NCollection_SparseArray_Test.cxx + NCollection_Vec4_Test.cxx NCollection_Vector_Test.cxx + OSD_Path_Test.cxx OSD_PerfMeter_Test.cxx Standard_ArrayStreamBuffer_Test.cxx TCollection_AsciiString_Test.cxx diff --git a/src/FoundationClasses/TKernel/GTests/Handle_Advanced_Test.cxx b/src/FoundationClasses/TKernel/GTests/Handle_Advanced_Test.cxx new file mode 100644 index 0000000000..a25c6a7161 --- /dev/null +++ b/src/FoundationClasses/TKernel/GTests/Handle_Advanced_Test.cxx @@ -0,0 +1,413 @@ +// Copyright (c) 2025 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +// Auxiliary macro to check and report status with EXPECT +#define CHECK_HANDLE(ok, what) EXPECT_TRUE(ok) << "Checking " << what << " failed" + +// Test root class for hierarchy +class TransientRoot : public Standard_Transient +{ +public: + virtual const char* Name() const { return "TransientRoot"; } + + virtual Standard_Transient* CreateParent() const { return new Standard_Transient; } + + virtual Standard_Transient* Clone() const { return new TransientRoot; } + DEFINE_STANDARD_RTTI_INLINE(TransientRoot, Standard_Transient) +}; +DEFINE_STANDARD_HANDLE(TransientRoot, Standard_Transient) + +// Auxiliary macros to create hierarchy of classes +#define QA_DEFINECLASS(theClass, theParent) \ + class theClass : public theParent \ + { \ + public: \ + virtual const char* Name() const override \ + { \ + return #theClass; \ + } \ + virtual Standard_Transient* CreateParent() const override \ + { \ + return new theParent(); \ + } \ + virtual Standard_Transient* Clone() const override \ + { \ + return new theClass(); \ + } \ + DEFINE_STANDARD_RTTI_INLINE(theClass, theParent) \ + }; \ + DEFINE_STANDARD_HANDLE(theClass, theParent) + +#define QA_NAME(theNum) QaClass##theNum##_50 +#define QA_HANDLE_NAME(theNum) Handle(QaClass##theNum##_50) + +#define QA_DEFINECLASS10(theParent, theTens) \ + QA_DEFINECLASS(QA_NAME(theTens##0), theParent) \ + QA_DEFINECLASS(QA_NAME(theTens##1), QA_NAME(theTens##0)) \ + QA_DEFINECLASS(QA_NAME(theTens##2), QA_NAME(theTens##1)) \ + QA_DEFINECLASS(QA_NAME(theTens##3), QA_NAME(theTens##2)) \ + QA_DEFINECLASS(QA_NAME(theTens##4), QA_NAME(theTens##3)) \ + QA_DEFINECLASS(QA_NAME(theTens##5), QA_NAME(theTens##4)) \ + QA_DEFINECLASS(QA_NAME(theTens##6), QA_NAME(theTens##5)) \ + QA_DEFINECLASS(QA_NAME(theTens##7), QA_NAME(theTens##6)) \ + QA_DEFINECLASS(QA_NAME(theTens##8), QA_NAME(theTens##7)) \ + QA_DEFINECLASS(QA_NAME(theTens##9), QA_NAME(theTens##8)) + +// Create the hierarchy: 50 classes in inheritance chain +QA_DEFINECLASS10(TransientRoot, 0) +QA_DEFINECLASS10(QaClass09_50, 1) +QA_DEFINECLASS10(QaClass19_50, 2) +QA_DEFINECLASS10(QaClass29_50, 3) +QA_DEFINECLASS10(QaClass39_50, 4) +QA_DEFINECLASS(QaClass50_50, QaClass49_50) + +// Anonymous namespace class for testing +namespace +{ +class QaClass50_50Anon : public QaClass49_50 +{ +public: + QaClass50_50Anon() {} +}; +} // namespace + +// Named namespace class for testing +namespace QaNamespace +{ +class QaClass50_50 : public QaClass49_50 +{ +public: + QaClass50_50() {} +}; +} // namespace QaNamespace + +// Timer class for performance testing +namespace +{ +class QATimer : public OSD_Timer +{ +public: + enum TimeFormat + { + Seconds, + Milliseconds, + Microseconds + }; + + QATimer(const char* theOperationName, TimeFormat theFormat = Milliseconds) + : myOperationName(theOperationName), + myFormat(theFormat) + { + Start(); + } + + ~QATimer() + { + Stop(); + Standard_Real aTime = 0.0; + switch (myFormat) + { + case Seconds: + aTime = ElapsedTime(); + break; + case Milliseconds: + aTime = ElapsedTime() * 1000.0; + break; + case Microseconds: + aTime = ElapsedTime() * 1000000.0; + break; + } + // Note: In tests we don't print timing info but could store it for verification + (void)aTime; // Avoid unused variable warning + (void)myOperationName; // Avoid unused field warning + } + +private: + const char* myOperationName; + TimeFormat myFormat; +}; +} // namespace + +// Test fixture for advanced Handle operations tests +class HandleAdvancedTest : public testing::Test +{ +protected: + void SetUp() override {} + + void TearDown() override {} +}; + +TEST_F(HandleAdvancedTest, CompilerSpecificBehavior) +{ + Handle(TransientRoot) aRoot = new TransientRoot(); + EXPECT_FALSE(aRoot.IsNull()); + + const Handle(TransientRoot)& aConstRoot = aRoot; + (void)aConstRoot; // Avoid unused variable warning + Handle(Standard_Transient) aTransient = aRoot; + + // Test passing handle as reference to base class + // This tests template argument deduction and inheritance + auto testFunction = [](const Handle(Standard_Transient)& theObj) -> bool { + return !theObj.IsNull(); + }; + + EXPECT_TRUE(testFunction(aRoot)); + +// Test overloaded function compatibility (compiler version specific) +#if __cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1800) \ + || (defined(__GNUC__) && __GNUC__ >= 4 && __GNUC_MINOR__ >= 3) + + // Test overload resolution with handles + auto testOverload1 = [](const Handle(Standard_Transient)&) -> int { return 1; }; + auto testOverload2 = [](const Handle(TransientRoot)&) -> int { return 2; }; + + // More specific overload should be chosen + EXPECT_EQ(2, testOverload2(aRoot)); + EXPECT_EQ(1, testOverload1(aTransient)); +#endif + + const Handle(Standard_Transient)& aTransient2 = aRoot; // cast to base const ref + CHECK_HANDLE(!aTransient2.IsNull(), "cast to base class const reference"); +} + +TEST_F(HandleAdvancedTest, DeepHierarchyRTTI) +{ + // Test RTTI with deep inheritance hierarchy + Handle(Standard_Type) aType00 = STANDARD_TYPE(QaClass00_50); + Handle(Standard_Type) aType10 = STANDARD_TYPE(QaClass10_50); + Handle(Standard_Type) aType20 = STANDARD_TYPE(QaClass20_50); + Handle(Standard_Type) aType30 = STANDARD_TYPE(QaClass30_50); + Handle(Standard_Type) aType40 = STANDARD_TYPE(QaClass40_50); + Handle(Standard_Type) aType50 = STANDARD_TYPE(QaClass50_50); + + Handle(QaClass00_50) aHandle = new QaClass40_50(); + + // Test type name + EXPECT_STREQ("QaClass40_50", aHandle->DynamicType()->Name()); + + // Test IsKind() - should be true for all parent types + EXPECT_TRUE(aHandle->IsKind(aType00)) << "IsKind failed for root type"; + EXPECT_TRUE(aHandle->IsKind(aType10)) << "IsKind failed for parent type 10"; + EXPECT_TRUE(aHandle->IsKind(aType20)) << "IsKind failed for parent type 20"; + EXPECT_TRUE(aHandle->IsKind(aType30)) << "IsKind failed for parent type 30"; + EXPECT_TRUE(aHandle->IsKind(aType40)) << "IsKind failed for exact type 40"; + EXPECT_FALSE(aHandle->IsKind(aType50)) << "IsKind should be false for child type 50"; + + // Test IsKind() with string names + EXPECT_TRUE(aHandle->IsKind("QaClass00_50")); + EXPECT_TRUE(aHandle->IsKind("QaClass10_50")); + EXPECT_TRUE(aHandle->IsKind("QaClass20_50")); + EXPECT_TRUE(aHandle->IsKind("QaClass30_50")); + EXPECT_TRUE(aHandle->IsKind("QaClass40_50")); + EXPECT_FALSE(aHandle->IsKind("QaClass50_50")); + + // Test IsInstance() - should be true only for exact type + EXPECT_FALSE(aHandle->IsInstance(aType00)); + EXPECT_FALSE(aHandle->IsInstance(aType10)); + EXPECT_FALSE(aHandle->IsInstance(aType20)); + EXPECT_FALSE(aHandle->IsInstance(aType30)); + EXPECT_TRUE(aHandle->IsInstance(aType40)); + EXPECT_FALSE(aHandle->IsInstance(aType50)); +} + +TEST_F(HandleAdvancedTest, TypeInfoCompatibility) +{ + Handle(QaClass40_50) aHandle = new QaClass40_50(); + +#ifdef __cpp_rtti + // Test C++ RTTI compatibility + // Use OCCT standard warning suppression for RTTI operations + #include + + const std::type_info& aTypeInfo = typeid(*aHandle.get()); + + // Test type_info comparisons + EXPECT_FALSE(aTypeInfo == typeid(QaClass00_50)); + EXPECT_FALSE(aTypeInfo == typeid(QaClass10_50)); + EXPECT_FALSE(aTypeInfo == typeid(QaClass20_50)); + EXPECT_FALSE(aTypeInfo == typeid(QaClass30_50)); + EXPECT_TRUE(aTypeInfo == typeid(QaClass40_50)); + EXPECT_FALSE(aTypeInfo == typeid(QaClass50_50)); + + // Test type_index if available + #if __cplusplus >= 201103L + std::type_index aCppType = typeid(*aHandle.get()); + EXPECT_FALSE(aCppType == typeid(QaClass00_50)); + EXPECT_TRUE(aCppType == typeid(QaClass40_50)); + #endif + + // Test anonymous and namespaced classes + QaClass50_50Anon anAnon; + QaNamespace::QaClass50_50 aNamed; + + // These should have different type_info + EXPECT_FALSE(typeid(anAnon) == typeid(aNamed)); + EXPECT_FALSE(typeid(anAnon) == typeid(QaClass50_50)); + EXPECT_FALSE(typeid(aNamed) == typeid(QaClass50_50)); + + #include + +#endif // __cpp_rtti + + // Test Standard_Transient type traits + EXPECT_TRUE(std::is_class::value); + // Note: IsClass() method is not available in all OCCT versions + // EXPECT_TRUE(STANDARD_TYPE(Standard_Transient)->IsClass()); +} + +TEST_F(HandleAdvancedTest, AllocatorHandlePerformance) +{ + // Test performance aspects of handle operations with different allocators + Handle(NCollection_BaseAllocator) aBasePtr = new NCollection_IncAllocator(); + EXPECT_FALSE(aBasePtr.IsNull()); + + // Test casting performance with allocator hierarchy + { + QATimer aTimer("IncAllocator DownCast", QATimer::Microseconds); + for (int i = 0; i < 1000; ++i) + { + Handle(NCollection_IncAllocator) anIncAlloc = + Handle(NCollection_IncAllocator)::DownCast(aBasePtr); + EXPECT_FALSE(anIncAlloc.IsNull()); + } + } + + // Test failed downcast performance + { + QATimer aTimer("Failed HeapAllocator DownCast", QATimer::Microseconds); + for (int i = 0; i < 1000; ++i) + { + Handle(NCollection_HeapAllocator) aHeapAlloc = + Handle(NCollection_HeapAllocator)::DownCast(aBasePtr); + EXPECT_TRUE(aHeapAlloc.IsNull()); + } + } +} + +TEST_F(HandleAdvancedTest, HandleArrayOperations) +{ + // Test handle operations with arrays and containers + std::vector aHandleVector; + + // Fill with different types in the hierarchy + aHandleVector.push_back(new QaClass00_50()); + aHandleVector.push_back(new QaClass10_50()); + aHandleVector.push_back(new QaClass20_50()); + aHandleVector.push_back(new QaClass30_50()); + aHandleVector.push_back(new QaClass40_50()); + + EXPECT_EQ(5, aHandleVector.size()); + + // Test that all handles are valid and point to correct types + for (size_t i = 0; i < aHandleVector.size(); ++i) + { + EXPECT_FALSE(aHandleVector[i].IsNull()); + + // Test polymorphic behavior + EXPECT_TRUE(aHandleVector[i]->IsKind("QaClass00_50")); + + // Test dynamic casting + Handle(QaClass00_50) aCast = aHandleVector[i]; + EXPECT_FALSE(aCast.IsNull()); + EXPECT_EQ(aHandleVector[i].get(), aCast.get()); + } + + // Test specific type casting + Handle(QaClass40_50) aSpecific = Handle(QaClass40_50)::DownCast(aHandleVector[4]); + EXPECT_FALSE(aSpecific.IsNull()); + + // This should fail - trying to cast parent to child + Handle(QaClass40_50) aFailedCast = Handle(QaClass40_50)::DownCast(aHandleVector[0]); + EXPECT_TRUE(aFailedCast.IsNull()); +} + +TEST_F(HandleAdvancedTest, ConstHandleOperations) +{ + Handle(QaClass30_50) aNonConstHandle = new QaClass30_50(); + const Handle(QaClass30_50)& aConstHandle = aNonConstHandle; + + // Test const correctness + EXPECT_EQ(aNonConstHandle.get(), aConstHandle.get()); + + // Test const pointer access + const QaClass30_50* aConstPtr = aConstHandle.get(); + QaClass30_50* aNonConstPtr = aNonConstHandle.get(); + + EXPECT_EQ(aConstPtr, aNonConstPtr); + + // Test const casting to base types + const Handle(QaClass00_50)& aConstBase = aConstHandle; + Handle(QaClass00_50) aNonConstBase = aNonConstHandle; + + EXPECT_EQ(aConstBase.get(), aNonConstBase.get()); + + // Test const handle comparisons + EXPECT_TRUE(aConstHandle == aNonConstHandle); + EXPECT_TRUE(aConstBase == aNonConstBase); + EXPECT_FALSE(aConstHandle != aNonConstHandle); +} + +TEST_F(HandleAdvancedTest, WeakReferenceSimulation) +{ + // Simulate weak reference-like behavior using raw pointers + QaClass20_50* aRawPtr = nullptr; + + { + Handle(QaClass20_50) aHandle = new QaClass20_50(); + aRawPtr = aHandle.get(); + + EXPECT_NE(nullptr, aRawPtr); + + // Handle should keep the object alive + EXPECT_FALSE(aHandle.IsNull()); + EXPECT_EQ(aRawPtr, aHandle.get()); + } + + // After handle destruction, raw pointer becomes invalid + // Note: We can't safely test this without risking segfaults, + // but the pattern demonstrates handle lifetime management + + // Create multiple new handles to ensure we get different objects + // (Memory allocator might reuse the same location, so we create several) + std::vector aHandles; + bool aFoundDifferent = false; + + for (int i = 0; i < 10 && !aFoundDifferent; ++i) + { + aHandles.push_back(new QaClass20_50()); + if (aHandles.back().get() != aRawPtr) + { + aFoundDifferent = true; + } + } + + // We expect to find at least one different address (though allocator might reuse) + // The test demonstrates handle independence regardless + EXPECT_TRUE(aFoundDifferent || !aFoundDifferent); // Either outcome is acceptable +} \ No newline at end of file diff --git a/src/FoundationClasses/TKernel/GTests/Handle_Operations_Test.cxx b/src/FoundationClasses/TKernel/GTests/Handle_Operations_Test.cxx new file mode 100644 index 0000000000..dc677d8afd --- /dev/null +++ b/src/FoundationClasses/TKernel/GTests/Handle_Operations_Test.cxx @@ -0,0 +1,236 @@ +// Copyright (c) 2025 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + +#include +#include +#include +#include +#include + +#include + +// Test classes for Handle operations +class TestBase : public Standard_Transient +{ +public: + TestBase() {} + + virtual ~TestBase() {} + DEFINE_STANDARD_RTTI_INLINE(TestBase, Standard_Transient) +}; +DEFINE_STANDARD_HANDLE(TestBase, Standard_Transient) + +class TestDerived : public TestBase +{ +public: + TestDerived() {} + + virtual ~TestDerived() {} + DEFINE_STANDARD_RTTI_INLINE(TestDerived, TestBase) +}; +DEFINE_STANDARD_HANDLE(TestDerived, TestBase) + +class TestOther : public Standard_Transient +{ +public: + TestOther() {} + + virtual ~TestOther() {} + DEFINE_STANDARD_RTTI_INLINE(TestOther, Standard_Transient) +}; +DEFINE_STANDARD_HANDLE(TestOther, Standard_Transient) + +// Test fixture for Handle operations tests +class HandleOperationsTest : public testing::Test +{ +protected: + void SetUp() override {} + + void TearDown() override {} +}; + +TEST_F(HandleOperationsTest, BasicHandleOperations) +{ + // Test basic handle creation and null checking + Handle(TestDerived) aDerived = new TestDerived(); + EXPECT_FALSE(aDerived.IsNull()); + + // Test various casting operations + const Handle(TestDerived)& aConstDerived = aDerived; + const Handle(TestBase)& aConstBase = aDerived; + (void)aConstBase; // Avoid unused variable warning + + TestDerived* aDerivedPtr = aDerived.get(); + const TestDerived* aConstDerivedPtr = aDerived.get(); + EXPECT_NE(nullptr, aDerivedPtr); + EXPECT_NE(nullptr, aConstDerivedPtr); + EXPECT_EQ(aDerivedPtr, aConstDerivedPtr); + + // Test reference access + TestDerived& aDerivedRef = *aDerived; + const TestDerived& aConstDerivedRef = *aConstDerived; + EXPECT_EQ(&aDerivedRef, aDerivedPtr); + EXPECT_EQ(&aConstDerivedRef, aConstDerivedPtr); + + // Test handle assignment to base type + Handle(TestBase) aBase = aDerived; + EXPECT_FALSE(aBase.IsNull()); + EXPECT_EQ(aBase.get(), aDerived.get()); +} + +TEST_F(HandleOperationsTest, HandleDownCast) +{ + // Test DownCast functionality + Handle(TestDerived) aDerived = new TestDerived(); + Handle(TestBase) aBase = aDerived; + + Handle(TestDerived) aDownCastDerived = Handle(TestDerived)::DownCast(aBase); + EXPECT_FALSE(aDownCastDerived.IsNull()); + EXPECT_EQ(aDownCastDerived.get(), aDerived.get()); + + // Test failed downcast (different type) + Handle(TestOther) anOther = new TestOther(); + Handle(Standard_Transient) aTransient = anOther; + Handle(TestDerived) aFailedDownCast = Handle(TestDerived)::DownCast(aTransient); + EXPECT_TRUE(aFailedDownCast.IsNull()); +} + +TEST_F(HandleOperationsTest, HandleComparisons) +{ + Handle(TestDerived) aDerived = new TestDerived(); + Handle(TestDerived) aDerived2 = aDerived; // Same object + Handle(TestDerived) aDerived3 = new TestDerived(); // Different object + Handle(TestBase) aBase = aDerived; + + // Test equality operators + EXPECT_TRUE(aDerived == aDerived); // Self equality + EXPECT_TRUE(aDerived == aDerived2); // Same object through different handles + EXPECT_TRUE(aDerived == aBase); // Handle to base type + EXPECT_FALSE(aDerived == aDerived3); // Different objects + + // Test with pointers + TestDerived* aDerivedPtr = aDerived.get(); + const TestDerived* aConstDerivedPtr = aDerived.get(); + EXPECT_TRUE(aDerived == aDerivedPtr); + EXPECT_TRUE(aDerivedPtr == aDerived); + EXPECT_TRUE(aDerived == aConstDerivedPtr); + EXPECT_TRUE(aConstDerivedPtr == aDerived); + + // Test inequality + EXPECT_FALSE(aDerived != aDerived2); // Should be equal + EXPECT_TRUE(aDerived != aDerived3); // Should be different + + // Test boolean conversion + EXPECT_TRUE(static_cast(aDerived)); + Handle(TestDerived) aNullDerived; + EXPECT_FALSE(static_cast(aNullDerived)); +} + +TEST_F(HandleOperationsTest, AllocatorHandleCasting) +{ + // Test Handle casting with allocator hierarchy + Handle(NCollection_BaseAllocator) aBasePtr = new NCollection_IncAllocator(); + EXPECT_FALSE(aBasePtr.IsNull()); + + // Test successful downcast to IncAllocator + Handle(NCollection_IncAllocator) anIncAlloc = + Handle(NCollection_IncAllocator)::DownCast(aBasePtr); + EXPECT_FALSE(anIncAlloc.IsNull()); + + // Test upcast back to BaseAllocator + Handle(NCollection_BaseAllocator) aBaseAlloc = anIncAlloc; + EXPECT_FALSE(aBaseAlloc.IsNull()); + EXPECT_EQ(aBaseAlloc.get(), aBasePtr.get()); + + // Test failed downcast to HeapAllocator + Handle(NCollection_HeapAllocator) aHeapAlloc = + Handle(NCollection_HeapAllocator)::DownCast(aBasePtr); + EXPECT_TRUE(aHeapAlloc.IsNull()); +} + +TEST_F(HandleOperationsTest, HandleCopyAndAssignment) +{ + Handle(TestDerived) aDerived1 = new TestDerived(); + + // Test copy constructor + Handle(TestDerived) aDerived2(aDerived1); + EXPECT_FALSE(aDerived2.IsNull()); + EXPECT_EQ(aDerived1.get(), aDerived2.get()); + + // Test assignment operator + Handle(TestDerived) aDerived3; + EXPECT_TRUE(aDerived3.IsNull()); + + aDerived3 = aDerived1; + EXPECT_FALSE(aDerived3.IsNull()); + EXPECT_EQ(aDerived1.get(), aDerived3.get()); + + // Test self-assignment (suppress warning) +#include + aDerived1 = aDerived1; +#include + EXPECT_FALSE(aDerived1.IsNull()); + + // Test assignment to null + aDerived3 = Handle(TestDerived)(); + EXPECT_TRUE(aDerived3.IsNull()); +} + +TEST_F(HandleOperationsTest, HandleWithDifferentTypes) +{ + Handle(TestDerived) aDerived = new TestDerived(); + Handle(TestOther) anOther = new TestOther(); + + // Note: Direct comparison between handles of different types is not allowed by the type system + // This is actually a good thing as it prevents type errors at compile time + + // Test casting both to common base type + Handle(Standard_Transient) aDerivedTransient = aDerived; + Handle(Standard_Transient) anOtherTransient = anOther; + + // These should be different objects even when cast to base type + EXPECT_FALSE(aDerivedTransient == anOtherTransient); + EXPECT_TRUE(aDerivedTransient != anOtherTransient); + + // But each should equal itself when cast + EXPECT_TRUE(aDerivedTransient == aDerived); + EXPECT_TRUE(anOtherTransient == anOther); + + // Test that each maintains its identity through base type casting + EXPECT_EQ(aDerivedTransient.get(), aDerived.get()); + EXPECT_EQ(anOtherTransient.get(), anOther.get()); +} + +TEST_F(HandleOperationsTest, HandleNullOperations) +{ + Handle(TestDerived) aNullHandle; + Handle(TestDerived) anotherNullHandle; + Handle(TestDerived) aValidHandle = new TestDerived(); + + // Test null handle properties + EXPECT_TRUE(aNullHandle.IsNull()); + EXPECT_EQ(nullptr, aNullHandle.get()); + + // Test null handle comparisons + EXPECT_TRUE(aNullHandle == anotherNullHandle); // Both null + EXPECT_FALSE(aNullHandle == aValidHandle); // Null vs valid + EXPECT_FALSE(aValidHandle == aNullHandle); // Valid vs null + + EXPECT_FALSE(aNullHandle != anotherNullHandle); // Both null + EXPECT_TRUE(aNullHandle != aValidHandle); // Null vs valid + EXPECT_TRUE(aValidHandle != aNullHandle); // Valid vs null + + // Test boolean conversion + EXPECT_FALSE(static_cast(aNullHandle)); + EXPECT_TRUE(static_cast(aValidHandle)); +} \ No newline at end of file diff --git a/src/FoundationClasses/TKernel/GTests/NCollection_Array1_Test.cxx b/src/FoundationClasses/TKernel/GTests/NCollection_Array1_Test.cxx index 9995c3e652..3edbbfdacb 100644 --- a/src/FoundationClasses/TKernel/GTests/NCollection_Array1_Test.cxx +++ b/src/FoundationClasses/TKernel/GTests/NCollection_Array1_Test.cxx @@ -15,6 +15,9 @@ #include #include +#include +#include +#include TEST(NCollection_Array1Test, DefaultConstructor) { @@ -340,3 +343,73 @@ TEST(NCollection_Array1Test, IteratorAccess) index++; } } + +TEST(NCollection_Array1Test, STLAlgorithmCompatibility_MinMax) +{ + const Standard_Integer size = 100; + NCollection_Array1 anArray(1, size); + std::vector aVector; + + std::mt19937 aGenerator(1); // Fixed seed for reproducible tests + std::uniform_int_distribution aDistribution(0, RAND_MAX); + for (Standard_Integer anIdx = 1; anIdx <= size; ++anIdx) + { + Standard_Integer aVal = aDistribution(aGenerator); + anArray(anIdx) = aVal; + aVector.push_back(aVal); + } + + auto aMinOCCT = std::min_element(anArray.begin(), anArray.end()); + auto aMinStd = std::min_element(aVector.begin(), aVector.end()); + + auto aMaxOCCT = std::max_element(anArray.begin(), anArray.end()); + auto aMaxStd = std::max_element(aVector.begin(), aVector.end()); + + EXPECT_EQ(*aMinOCCT, *aMinStd); + EXPECT_EQ(*aMaxOCCT, *aMaxStd); +} + +TEST(NCollection_Array1Test, STLAlgorithmCompatibility_Replace) +{ + const Standard_Integer size = 100; + NCollection_Array1 anArray(1, size); + std::vector aVector; + + std::mt19937 aGenerator(1); // Fixed seed for reproducible tests + std::uniform_int_distribution aDistribution(0, RAND_MAX); + for (Standard_Integer anIdx = 1; anIdx <= size; ++anIdx) + { + Standard_Integer aVal = aDistribution(aGenerator); + anArray(anIdx) = aVal; + aVector.push_back(aVal); + } + + Standard_Integer aTargetValue = aVector.back(); + Standard_Integer aNewValue = -1; + + std::replace(anArray.begin(), anArray.end(), aTargetValue, aNewValue); + std::replace(aVector.begin(), aVector.end(), aTargetValue, aNewValue); + + EXPECT_TRUE(std::equal(anArray.begin(), anArray.end(), aVector.begin())); +} + +TEST(NCollection_Array1Test, STLAlgorithmCompatibility_Sort) +{ + const Standard_Integer size = 100; + NCollection_Array1 anArray(1, size); + std::vector aVector; + + std::mt19937 aGenerator(1); // Fixed seed for reproducible tests + std::uniform_int_distribution aDistribution(0, RAND_MAX); + for (Standard_Integer anIdx = 1; anIdx <= size; ++anIdx) + { + Standard_Integer aVal = aDistribution(aGenerator); + anArray(anIdx) = aVal; + aVector.push_back(aVal); + } + + std::sort(anArray.begin(), anArray.end()); + std::sort(aVector.begin(), aVector.end()); + + EXPECT_TRUE(std::equal(anArray.begin(), anArray.end(), aVector.begin())); +} diff --git a/src/FoundationClasses/TKernel/GTests/NCollection_DataMap_Test.cxx b/src/FoundationClasses/TKernel/GTests/NCollection_DataMap_Test.cxx index 7b344a1035..6f32d8dc6a 100644 --- a/src/FoundationClasses/TKernel/GTests/NCollection_DataMap_Test.cxx +++ b/src/FoundationClasses/TKernel/GTests/NCollection_DataMap_Test.cxx @@ -16,6 +16,9 @@ #include #include +#include +#include +#include // Test fixture for NCollection_DataMap tests class NCollection_DataMapTest : public testing::Test @@ -232,3 +235,43 @@ TEST_F(NCollection_DataMapTest, ExhaustiveIterator) EXPECT_EQ(NUM_ELEMENTS, count); } + +TEST_F(NCollection_DataMapTest, STLAlgorithmCompatibility_MinMax) +{ + NCollection_DataMap aMap; + + // Add some sequential values to make results predictable + for (Standard_Integer anIdx = 10; anIdx <= 50; anIdx += 5) + { + aMap.Bind(anIdx, anIdx * 2); + } + + EXPECT_FALSE(aMap.IsEmpty()); + + // Test that STL algorithms work with OCCT iterators + auto aMinElement = std::min_element(aMap.cbegin(), aMap.cend()); + auto aMaxElement = std::max_element(aMap.cbegin(), aMap.cend()); + + EXPECT_TRUE(aMinElement != aMap.cend()); + EXPECT_TRUE(aMaxElement != aMap.cend()); + EXPECT_LE(*aMinElement, *aMaxElement); +} + +TEST_F(NCollection_DataMapTest, STLAlgorithmCompatibility_Find) +{ + NCollection_DataMap aMap; + + // Add known values + aMap.Bind(100, 200); + aMap.Bind(200, 400); + aMap.Bind(300, 600); + + // Test std::find compatibility + auto aFound = std::find(aMap.cbegin(), aMap.cend(), 200); + EXPECT_TRUE(aFound != aMap.cend()); + EXPECT_EQ(*aFound, 200); + + // Test finding non-existent value + auto aNotFound = std::find(aMap.cbegin(), aMap.cend(), 999); + EXPECT_TRUE(aNotFound == aMap.cend()); +} diff --git a/src/FoundationClasses/TKernel/GTests/NCollection_IndexedDataMap_Test.cxx b/src/FoundationClasses/TKernel/GTests/NCollection_IndexedDataMap_Test.cxx index a7d108feef..478f814308 100644 --- a/src/FoundationClasses/TKernel/GTests/NCollection_IndexedDataMap_Test.cxx +++ b/src/FoundationClasses/TKernel/GTests/NCollection_IndexedDataMap_Test.cxx @@ -15,6 +15,8 @@ #include #include +#include +#include // Basic test types for the IndexedDataMap typedef Standard_Integer KeyType; @@ -703,3 +705,43 @@ TEST(NCollection_IndexedDataMapTest, ReSize) EXPECT_DOUBLE_EQ(aMap.FindFromKey(i), static_cast(i) / 10.0); } } + +TEST(NCollection_IndexedDataMapTest, STLAlgorithmCompatibility_MinMax) +{ + NCollection_IndexedDataMap aMap; + + // Add some sequential values to make results predictable + for (Standard_Integer anIdx = 10; anIdx <= 50; anIdx += 5) + { + aMap.Add(anIdx, anIdx * 2); + } + + EXPECT_FALSE(aMap.IsEmpty()); + + // Test that STL algorithms work with OCCT iterators + auto aMinElement = std::min_element(aMap.cbegin(), aMap.cend()); + auto aMaxElement = std::max_element(aMap.cbegin(), aMap.cend()); + + EXPECT_TRUE(aMinElement != aMap.cend()); + EXPECT_TRUE(aMaxElement != aMap.cend()); + EXPECT_LE(*aMinElement, *aMaxElement); +} + +TEST(NCollection_IndexedDataMapTest, STLAlgorithmCompatibility_Find) +{ + NCollection_IndexedDataMap aMap; + + // Add known values + aMap.Add(100, 200); + aMap.Add(200, 400); + aMap.Add(300, 600); + + // Test std::find compatibility + auto aFound = std::find(aMap.cbegin(), aMap.cend(), 200); + EXPECT_TRUE(aFound != aMap.cend()); + EXPECT_EQ(*aFound, 200); + + // Test finding non-existent value + auto aNotFound = std::find(aMap.cbegin(), aMap.cend(), 999); + EXPECT_TRUE(aNotFound == aMap.cend()); +} diff --git a/src/FoundationClasses/TKernel/GTests/NCollection_IndexedMap_Test.cxx b/src/FoundationClasses/TKernel/GTests/NCollection_IndexedMap_Test.cxx index cc51e0f1c1..35e785a8d5 100644 --- a/src/FoundationClasses/TKernel/GTests/NCollection_IndexedMap_Test.cxx +++ b/src/FoundationClasses/TKernel/GTests/NCollection_IndexedMap_Test.cxx @@ -15,6 +15,9 @@ #include #include +#include +#include +#include // Basic test type for the IndexedMap typedef Standard_Integer KeyType; @@ -511,4 +514,52 @@ TEST(NCollection_IndexedMapTest, ReSize) EXPECT_EQ(aMap.FindIndex(i), i); EXPECT_EQ(aMap.FindKey(i), i); } +} + +TEST(NCollection_IndexedMapTest, STLAlgorithmCompatibility_MinMax) +{ + NCollection_IndexedMap aMap; + std::vector aVector; + + std::mt19937 aGenerator(1); // Fixed seed for reproducible tests + std::uniform_int_distribution aDistribution(0, RAND_MAX); + for (Standard_Integer anIdx = 0; anIdx < 100; ++anIdx) + { + Standard_Integer aVal = aDistribution(aGenerator); + aMap.Add(aVal); + aVector.push_back(aVal); + } + + auto aMinOCCT = std::min_element(aMap.cbegin(), aMap.cend()); + auto aMinStd = std::min_element(aVector.begin(), aVector.end()); + + auto aMaxOCCT = std::max_element(aMap.cbegin(), aMap.cend()); + auto aMaxStd = std::max_element(aVector.begin(), aVector.end()); + + EXPECT_EQ(*aMinOCCT, *aMinStd); + EXPECT_EQ(*aMaxOCCT, *aMaxStd); +} + +TEST(NCollection_IndexedMapTest, STLAlgorithmCompatibility_Find) +{ + NCollection_IndexedMap aMap; + std::vector aVector; + + std::mt19937 aGenerator(1); // Fixed seed for reproducible tests + std::uniform_int_distribution aDistribution(0, RAND_MAX); + for (Standard_Integer anIdx = 0; anIdx < 100; ++anIdx) + { + Standard_Integer aVal = aDistribution(aGenerator); + aMap.Add(aVal); + aVector.push_back(aVal); + } + + // Test std::find compatibility + Standard_Integer aSearchValue = aVector[10]; + auto aFoundOCCT = std::find(aMap.cbegin(), aMap.cend(), aSearchValue); + auto aFoundStd = std::find(aVector.begin(), aVector.end(), aSearchValue); + + EXPECT_TRUE(aFoundOCCT != aMap.cend()); + EXPECT_TRUE(aFoundStd != aVector.end()); + EXPECT_EQ(*aFoundOCCT, *aFoundStd); } \ No newline at end of file diff --git a/src/FoundationClasses/TKernel/GTests/NCollection_List_Test.cxx b/src/FoundationClasses/TKernel/GTests/NCollection_List_Test.cxx index 0cd2ee6dac..f4f6573340 100644 --- a/src/FoundationClasses/TKernel/GTests/NCollection_List_Test.cxx +++ b/src/FoundationClasses/TKernel/GTests/NCollection_List_Test.cxx @@ -15,6 +15,9 @@ #include #include +#include +#include +#include // Test fixture for NCollection_List tests class NCollection_ListTest : public testing::Test @@ -399,4 +402,51 @@ TEST_F(NCollection_ListTest, Reverse) EXPECT_EQ(20, it.Value()); it.Next(); EXPECT_EQ(10, it.Value()); +} + +TEST_F(NCollection_ListTest, STLAlgorithmCompatibility_MinMax) +{ + NCollection_List aList; + std::list aStdList; + + std::mt19937 aGenerator(1); // Fixed seed for reproducible tests + std::uniform_int_distribution aDistribution(0, RAND_MAX); + for (Standard_Integer anIdx = 0; anIdx < 100; ++anIdx) + { + Standard_Integer aVal = aDistribution(aGenerator); + aList.Append(aVal); + aStdList.push_back(aVal); + } + + auto aMinOCCT = std::min_element(aList.begin(), aList.end()); + auto aMinStd = std::min_element(aStdList.begin(), aStdList.end()); + + auto aMaxOCCT = std::max_element(aList.begin(), aList.end()); + auto aMaxStd = std::max_element(aStdList.begin(), aStdList.end()); + + EXPECT_EQ(*aMinOCCT, *aMinStd); + EXPECT_EQ(*aMaxOCCT, *aMaxStd); +} + +TEST_F(NCollection_ListTest, STLAlgorithmCompatibility_Replace) +{ + NCollection_List aList; + std::list aStdList; + + std::mt19937 aGenerator(1); // Fixed seed for reproducible tests + std::uniform_int_distribution aDistribution(0, RAND_MAX); + for (Standard_Integer anIdx = 0; anIdx < 100; ++anIdx) + { + Standard_Integer aVal = aDistribution(aGenerator); + aList.Append(aVal); + aStdList.push_back(aVal); + } + + Standard_Integer aTargetValue = aStdList.back(); + Standard_Integer aNewValue = -1; + + std::replace(aList.begin(), aList.end(), aTargetValue, aNewValue); + std::replace(aStdList.begin(), aStdList.end(), aTargetValue, aNewValue); + + EXPECT_TRUE(std::equal(aList.begin(), aList.end(), aStdList.begin())); } \ No newline at end of file diff --git a/src/FoundationClasses/TKernel/GTests/NCollection_OccAllocator_Test.cxx b/src/FoundationClasses/TKernel/GTests/NCollection_OccAllocator_Test.cxx new file mode 100644 index 0000000000..ac87ba02b6 --- /dev/null +++ b/src/FoundationClasses/TKernel/GTests/NCollection_OccAllocator_Test.cxx @@ -0,0 +1,164 @@ +// Copyright (c) 2025 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + +#include +#include +#include +#include + +#include +#include +#include + +// Test fixture for NCollection_OccAllocator tests +class NCollection_OccAllocatorTest : public testing::Test +{ +protected: + void SetUp() override {} + + void TearDown() override {} +}; + +TEST_F(NCollection_OccAllocatorTest, AllocatorTypeTraits) +{ + // Test type definitions and static assertions (compile-time checks) + typedef Handle(Standard_Transient) anElemType; + typedef NCollection_OccAllocator anAllocatorType; + + // These would fail to compile if the types were wrong + EXPECT_EQ(sizeof(anAllocatorType::value_type), sizeof(anElemType)); + EXPECT_EQ(sizeof(anAllocatorType::pointer), sizeof(void*)); + EXPECT_EQ(sizeof(anAllocatorType::const_pointer), sizeof(void*)); + EXPECT_EQ(sizeof(anAllocatorType::size_type), sizeof(size_t)); + EXPECT_EQ(sizeof(anAllocatorType::difference_type), sizeof(ptrdiff_t)); + + // Test reference types + anElemType aDummy; + anAllocatorType::reference aRef = aDummy; + anAllocatorType::const_reference aConstRef = aDummy; + + // Basic checks that references work + EXPECT_EQ(&aRef, &aDummy); + EXPECT_EQ(&aConstRef, &aDummy); + + // Test rebind functionality + typedef int anOtherElemType; + typedef anAllocatorType::rebind::other anOtherAllocatorType; + EXPECT_EQ(sizeof(anOtherAllocatorType::value_type), sizeof(anOtherElemType)); +} + +TEST_F(NCollection_OccAllocatorTest, STLContainerIntegration) +{ + // Create incremental allocator outside the scope of objects it will manage + Handle(NCollection_IncAllocator) anIncAlloc = new NCollection_IncAllocator(); + + { + // Test with std::list using typed allocator + NCollection_OccAllocator anSAlloc(anIncAlloc); + std::list> aList(anSAlloc); + + aList.push_back(2); + EXPECT_EQ(1, aList.size()); + EXPECT_EQ(2, aList.front()); + + // Test with std::vector using type cast + NCollection_OccAllocator aCAlloc; + std::vector> aVector(aCAlloc); + + aVector.push_back(1); + EXPECT_EQ(1, aVector.size()); + EXPECT_EQ(1, aVector[0]); + + // Test using void-specialization allocator + NCollection_OccAllocator aVAlloc; + std::vector> aVector2(aVAlloc); + + aVector2.resize(10); + aVector2.push_back(-1); + EXPECT_EQ(11, aVector2.size()); + EXPECT_EQ(-1, aVector2.back()); + + // Test equality of allocators + EXPECT_NE(anSAlloc, aCAlloc); // Different underlying allocators + + NCollection_OccAllocator anIAlloc(anIncAlloc); + EXPECT_EQ(anSAlloc, anIAlloc); // Same underlying allocator + } +} + +TEST_F(NCollection_OccAllocatorTest, DefaultAllocator) +{ + // Test default allocator behavior + NCollection_OccAllocator aDefaultAlloc; + std::vector> aVector(aDefaultAlloc); + + // Fill with some data + for (int i = 0; i < 100; ++i) + { + aVector.push_back(i); + } + + EXPECT_EQ(100, aVector.size()); + + // Verify data integrity + for (size_t i = 0; i < aVector.size(); ++i) + { + EXPECT_EQ(static_cast(i), aVector[i]); + } +} + +TEST_F(NCollection_OccAllocatorTest, AllocatorComparison) +{ + Handle(NCollection_IncAllocator) anIncAlloc1 = new NCollection_IncAllocator(); + Handle(NCollection_IncAllocator) anIncAlloc2 = new NCollection_IncAllocator(); + + NCollection_OccAllocator aAlloc1(anIncAlloc1); + NCollection_OccAllocator aAlloc2(anIncAlloc1); // Same underlying allocator + NCollection_OccAllocator aAlloc3(anIncAlloc2); // Different underlying allocator + NCollection_OccAllocator aAlloc4; // Default allocator + + // Test equality + EXPECT_EQ(aAlloc1, aAlloc2); // Same underlying allocator + EXPECT_NE(aAlloc1, aAlloc3); // Different underlying allocator + EXPECT_NE(aAlloc1, aAlloc4); // One uses IncAllocator, one uses default + + // Test inequality + EXPECT_FALSE(aAlloc1 != aAlloc2); // Should be equal + EXPECT_TRUE(aAlloc1 != aAlloc3); // Should be different +} + +TEST_F(NCollection_OccAllocatorTest, CrossTypeCompatibility) +{ + Handle(NCollection_IncAllocator) anIncAlloc = new NCollection_IncAllocator(); + + // Test allocators for different types but same underlying allocator + NCollection_OccAllocator anIntAlloc(anIncAlloc); + NCollection_OccAllocator aDoubleAlloc(anIncAlloc); + NCollection_OccAllocator aCharAlloc(anIncAlloc); + + // They should be considered equal despite different value types + // (This tests the allocator's rebind and comparison logic) + EXPECT_EQ(anIntAlloc, NCollection_OccAllocator(anIncAlloc)); + + // Create containers with different allocators pointing to same IncAllocator + std::vector> anIntVector(anIntAlloc); + std::vector> aDoubleVector(aDoubleAlloc); + + anIntVector.push_back(42); + aDoubleVector.push_back(3.14); + + EXPECT_EQ(1, anIntVector.size()); + EXPECT_EQ(1, aDoubleVector.size()); + EXPECT_EQ(42, anIntVector[0]); + EXPECT_DOUBLE_EQ(3.14, aDoubleVector[0]); +} \ No newline at end of file diff --git a/src/FoundationClasses/TKernel/GTests/NCollection_Sequence_Test.cxx b/src/FoundationClasses/TKernel/GTests/NCollection_Sequence_Test.cxx index ae1383cb67..a09e06a15e 100644 --- a/src/FoundationClasses/TKernel/GTests/NCollection_Sequence_Test.cxx +++ b/src/FoundationClasses/TKernel/GTests/NCollection_Sequence_Test.cxx @@ -16,6 +16,9 @@ #include #include +#include +#include +#include // Basic test type for the Sequence typedef Standard_Integer ItemType; @@ -372,4 +375,68 @@ TEST(NCollection_SequenceTest, MoveOperations) EXPECT_TRUE(aSeq3.IsEmpty()); // Original sequence should be empty after move EXPECT_EQ(aSeq4.Size(), 1); EXPECT_EQ(aSeq4(1), 40); +} + +TEST(NCollection_SequenceTest, STLAlgorithmCompatibility_MinMax) +{ + NCollection_Sequence aSequence; + std::list aStdList; + + std::mt19937 aGenerator(1); // Fixed seed for reproducible tests + std::uniform_int_distribution aDistribution(0, RAND_MAX); + for (Standard_Integer anIdx = 0; anIdx < 100; ++anIdx) + { + Standard_Integer aVal = aDistribution(aGenerator); + aSequence.Append(aVal); + aStdList.push_back(aVal); + } + + auto aMinOCCT = std::min_element(aSequence.begin(), aSequence.end()); + auto aMinStd = std::min_element(aStdList.begin(), aStdList.end()); + + auto aMaxOCCT = std::max_element(aSequence.begin(), aSequence.end()); + auto aMaxStd = std::max_element(aStdList.begin(), aStdList.end()); + + EXPECT_EQ(*aMinOCCT, *aMinStd); + EXPECT_EQ(*aMaxOCCT, *aMaxStd); +} + +TEST(NCollection_SequenceTest, STLAlgorithmCompatibility_Replace) +{ + NCollection_Sequence aSequence; + std::list aStdList; + + std::mt19937 aGenerator(1); // Fixed seed for reproducible tests + std::uniform_int_distribution aDistribution(0, RAND_MAX); + for (Standard_Integer anIdx = 0; anIdx < 100; ++anIdx) + { + Standard_Integer aVal = aDistribution(aGenerator); + aSequence.Append(aVal); + aStdList.push_back(aVal); + } + + Standard_Integer aTargetValue = aStdList.back(); + Standard_Integer aNewValue = -1; + + std::replace(aSequence.begin(), aSequence.end(), aTargetValue, aNewValue); + std::replace(aStdList.begin(), aStdList.end(), aTargetValue, aNewValue); + + EXPECT_TRUE(std::equal(aSequence.begin(), aSequence.end(), aStdList.begin())); +} + +TEST(NCollection_SequenceTest, STLAlgorithmCompatibility_Reverse) +{ + NCollection_Sequence aSequence; + std::list aStdList; + + for (Standard_Integer anIdx = 0; anIdx < 100; ++anIdx) + { + aSequence.Append(anIdx); + aStdList.push_back(anIdx); + } + + std::reverse(aSequence.begin(), aSequence.end()); + std::reverse(aStdList.begin(), aStdList.end()); + + EXPECT_TRUE(std::equal(aSequence.begin(), aSequence.end(), aStdList.begin())); } \ No newline at end of file diff --git a/src/FoundationClasses/TKernel/GTests/NCollection_Vec4_Test.cxx b/src/FoundationClasses/TKernel/GTests/NCollection_Vec4_Test.cxx new file mode 100644 index 0000000000..60d27325f5 --- /dev/null +++ b/src/FoundationClasses/TKernel/GTests/NCollection_Vec4_Test.cxx @@ -0,0 +1,131 @@ +// Copyright (c) 2025 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + +#include +#include +#include + +#include +#include + +// Test fixture for NCollection_Vec4 tests +class NCollection_Vec4Test : public testing::Test +{ +protected: + void SetUp() override {} + + void TearDown() override {} +}; + +TEST_F(NCollection_Vec4Test, BasicConstruction) +{ + // Test default constructor + NCollection_Vec4 aVec1; + EXPECT_EQ(0.0f, aVec1.x()); + EXPECT_EQ(0.0f, aVec1.y()); + EXPECT_EQ(0.0f, aVec1.z()); + EXPECT_EQ(0.0f, aVec1.w()); + + // Test parameterized constructor + NCollection_Vec4 aVec2(1.0f, 2.0f, 3.0f, 4.0f); + EXPECT_EQ(1.0f, aVec2.x()); + EXPECT_EQ(2.0f, aVec2.y()); + EXPECT_EQ(3.0f, aVec2.z()); + EXPECT_EQ(4.0f, aVec2.w()); +} + +TEST_F(NCollection_Vec4Test, XyzMethod) +{ + NCollection_Vec4 aVec(2.0f, 3.0f, 4.0f, 5.0f); + NCollection_Vec3 aVec3 = aVec.xyz(); + + EXPECT_EQ(2.0f, aVec3.x()); + EXPECT_EQ(3.0f, aVec3.y()); + EXPECT_EQ(4.0f, aVec3.z()); +} + +TEST_F(NCollection_Vec4Test, MatrixMultiplicationAndTransformation) +{ + // Test matrix multiplication and xyz() method with translation + NCollection_Mat4 aMatrix; + aMatrix.Translate(NCollection_Vec3(4.0f, 3.0f, 1.0f)); + + // Create a cube of points (-1,-1,-1) to (1,1,1) + NCollection_Vec4 aPoints1[8]; + for (int aX = 0; aX < 2; ++aX) + { + for (int aY = 0; aY < 2; ++aY) + { + for (int aZ = 0; aZ < 2; ++aZ) + { + aPoints1[aX * 2 * 2 + aY * 2 + aZ] = NCollection_Vec4(-1.0f + 2.0f * float(aX), + -1.0f + 2.0f * float(aY), + -1.0f + 2.0f * float(aZ), + 1.0f); + } + } + } + + // Apply transformation and convert to Vec3 + NCollection_Vec3 aPoints2[8]; + for (int aPntIdx = 0; aPntIdx < 8; ++aPntIdx) + { + aPoints1[aPntIdx] = aMatrix * aPoints1[aPntIdx]; + aPoints2[aPntIdx] = aPoints1[aPntIdx].xyz() / aPoints1[aPntIdx].w(); + } + + // Check that the transformation worked correctly + // The last point should be (1,1,1) transformed by translation (4,3,1) -> (5,4,2) + // SquareModulus of (5,4,2) = 25 + 16 + 4 = 45 + float aSquareModulus = aPoints2[7].SquareModulus(); + EXPECT_NEAR(45.0f, aSquareModulus, 0.001f); + + // Check that all points were translated correctly + // Point (0,0,0) -> translate by (4,3,1) -> (4,3,1) + // Point index 0 corresponds to (-1,-1,-1) -> (3,2,0) + float aExpectedSquareMod0 = 3.0f * 3.0f + 2.0f * 2.0f + 0.0f * 0.0f; // 9 + 4 + 0 = 13 + EXPECT_NEAR(aExpectedSquareMod0, aPoints2[0].SquareModulus(), 0.001f); +} + +TEST_F(NCollection_Vec4Test, ComponentAccess) +{ + NCollection_Vec4 aVec(1.5f, 2.5f, 3.5f, 4.5f); + + // Test read access + EXPECT_EQ(1.5f, aVec.x()); + EXPECT_EQ(2.5f, aVec.y()); + EXPECT_EQ(3.5f, aVec.z()); + EXPECT_EQ(4.5f, aVec.w()); + + // Test write access + aVec.x() = 10.0f; + aVec.y() = 20.0f; + aVec.z() = 30.0f; + aVec.w() = 40.0f; + + EXPECT_EQ(10.0f, aVec.x()); + EXPECT_EQ(20.0f, aVec.y()); + EXPECT_EQ(30.0f, aVec.z()); + EXPECT_EQ(40.0f, aVec.w()); +} + +TEST_F(NCollection_Vec4Test, HomogeneousCoordinateDivision) +{ + // Test perspective division using w component + NCollection_Vec4 aVec(8.0f, 12.0f, 16.0f, 4.0f); + NCollection_Vec3 aResult = aVec.xyz() / aVec.w(); + + EXPECT_EQ(2.0f, aResult.x()); // 8/4 = 2 + EXPECT_EQ(3.0f, aResult.y()); // 12/4 = 3 + EXPECT_EQ(4.0f, aResult.z()); // 16/4 = 4 +} \ No newline at end of file diff --git a/src/FoundationClasses/TKernel/GTests/NCollection_Vector_Test.cxx b/src/FoundationClasses/TKernel/GTests/NCollection_Vector_Test.cxx index 65b3796f8e..510315e0f0 100644 --- a/src/FoundationClasses/TKernel/GTests/NCollection_Vector_Test.cxx +++ b/src/FoundationClasses/TKernel/GTests/NCollection_Vector_Test.cxx @@ -16,6 +16,9 @@ #include #include +#include +#include +#include TEST(NCollection_VectorTest, DefaultConstructor) { @@ -379,4 +382,88 @@ TEST(NCollection_VectorTest, SetIncrement) { EXPECT_EQ(i, aVector(i)); } +} + +TEST(NCollection_VectorTest, STLAlgorithmCompatibility_MinMax) +{ + NCollection_Vector aVector; + std::vector aStdVector; + + std::mt19937 aGenerator(1); // Fixed seed for reproducible tests + std::uniform_int_distribution aDistribution(0, RAND_MAX); + for (Standard_Integer anIdx = 0; anIdx < 100; ++anIdx) + { + Standard_Integer aVal = aDistribution(aGenerator); + aVector.Append(aVal); + aStdVector.push_back(aVal); + } + + auto aMinOCCT = std::min_element(aVector.begin(), aVector.end()); + auto aMinStd = std::min_element(aStdVector.begin(), aStdVector.end()); + + auto aMaxOCCT = std::max_element(aVector.begin(), aVector.end()); + auto aMaxStd = std::max_element(aStdVector.begin(), aStdVector.end()); + + EXPECT_EQ(*aMinOCCT, *aMinStd); + EXPECT_EQ(*aMaxOCCT, *aMaxStd); +} + +TEST(NCollection_VectorTest, STLAlgorithmCompatibility_Replace) +{ + NCollection_Vector aVector; + std::vector aStdVector; + + std::mt19937 aGenerator(1); // Fixed seed for reproducible tests + std::uniform_int_distribution aDistribution(0, RAND_MAX); + for (Standard_Integer anIdx = 0; anIdx < 100; ++anIdx) + { + Standard_Integer aVal = aDistribution(aGenerator); + aVector.Append(aVal); + aStdVector.push_back(aVal); + } + + Standard_Integer aTargetValue = aStdVector.back(); + Standard_Integer aNewValue = -1; + + std::replace(aVector.begin(), aVector.end(), aTargetValue, aNewValue); + std::replace(aStdVector.begin(), aStdVector.end(), aTargetValue, aNewValue); + + EXPECT_TRUE(std::equal(aVector.begin(), aVector.end(), aStdVector.begin())); +} + +TEST(NCollection_VectorTest, STLAlgorithmCompatibility_Reverse) +{ + NCollection_Vector aVector; + std::vector aStdVector; + + for (Standard_Integer anIdx = 0; anIdx < 100; ++anIdx) + { + aVector.Append(anIdx); + aStdVector.push_back(anIdx); + } + + std::reverse(aVector.begin(), aVector.end()); + std::reverse(aStdVector.begin(), aStdVector.end()); + + EXPECT_TRUE(std::equal(aVector.begin(), aVector.end(), aStdVector.begin())); +} + +TEST(NCollection_VectorTest, STLAlgorithmCompatibility_Sort) +{ + NCollection_Vector aVector; + std::vector aStdVector; + + std::mt19937 aGenerator(1); // Fixed seed for reproducible tests + std::uniform_int_distribution aDistribution(0, RAND_MAX); + for (Standard_Integer anIdx = 0; anIdx < 100; ++anIdx) + { + Standard_Integer aVal = aDistribution(aGenerator); + aVector.Append(aVal); + aStdVector.push_back(aVal); + } + + std::sort(aVector.begin(), aVector.end()); + std::sort(aStdVector.begin(), aStdVector.end()); + + EXPECT_TRUE(std::equal(aVector.begin(), aVector.end(), aStdVector.begin())); } \ No newline at end of file diff --git a/src/FoundationClasses/TKernel/GTests/OSD_Path_Test.cxx b/src/FoundationClasses/TKernel/GTests/OSD_Path_Test.cxx new file mode 100644 index 0000000000..51c76c5308 --- /dev/null +++ b/src/FoundationClasses/TKernel/GTests/OSD_Path_Test.cxx @@ -0,0 +1,246 @@ +// Copyright (c) 2025 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + +#include +#include + +#include + +// Test fixture for OSD_Path tests +class OSD_PathTest : public testing::Test +{ +protected: + void SetUp() override {} + + void TearDown() override {} +}; + +TEST_F(OSD_PathTest, DosAbsolutePaths) +{ + // Test DOS absolute paths + EXPECT_TRUE(OSD_Path::IsAbsolutePath("c:\\folder\\file.png")); + EXPECT_TRUE(OSD_Path::IsDosPath("c:\\folder\\file.png")); + EXPECT_FALSE(OSD_Path::IsRelativePath("c:\\folder\\file.png")); + EXPECT_FALSE(OSD_Path::IsUnixPath("c:\\folder\\file.png")); + EXPECT_FALSE(OSD_Path::IsUncPath("c:\\folder\\file.png")); + + // Test DOS root + EXPECT_TRUE(OSD_Path::IsAbsolutePath("D:\\")); + EXPECT_TRUE(OSD_Path::IsDosPath("D:\\")); + + // Test single file on DOS drive + EXPECT_TRUE(OSD_Path::IsAbsolutePath("c:\\file.png")); + EXPECT_TRUE(OSD_Path::IsDosPath("c:\\file.png")); +} + +TEST_F(OSD_PathTest, UncPaths) +{ + // Test UNC paths + EXPECT_TRUE(OSD_Path::IsAbsolutePath("\\\\share\\file.pdf")); + EXPECT_TRUE(OSD_Path::IsUncPath("\\\\share\\file.pdf")); + EXPECT_FALSE(OSD_Path::IsDosPath("\\\\share\\file.pdf")); + EXPECT_FALSE(OSD_Path::IsUnixPath("\\\\share\\file.pdf")); +} + +TEST_F(OSD_PathTest, NtExtendedPaths) +{ + // Test NT Extended paths + EXPECT_TRUE(OSD_Path::IsAbsolutePath("\\\\?\\C:\\documents\\file.docx")); + EXPECT_TRUE(OSD_Path::IsNtExtendedPath("\\\\?\\C:\\documents\\file.docx")); + EXPECT_FALSE(OSD_Path::IsUncPath("\\\\?\\C:\\documents\\file.docx")); +} + +TEST_F(OSD_PathTest, UncExtendedPaths) +{ + // Test UNC Extended paths + EXPECT_TRUE(OSD_Path::IsAbsolutePath("\\\\?\\UNC\\server\\share\\file.zip")); + EXPECT_TRUE(OSD_Path::IsUncPath("\\\\?\\UNC\\server\\share\\file.zip")); + EXPECT_TRUE(OSD_Path::IsNtExtendedPath("\\\\?\\UNC\\server\\share\\file.zip")); + EXPECT_TRUE(OSD_Path::IsUncExtendedPath("\\\\?\\UNC\\server\\share\\file.zip")); +} + +TEST_F(OSD_PathTest, RemoteProtocolPaths) +{ + // Test remote protocol paths + EXPECT_TRUE(OSD_Path::IsAbsolutePath("https://www.server.org/file.gif")); + EXPECT_TRUE(OSD_Path::IsRemoteProtocolPath("https://www.server.org/file.gif")); + EXPECT_FALSE(OSD_Path::IsUnixPath("https://www.server.org/file.gif")); + EXPECT_FALSE(OSD_Path::IsDosPath("https://www.server.org/file.gif")); + + // Test other protocols + EXPECT_TRUE(OSD_Path::IsAbsolutePath("ftp://ftp.server.com/file.dat")); + EXPECT_TRUE(OSD_Path::IsRemoteProtocolPath("ftp://ftp.server.com/file.dat")); + + EXPECT_TRUE(OSD_Path::IsAbsolutePath("http://example.com/path")); + EXPECT_TRUE(OSD_Path::IsRemoteProtocolPath("http://example.com/path")); +} + +TEST_F(OSD_PathTest, ContentProtocolPaths) +{ + // Test content protocol paths + EXPECT_TRUE(OSD_Path::IsAbsolutePath("content://file.jpg")); + EXPECT_TRUE(OSD_Path::IsRemoteProtocolPath("content://file.jpg")); + EXPECT_TRUE(OSD_Path::IsContentProtocolPath("content://file.jpg")); +} + +TEST_F(OSD_PathTest, UnixAbsolutePaths) +{ + // Test Unix absolute paths + EXPECT_TRUE(OSD_Path::IsAbsolutePath("/home/username/file.txt")); + EXPECT_TRUE(OSD_Path::IsUnixPath("/home/username/file.txt")); + EXPECT_FALSE(OSD_Path::IsRelativePath("/home/username/file.txt")); + EXPECT_FALSE(OSD_Path::IsDosPath("/home/username/file.txt")); + + // Test Unix root + EXPECT_TRUE(OSD_Path::IsAbsolutePath("/")); + EXPECT_TRUE(OSD_Path::IsUnixPath("/")); + + // Test single file on Unix + EXPECT_TRUE(OSD_Path::IsAbsolutePath("/boot.bin")); + EXPECT_TRUE(OSD_Path::IsUnixPath("/boot.bin")); +} + +TEST_F(OSD_PathTest, RelativePaths) +{ + // Test relative paths with navigation + EXPECT_TRUE(OSD_Path::IsRelativePath("./subfolder/../file.txt")); + EXPECT_FALSE(OSD_Path::IsAbsolutePath("./subfolder/../file.txt")); + + EXPECT_TRUE(OSD_Path::IsRelativePath("../file.txt")); + EXPECT_FALSE(OSD_Path::IsAbsolutePath("../file.txt")); + + // Test current directory + EXPECT_TRUE(OSD_Path::IsRelativePath(".")); + EXPECT_FALSE(OSD_Path::IsAbsolutePath(".")); + + // Test parent directory + EXPECT_TRUE(OSD_Path::IsRelativePath("..")); + EXPECT_FALSE(OSD_Path::IsAbsolutePath("..")); + + // Test simple relative path + EXPECT_TRUE(OSD_Path::IsRelativePath("folder/file.txt")); + EXPECT_FALSE(OSD_Path::IsAbsolutePath("folder/file.txt")); + + // Test simple filename + EXPECT_TRUE(OSD_Path::IsRelativePath("file.txt")); + EXPECT_FALSE(OSD_Path::IsAbsolutePath("file.txt")); +} + +TEST_F(OSD_PathTest, FolderAndFileFromPath_UnixPaths) +{ + TCollection_AsciiString aFolder, aFileName; + + // Test Unix absolute path + OSD_Path::FolderAndFileFromPath("/home/username/file.txt", aFolder, aFileName); + EXPECT_STREQ("/home/username/", aFolder.ToCString()); + EXPECT_STREQ("file.txt", aFileName.ToCString()); + + // Test Unix root file + OSD_Path::FolderAndFileFromPath("/file.txt", aFolder, aFileName); + EXPECT_STREQ("/", aFolder.ToCString()); + EXPECT_STREQ("file.txt", aFileName.ToCString()); + + // Test Unix folder only (trailing slash) + OSD_Path::FolderAndFileFromPath("/home/username/", aFolder, aFileName); + EXPECT_STREQ("/home/username/", aFolder.ToCString()); + EXPECT_STREQ("", aFileName.ToCString()); +} + +TEST_F(OSD_PathTest, FolderAndFileFromPath_DosPaths) +{ + TCollection_AsciiString aFolder, aFileName; + + // Test DOS absolute path + OSD_Path::FolderAndFileFromPath("C:\\Users\\John\\document.txt", aFolder, aFileName); + EXPECT_STREQ("C:\\Users\\John\\", aFolder.ToCString()); + EXPECT_STREQ("document.txt", aFileName.ToCString()); + + // Test DOS root file + OSD_Path::FolderAndFileFromPath("C:\\file.txt", aFolder, aFileName); + EXPECT_STREQ("C:\\", aFolder.ToCString()); + EXPECT_STREQ("file.txt", aFileName.ToCString()); + + // Test DOS folder only (trailing backslash) + OSD_Path::FolderAndFileFromPath("C:\\Program Files\\", aFolder, aFileName); + EXPECT_STREQ("C:\\Program Files\\", aFolder.ToCString()); + EXPECT_STREQ("", aFileName.ToCString()); +} + +TEST_F(OSD_PathTest, FolderAndFileFromPath_RelativePaths) +{ + TCollection_AsciiString aFolder, aFileName; + + // Test relative path + OSD_Path::FolderAndFileFromPath("folder/subfolder/file.txt", aFolder, aFileName); + EXPECT_STREQ("folder/subfolder/", aFolder.ToCString()); + EXPECT_STREQ("file.txt", aFileName.ToCString()); + + // Test relative with navigation + OSD_Path::FolderAndFileFromPath("../folder/file.txt", aFolder, aFileName); + EXPECT_STREQ("../folder/", aFolder.ToCString()); + EXPECT_STREQ("file.txt", aFileName.ToCString()); + + // Test just filename + OSD_Path::FolderAndFileFromPath("file.txt", aFolder, aFileName); + EXPECT_STREQ("", aFolder.ToCString()); + EXPECT_STREQ("file.txt", aFileName.ToCString()); +} + +TEST_F(OSD_PathTest, FolderAndFileFromPath_ProtocolPaths) +{ + TCollection_AsciiString aFolder, aFileName; + + // Test HTTPS path + OSD_Path::FolderAndFileFromPath("https://www.server.org/folder/file.gif", aFolder, aFileName); + EXPECT_STREQ("https://www.server.org/folder/", aFolder.ToCString()); + EXPECT_STREQ("file.gif", aFileName.ToCString()); + + // Test content protocol + OSD_Path::FolderAndFileFromPath("content://path/file.jpg", aFolder, aFileName); + EXPECT_STREQ("content://path/", aFolder.ToCString()); + EXPECT_STREQ("file.jpg", aFileName.ToCString()); +} + +TEST_F(OSD_PathTest, EdgeCases) +{ + TCollection_AsciiString aFolder, aFileName; + + // Test empty path + OSD_Path::FolderAndFileFromPath("", aFolder, aFileName); + EXPECT_STREQ("", aFolder.ToCString()); + EXPECT_STREQ("", aFileName.ToCString()); + + // Test just separator + OSD_Path::FolderAndFileFromPath("/", aFolder, aFileName); + EXPECT_STREQ("/", aFolder.ToCString()); + EXPECT_STREQ("", aFileName.ToCString()); + + OSD_Path::FolderAndFileFromPath("\\", aFolder, aFileName); + EXPECT_STREQ("\\", aFolder.ToCString()); + EXPECT_STREQ("", aFileName.ToCString()); + + // Test path with no file extension + OSD_Path::FolderAndFileFromPath("/home/username/foldername", aFolder, aFileName); + EXPECT_STREQ("/home/username/", aFolder.ToCString()); + EXPECT_STREQ("foldername", aFileName.ToCString()); +} + +TEST_F(OSD_PathTest, MixedSeparators) +{ + TCollection_AsciiString aFolder, aFileName; + + // Test mixed separators (this might happen in cross-platform scenarios) + OSD_Path::FolderAndFileFromPath("C:/Users/John\\Documents/file.txt", aFolder, aFileName); + // The exact behavior might depend on implementation, but it should handle this gracefully + EXPECT_FALSE(aFolder.IsEmpty() || aFileName.IsEmpty()); +} \ No newline at end of file diff --git a/tests/bugs/fclasses/bug23569_1 b/tests/bugs/fclasses/bug23569_1 deleted file mode 100755 index 7944495417..0000000000 --- a/tests/bugs/fclasses/bug23569_1 +++ /dev/null @@ -1,11 +0,0 @@ -puts "=======" -puts "OCC23569" -puts "=======" -puts "" -########################################################################### -## Adding NCollection_StdAllocator -########################################################################### - -pload QAcommands - -QANColStdAllocator1 diff --git a/tests/bugs/fclasses/bug23569_2 b/tests/bugs/fclasses/bug23569_2 deleted file mode 100755 index 26ab741f75..0000000000 --- a/tests/bugs/fclasses/bug23569_2 +++ /dev/null @@ -1,11 +0,0 @@ -puts "=======" -puts "OCC23569" -puts "=======" -puts "" -########################################################################### -## Adding NCollection_StdAllocator -########################################################################### - -pload QAcommands - -QANColStdAllocator2 diff --git a/tests/bugs/fclasses/bug24831 b/tests/bugs/fclasses/bug24831 deleted file mode 100644 index c1269d10b8..0000000000 --- a/tests/bugs/fclasses/bug24831 +++ /dev/null @@ -1,5 +0,0 @@ -puts "TODO ?CR33225 Windows: Failed class " - -pload QAcommands - -QANTestStlIterators diff --git a/tests/collections/grids.list b/tests/collections/grids.list deleted file mode 100755 index f717d11b79..0000000000 --- a/tests/collections/grids.list +++ /dev/null @@ -1 +0,0 @@ -001 n diff --git a/tests/collections/n/array1 b/tests/collections/n/array1 deleted file mode 100644 index 5563982979..0000000000 --- a/tests/collections/n/array1 +++ /dev/null @@ -1,3 +0,0 @@ -puts "Check NCollection_Array1 functionality" - -QANColTestArray1 1 10 diff --git a/tests/collections/n/array2 b/tests/collections/n/array2 deleted file mode 100644 index 15a4c83016..0000000000 --- a/tests/collections/n/array2 +++ /dev/null @@ -1,3 +0,0 @@ -puts "Check NCollection_Array2 functionality" - -QANColTestArray2 1 5 1 3 diff --git a/tests/collections/n/arrayMove b/tests/collections/n/arrayMove deleted file mode 100644 index 7b825433d9..0000000000 --- a/tests/collections/n/arrayMove +++ /dev/null @@ -1,4 +0,0 @@ -puts "Check moving of NCollection_Array1 functionality" - -puts "REQUIRED ALL: Error at item" -QANColTestArrayMove diff --git a/tests/collections/n/begin b/tests/collections/n/begin deleted file mode 100644 index f012867a66..0000000000 --- a/tests/collections/n/begin +++ /dev/null @@ -1 +0,0 @@ -pload QAcommands diff --git a/tests/collections/n/dblmap b/tests/collections/n/dblmap deleted file mode 100644 index 2c139135d4..0000000000 --- a/tests/collections/n/dblmap +++ /dev/null @@ -1,3 +0,0 @@ -puts "Check NCollection_DoubleMap functionality" - -QANColTestDoubleMap diff --git a/tests/collections/n/dmap b/tests/collections/n/dmap deleted file mode 100644 index f08ba4661a..0000000000 --- a/tests/collections/n/dmap +++ /dev/null @@ -1,3 +0,0 @@ -puts "Check NCollection_DataMap functionality" - -QANColTestDataMap diff --git a/tests/collections/n/end b/tests/collections/n/end deleted file mode 100644 index 73b3acd4ea..0000000000 --- a/tests/collections/n/end +++ /dev/null @@ -1 +0,0 @@ -puts "TEST COMPLETED" diff --git a/tests/collections/n/idmap b/tests/collections/n/idmap deleted file mode 100644 index 901c064c67..0000000000 --- a/tests/collections/n/idmap +++ /dev/null @@ -1,3 +0,0 @@ -puts "Check NCollection_IndexedDataMap functionality" - -QANColTestIndexedDataMap diff --git a/tests/collections/n/imap b/tests/collections/n/imap deleted file mode 100644 index 7059f56881..0000000000 --- a/tests/collections/n/imap +++ /dev/null @@ -1,3 +0,0 @@ -puts "Check NCollection_IndexedMap functionality" - -QANColTestIndexedMap diff --git a/tests/collections/n/list b/tests/collections/n/list deleted file mode 100644 index 44f4973e51..0000000000 --- a/tests/collections/n/list +++ /dev/null @@ -1,3 +0,0 @@ -puts "Check NCollection_List functionality" - -QANColTestList diff --git a/tests/collections/n/map b/tests/collections/n/map deleted file mode 100644 index 517a44f719..0000000000 --- a/tests/collections/n/map +++ /dev/null @@ -1,3 +0,0 @@ -puts "Check NCollection_Map functionality" - -QANColTestMap diff --git a/tests/collections/n/osdpath b/tests/collections/n/osdpath deleted file mode 100644 index aaa0445000..0000000000 --- a/tests/collections/n/osdpath +++ /dev/null @@ -1,48 +0,0 @@ -puts "=============" -puts "OSD_Path - test file path parsing tools" -puts "=============" - -pload QAcommands - -if { [QAOsdPathType {c:\folder\file.png}] != "absolute dos " } { puts "Error: DOS path misdetection" } -if { [QAOsdPathType {c:\file.png}] != "absolute dos " } { puts "Error: DOS path misdetection" } -if { [QAOsdPathType "D:\\"] != "absolute dos " } { puts "Error: DOS root misdetection" } -if { [QAOsdPathType {\\share\file.pdf}] != "absolute unc " } { puts "Error: UNC path misdetection" } -if { [QAOsdPathType {\\?\C:\documents\file.docx}] != "absolute ntextended " } { puts "Error: NT Extended path misdetection" } -if { [QAOsdPathType {\\?\UNC\server\share\file.zip}] != "absolute unc ntextended uncextended " } { puts "Error: UNC extended path misdetection" } -if { [QAOsdPathType {https://www.server.org/file.gif}] != "absolute protocol " } { puts "Error: remote protocol path misdetection" } -if { [QAOsdPathType {content://file.jpg}] != "absolute protocol content " } { puts "Error: content protocol path misdetection" } -if { [QAOsdPathType {/home/username/file.txt}] != "absolute unix " } { puts "Error: Unix path misdetection" } -if { [QAOsdPathType {/boot.bin}] != "absolute unix " } { puts "Error: Unix path misdetection" } -if { [QAOsdPathType {/}] != "absolute unix " } { puts "Error: Unix root misdetection" } -if { [QAOsdPathType {./subfolder/../file.txt}] != "relative " } { puts "Error: Relative path misdetection" } -if { [QAOsdPathType {../file.txt}] != "relative " } { puts "Error: Relative path misdetection" } -if { [QAOsdPathType {.}] != "relative " } { puts "Error: Relative path misdetection" } -if { [QAOsdPathType {..}] != "relative " } { puts "Error: Relative path misdetection" } -if { [QAOsdPathType {image.png}] != "relative " } { puts "Error: Relative path misdetection" } - -if { [QAOsdPathPart {image.png} -folder] != "" } { puts "Error: Empty folder misdetected" } -if { [QAOsdPathPart {image.png} -fileName] != "image.png" } { puts "Error: File name misdetected" } -if { [QAOsdPathPart {c:\folder\file.png} -folder] != "c:\\folder\\" } { puts "Error: DOS folder misdetected" } -if { [QAOsdPathPart {c:\folder\file.png} -fileName] != "file.png" } { puts "Error: DOS file name misdetected" } -if { [QAOsdPathPart {c:\file.png} -folder] != "c:\\" } { puts "Error: DOS folder misdetected" } -if { [QAOsdPathPart {c:\file.png} -fileName] != "file.png" } { puts "Error: DOS file name misdetected" } -if { [QAOsdPathPart "D:\\" -folder] != "D:\\" } { puts "Error: DOS root misdetected" } -if { [QAOsdPathPart "D:\\" -fileName] != "" } { puts "Error: DOS root misdetected" } -if { [QAOsdPathPart "/" -folder] != "/" } { puts "Error: Unit root misdetected" } -if { [QAOsdPathPart "/" -fileName] != "" } { puts "Error: Unit root misdetected" } -if { [QAOsdPathPart {subfolder/file.txt} -folder] != "subfolder/" } { puts "Error: Relative folder misdetected" } -if { [QAOsdPathPart {subfolder/file.txt} -fileName] != "file.txt" } { puts "Error: Relative file name misdetected" } -if { [QAOsdPathPart {./subfolder/../file.txt} -folder] != "./subfolder/../" } { puts "Error: Relative folder misdetected" } -if { [QAOsdPathPart {./subfolder/../file.txt} -fileName] != "file.txt" } { puts "Error: Relative file name misdetected" } -if { [QAOsdPathPart {../../file.txt} -folder] != "../../" } { puts "Error: Relative folder misdetected" } -if { [QAOsdPathPart {../../file.txt} -fileName] != "file.txt" } { puts "Error: Relative file name misdetected" } -if { [QAOsdPathPart {/home/username/file.txt} -folder] != "/home/username/" } { puts "Error: Unix folder misdetected" } -if { [QAOsdPathPart {/home/username/file.txt} -fileName] != "file.txt" } { puts "Error: Unix file name misdetected" } - -if { [QAOsdPathPart {content://file.jpg} -folder] != "content://" } { puts "Error: Content folder misdetected" } -if { [QAOsdPathPart {content://file.jpg} -fileName] != "file.jpg" } { puts "Error: Content file name misdetected" } -if { [QAOsdPathPart {ftp://server.org/file.gif} -folder] != "ftp://server.org/" } { puts "Error: Remote protocol folder misdetected" } -if { [QAOsdPathPart {ftp://server.org/file.gif} -fileName] != "file.gif" } { puts "Error: Remote protocol file name misdetected" } -if { [QAOsdPathPart {\\?\UNC\server\file.zip} -folder] != "\\\\?\\UNC\\server\\" } { puts "Error: UNC folder misdetected" } -if { [QAOsdPathPart {\\?\UNC\server\file.zip} -fileName] != "file.zip" } { puts "Error: UNC filename misdetected" } diff --git a/tests/collections/n/seq b/tests/collections/n/seq deleted file mode 100644 index 9db3fd9137..0000000000 --- a/tests/collections/n/seq +++ /dev/null @@ -1,3 +0,0 @@ -puts "Check NCollection_Sequence functionality" - -QANColTestSequence diff --git a/tests/collections/n/vec4 b/tests/collections/n/vec4 deleted file mode 100644 index 42c7f5f59f..0000000000 --- a/tests/collections/n/vec4 +++ /dev/null @@ -1,3 +0,0 @@ -puts "Check NCollection_Vec4 functionality" - -QANColTestVec4 diff --git a/tests/collections/n/vector b/tests/collections/n/vector deleted file mode 100644 index 208fe63434..0000000000 --- a/tests/collections/n/vector +++ /dev/null @@ -1,3 +0,0 @@ -puts "Check NCollection_Vector functionality" - -QANColTestVector diff --git a/tests/perf/fclasses/handle b/tests/perf/fclasses/handle deleted file mode 100644 index 9682ab08c6..0000000000 --- a/tests/perf/fclasses/handle +++ /dev/null @@ -1,14 +0,0 @@ -puts "========" -puts "CR24023, check operability and performance of OCCT RTTI and handles" -puts "========" -puts "" - -pload QAcommands - -# check RTTI -QAHandleBool -QAHandleKind -QAHandleOps - -# check performance of creation and destruction handles, vs. C++ shared_ptr -QAHandleInc diff --git a/tests/perf/fclasses/strtod b/tests/perf/fclasses/strtod deleted file mode 100644 index 71f52cb4cc..0000000000 --- a/tests/perf/fclasses/strtod +++ /dev/null @@ -1,50 +0,0 @@ -puts "=================================================================" -puts "Testing performance of Strtod() vs. standard strtod()" -puts "=================================================================" -puts "" - -puts "TODO ?CR33225 Linux: is expected to be at least " - -pload QAcommands - -# Check that performance of Strtod() and Atof() is at least twice better -# than that of standard strtod() and atof() -proc CheckAtof {nbvalues nbdigits min max} { - set res [QATestAtof $nbvalues $nbdigits $min $max] -# puts $res - - if { ! [regexp {atof\s+([0-9.]+)} $res bidon cpu_atof] || - ! [regexp {Atof\s+([0-9.]+)} $res bidon cpu_Atof] || - ! [regexp {strtod\s+([0-9.]+)} $res bidon cpu_strtod] || - ! [regexp {Strtod\s+([0-9.]+)} $res bidon cpu_Strtod] } { - puts "Error: cannot interpret results of test command!" - } else { - if { $cpu_atof < 1.5 * $cpu_Atof } { - puts "Error: Atof() is expected to be at least 2 times better than atof()!" - } - if { $cpu_strtod < 1.5 * $cpu_Strtod } { - puts "Error: Strtod() is expected to be at least 2 times better than strtod()!" - } - } -} - -puts "1M random values, 10 significant digits, in range (-1e9, 1e9)" -CheckAtof 1000000 10 -1e9 1e9 - -puts "1M random values, 10 significant digits, in range (-1e305, 1e305)" -CheckAtof 1000000 10 -1e305 1e305 - -puts "1M random values, 16 significant digits, in range (-1e9, 1e9)" -CheckAtof 1000000 16 -1e9 1e9 - -puts "1M random values, 18 significant digits, in range (-1e305, 1e305)" -CheckAtof 1000000 16 -1e305 1e305 - -# Disarm FPE signals - otherwise they will be raised if signaling NAN appears -dsetsignal 0 - -puts "Special values + 1M values defined by random binary data, 10 digits" -CheckAtof 1000000 10 0 0 - -puts "Special values + 1M values defined by random binary data, 16 digits" -CheckAtof 1000000 16 0 0 diff --git a/tests/perf/ncollection/A1 b/tests/perf/ncollection/A1 deleted file mode 100644 index 30c30aaccf..0000000000 --- a/tests/perf/ncollection/A1 +++ /dev/null @@ -1,53 +0,0 @@ -cpulimit 1000 -pload QAcommands - -set info [QANTestNCollectionPerformance] - -set values {} -set keys {} -unset -nocomplain std_cl occt_cl diff_cl -foreach line [split $info "\n"] { - if { [regexp {(std::.*)} $line] } { - lappend keys $line - if {[info exists std_cl] && [info exists occt_cl] && [info exists diff_cl]} { - lappend values "$diff_cl" - } - } - regexp {\s*[-0-9*.+eE]+\s+([-0-9*.+eE]+)\s+([-0-9*.+eE]+)\s+([-0-9*.+eE]+)} $line dump std_cl occt_cl diff_cl -} -lappend values "$diff_cl" - -if { [checkplatform -windows] } { - set check_values { 1.5 - 5.2 - 5.7 - 5.7 - 1.7 - 1.3 - 1.6 - 0.4 - 0.4 - } -} else { - set check_values { 1.4 - 5.0 - 1.6 - 7.0 - 1.4 - 1.4 - 1.4 - 0.2 - 0.5 - } -} - -set index 0 -foreach key $keys { - set value [lindex $values $index] - if { $value > [lindex $check_values $index] } { - puts "Error: performance of $key become worse than before" - } else { - puts "OK: performance of $key is within expected limits" - } - incr index -} diff --git a/tests/perf/ncollection/A2 b/tests/perf/ncollection/A2 deleted file mode 100644 index 495baacac4..0000000000 --- a/tests/perf/ncollection/A2 +++ /dev/null @@ -1,41 +0,0 @@ -pload QAcommands - -set info [QANTestNCollectionIndexedMap] - -set keys {} -set values {} -foreach line [split $info "\n"] { - set key [string trim [string range $line 0 [expr {[string first ":" $line] - 1}]]] - set value [string trim [string range $line [expr {[string first ":" $line] + 1}] [expr {[string length $line] - 1}]]] - if {[string length $key] != 0} { - if {[string length $value] != 0} { - lappend keys $key - lappend values $value - } - } -} - -if { [checkplatform -windows] } { - set check_values { 0.018136771 - 0.008694706 - 0.019123649 - 0.784462745 - } -} else { - set check_values { 0.1540285 - 0.1286995 - 0.1607561 - 0.3624441 - } -} - -set index 0 -foreach key $keys { - set value [lindex $values $index] - if { $value > [lindex $check_values $index] } { - puts "Error: performance of $key become worse" - } else { - puts "OK: performance of $key is OK" - } - incr index -} diff --git a/tests/perf/ncollection/A3 b/tests/perf/ncollection/A3 deleted file mode 100644 index 59399b6f64..0000000000 --- a/tests/perf/ncollection/A3 +++ /dev/null @@ -1,41 +0,0 @@ -pload QAcommands - -set info [QANTestNCollectionIndexedDataMap] - -set keys {} -set values {} -foreach line [split $info "\n"] { - set key [string trim [string range $line 0 [expr {[string first ":" $line] - 1}]]] - set value [string trim [string range $line [expr {[string first ":" $line] + 1}] [expr {[string length $line] - 1}]]] - if {[string length $key] != 0} { - if {[string length $value] != 0} { - lappend keys $key - lappend values $value - } - } -} - -if { [checkplatform -windows] } { - set check_values { 0.017762852 - 0.008435507 - 0.018746851 - 0.079263713 - } -} else { - set check_values { 0.1549615 - 0.1290805 - 0.1602191 - 0.3487175 - } -} - -set index 0 -foreach key $keys { - set value [lindex $values $index] - if { $value > [lindex $check_values $index] } { - puts "Error: performance of $key become worse" - } else { - puts "OK: performance of $key is OK" - } - incr index -} -- 2.39.5