1 // Created on: 2002-05-21
2 // Created by: QA Admin
3 // Copyright (c) 2002-2012 OPEN CASCADE SAS
5 // The content of this file is subject to the Open CASCADE Technology Public
6 // License Version 6.5 (the "License"). You may not use the content of this file
7 // except in compliance with the License. Please obtain a copy of the License
8 // at http://www.opencascade.org and read it completely before using this file.
10 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 // The Original Code and all software distributed under the License is
14 // distributed on an "AS IS" basis, without warranty of any kind, and the
15 // Initial Developer hereby disclaims all such warranties, including without
16 // limitation, any warranties of merchantability, fitness for a particular
17 // purpose or non-infringement. Please see the License for the specific terms
18 // and conditions governing the rights and limitations under the License.
23 #include <Draw_Interpretor.hxx>
25 #include <DrawTrSurf.hxx>
26 #include <AIS_InteractiveContext.hxx>
27 #include <ViewerTest.hxx>
28 #include <AIS_Shape.hxx>
29 #include <TopoDS_Shape.hxx>
31 #include <gp_Pnt2d.hxx>
33 #include <GCE2d_MakeSegment.hxx>
34 #include <Geom2d_TrimmedCurve.hxx>
35 #include <DrawTrSurf.hxx>
37 #include <Precision.hxx>
39 #include <PCollection_HAsciiString.hxx>
44 #include <OSD_PerfMeter.hxx>
45 #include <OSD_Timer.hxx>
46 #include <BRepPrimAPI_MakeBox.hxx>
47 #include <BRepPrimAPI_MakeSphere.hxx>
48 #include <BRepAlgo_Cut.hxx>
50 static Standard_Integer OCC230 (Draw_Interpretor& di, Standard_Integer argc, const char ** argv)
53 di << "ERROR OCC230: Usage : " << argv[0] << " TrimmedCurve Pnt2d Pnt2d" << "\n";
58 if ( !DrawTrSurf::GetPoint2d(argv[2],P1)) {
59 di << "ERROR OCC230: " << argv[2] << " is not Pnt2d" << "\n";
62 if ( !DrawTrSurf::GetPoint2d(argv[3],P2)) {
63 di << "ERROR OCC230: " << argv[3] << " is not Pnt2d" << "\n";
67 GCE2d_MakeSegment MakeSegment(P1,P2);
68 Handle(Geom2d_TrimmedCurve) TrimmedCurve = MakeSegment.Value();
69 DrawTrSurf::Set(argv[1], TrimmedCurve);
73 static Standard_Integer OCC142 (Draw_Interpretor& di, Standard_Integer /*argc*/, const char ** /*argv*/)
75 for(Standard_Integer i= 0;i <= 20;i++){
76 Handle(PCollection_HAsciiString) pstr = new PCollection_HAsciiString("TEST");
79 di << "OCC142: OK" << "\n";
83 static Standard_Integer OCC23361 (Draw_Interpretor& di, Standard_Integer /*argc*/, const char ** /*argv*/)
88 t1.SetRotation(gp_Ax1(p, gp_Dir(0, 1, 0)), -0.49328285294022267);
89 t2.SetRotation(gp_Ax1(p, gp_Dir(0, 0, 1)), 0.87538474718473880);
91 gp_Trsf tComp = t2 * t1;
94 gp_Pnt p2 = p1.Transformed(tComp);
95 gp_Pnt p3 = p1.Transformed(t1);
98 // points must be equal
99 if ( ! p2.IsEqual(p3, Precision::Confusion()) )
100 di << "ERROR OCC23361: equivalent transformations does not produce equal points" << "\n";
102 di << "OCC23361: OK" << "\n";
107 static Standard_Integer OCC23237 (Draw_Interpretor& di, Standard_Integer /*argc*/, const char** /*argv*/)
109 OSD_PerfMeter aPM("TestMeter",0);
112 // run some operation in cycle for about 2 seconds to have good values of times to compare
114 printf("OSD_PerfMeter test.\nRunning Boolean operation on solids in loop.\n");
115 for (; aTM.ElapsedTime() < 2.; count++)
120 // do some operation that will take considerable time compared with time or starting / stopping timers
121 BRepPrimAPI_MakeBox aBox (10., 10., 10.);
122 BRepPrimAPI_MakeSphere aSphere (10.);
123 BRepAlgo_Cut (aBox.Shape(), aSphere.Shape());
130 Standard_Real aPerfMeter_CPUtime = 0., aTimer_ElapsedTime = aTM.ElapsedTime();
132 perf_get_meter("TestMeter", &aNbEnters, &aPerfMeter_CPUtime);
134 Standard_Real aTimeDiff = (fabs(aTimer_ElapsedTime - aPerfMeter_CPUtime) / aTimer_ElapsedTime);
136 printf("\nMeasurement results (%d cycles):\n", count);
137 printf("\nOSD_PerfMeter CPU time: %lf\nOSD_Timer elapsed time: %lf\n", aPerfMeter_CPUtime, aTimer_ElapsedTime);
138 printf("Time delta is: %.3lf %%\n", aTimeDiff * 100);
141 di << "OCC23237: Error: too much difference between CPU and elapsed times";
142 else if (aNbEnters != count)
143 di << "OCC23237: Error: counter reported by PerfMeter (" << aNbEnters << ") does not correspond to actual number of cycles";
145 di << "OCC23237: OK";
152 #include <Standard_Atomic.hxx>
153 #include <tbb/blocked_range.h>
154 #include <tbb/parallel_for.h>
156 class IncrementerDecrementer
159 IncrementerDecrementer (Standard_Integer* theVal, Standard_Boolean thePositive) : myVal (theVal), myPositive (thePositive)
161 void operator() (const tbb::blocked_range<size_t>& r) const
164 for (size_t i = r.begin(); i != r.end(); ++i)
165 Standard_Atomic_Increment (myVal);
167 for (size_t i = r.begin(); i != r.end(); ++i)
168 Standard_Atomic_Decrement (myVal);
171 Standard_Integer* myVal;
172 Standard_Boolean myPositive;
176 #define QCOMPARE(val1, val2) \
177 di << "Checking " #val1 " == " #val2 << \
178 ((val1) == (val2) ? ": OK\n" : ": Error\n")
181 static Standard_Integer OCC22980 (Draw_Interpretor& di, Standard_Integer /*argc*/, const char ** /*argv*/)
185 //check returned value
186 QCOMPARE (Standard_Atomic_Decrement (&aSum), -1);
187 QCOMPARE (Standard_Atomic_Increment (&aSum), 0);
188 QCOMPARE (Standard_Atomic_Increment (&aSum), 1);
189 QCOMPARE (Standard_Atomic_Increment (&aSum), 2);
190 // QCOMPARE (Standard_Atomic_DecrementTest (&aSum), 0);
191 // QCOMPARE (Standard_Atomic_DecrementTest (&aSum), 1);
195 const int N = 1 << 24; //big enough to ensure concurrency
198 tbb::parallel_for (tbb::blocked_range<size_t> (0, N), IncrementerDecrementer (&aSum, true));
202 tbb::parallel_for (tbb::blocked_range<size_t> (0, N), IncrementerDecrementer (&aSum, false));
210 static Standard_Integer OCC22980 (Draw_Interpretor& di, Standard_Integer /*argc*/, const char **argv)
212 di << "Test skipped: command " << argv[0] << " requires TBB library\n";
216 #endif /* HAVE_TBB */
218 #include <TDocStd_Application.hxx>
219 #include <XCAFApp_Application.hxx>
220 #include <TDocStd_Document.hxx>
221 #include <XCAFDoc_ShapeTool.hxx>
222 #include <XCAFDoc_DocumentTool.hxx>
223 #include <TDF_Label.hxx>
224 #include <TDataStd_Name.hxx>
226 static Standard_Integer OCC23595 (Draw_Interpretor& di, Standard_Integer /*argc*/, const char **argv)
228 const Handle(TDocStd_Application)& anApp = XCAFApp_Application::GetApplication();
229 Handle(TDocStd_Document) aDoc;
230 anApp->NewDocument ("XmlXCAF", aDoc);
231 QCOMPARE (!aDoc.IsNull(), Standard_True);
233 Handle(XCAFDoc_ShapeTool) aShTool = XCAFDoc_DocumentTool::ShapeTool (aDoc->Main());
235 //check default value
236 Standard_Boolean aValue = XCAFDoc_ShapeTool::AutoNaming();
237 QCOMPARE (aValue, Standard_True);
240 XCAFDoc_ShapeTool::SetAutoNaming (Standard_True);
241 TopoDS_Shape aShape = BRepPrimAPI_MakeBox (100., 200., 300.).Shape();
242 TDF_Label aLabel = aShTool->AddShape (aShape);
243 Handle(TDataStd_Name) anAttr;
244 QCOMPARE (aLabel.FindAttribute (TDataStd_Name::GetID(), anAttr), Standard_True);
247 XCAFDoc_ShapeTool::SetAutoNaming (Standard_False);
248 aShape = BRepPrimAPI_MakeBox (300., 200., 100.).Shape();
249 aLabel = aShTool->AddShape (aShape);
250 QCOMPARE (!aLabel.FindAttribute (TDataStd_Name::GetID(), anAttr), Standard_True);
253 XCAFDoc_ShapeTool::SetAutoNaming (aValue);
258 void QABugs::Commands_19(Draw_Interpretor& theCommands) {
259 const char *group = "QABugs";
261 theCommands.Add ("OCC230", "OCC230 TrimmedCurve Pnt2d Pnt2d", __FILE__, OCC230, group);
262 theCommands.Add ("OCC142", "OCC142", __FILE__, OCC142, group);
263 theCommands.Add ("OCC23361", "OCC23361", __FILE__, OCC23361, group);
264 theCommands.Add ("OCC23237", "OCC23237", __FILE__, OCC23237, group);
265 theCommands.Add ("OCC22980", "OCC22980", __FILE__, OCC22980, group);
266 theCommands.Add ("OCC23595", "OCC23595", __FILE__, OCC23595, group);