From 323ddeaed96f1be1a1071a7facc924085cd65d39 Mon Sep 17 00:00:00 2001 From: mpv Date: Fri, 20 May 2016 16:12:26 +0300 Subject: [PATCH] Some minor changes in tests. Now the initialization plugin performs correctly in the unit tests also. --- src/ConstructionPlugin/Test/TestPointName.py | 3 +- src/FeaturesPlugin/Test/TestGroup.py | 1 + src/Model/Model_AttributeIntArray.cpp | 2 +- src/Model/Model_BodyBuilder.cpp | 1 - src/Model/Model_Session.cpp | 2 ++ src/ModelAPI/CMakeLists.txt | 3 +- src/ModelAPI/Test/TestResults.py | 36 +++++++++++++++++++ src/ModelAPI/Test/TestUndoRedo.py | 9 ++--- .../SketchPlugin_SketchEntity.cpp | 1 - 9 files changed, 49 insertions(+), 9 deletions(-) create mode 100755 src/ModelAPI/Test/TestResults.py diff --git a/src/ConstructionPlugin/Test/TestPointName.py b/src/ConstructionPlugin/Test/TestPointName.py index df76871f2..43a942db0 100644 --- a/src/ConstructionPlugin/Test/TestPointName.py +++ b/src/ConstructionPlugin/Test/TestPointName.py @@ -14,7 +14,8 @@ aFeatureName = aFeature.name() aFeature.execute() aSession.finishOperation() -aFeature1 = aDoc.object("Construction", 0) +# with index "0" is Origin and then - all default constructions +aFeature1 = aDoc.object("Construction", 7) aFeature1Name = aFeature1.data().name() assert (aFeatureName == aFeature1Name) diff --git a/src/FeaturesPlugin/Test/TestGroup.py b/src/FeaturesPlugin/Test/TestGroup.py index 382c02416..a2ca95ef1 100644 --- a/src/FeaturesPlugin/Test/TestGroup.py +++ b/src/FeaturesPlugin/Test/TestGroup.py @@ -238,6 +238,7 @@ assert(aSelectionListAttr.size() == 1) assert(len(aGroupFeature.results()) > 0) aGroupResult = aGroupFeature.firstResult() assert(aGroupResult) +assert(aGroupResult.shape()) #========================================================================= # End of test #========================================================================= diff --git a/src/Model/Model_AttributeIntArray.cpp b/src/Model/Model_AttributeIntArray.cpp index b9cb85876..c01107332 100644 --- a/src/Model/Model_AttributeIntArray.cpp +++ b/src/Model/Model_AttributeIntArray.cpp @@ -34,7 +34,7 @@ void Model_AttributeIntArray::setSize(const int theSize) { if (myArray.IsNull() || !myArray->IsValid()) { // create array if it is not done yet if (theSize != 0) { // if size is zero, nothing to do (null array means there is no array) - myArray = TDataStd_IntegerArray::Set(myLab, 0, theSize); + myArray = TDataStd_IntegerArray::Set(myLab, 0, theSize - 1); owner()->data()->sendAttributeUpdated(this); } } else { // reset the old array diff --git a/src/Model/Model_BodyBuilder.cpp b/src/Model/Model_BodyBuilder.cpp index f84c169b2..2d025aa88 100755 --- a/src/Model/Model_BodyBuilder.cpp +++ b/src/Model/Model_BodyBuilder.cpp @@ -8,7 +8,6 @@ #include #include -#include #include #include #include diff --git a/src/Model/Model_Session.cpp b/src/Model/Model_Session.cpp index 4525cbf4a..886bfec9f 100644 --- a/src/Model/Model_Session.cpp +++ b/src/Model/Model_Session.cpp @@ -189,6 +189,8 @@ std::shared_ptr Model_Session::moduleDocument() Handle(Model_Application) anApp = Model_Application::getApplication(); bool aFirstCall = !anApp->hasRoot(); if (aFirstCall) { + // to be sure that plugins are loaded, even before the first "createFeature" call (in unit tests) + LoadPluginsInfo(); // creation of the root document is always outside of the transaction, so, avoid checking it setCheckTransactions(false); anApp->createDocument(0); // 0 is a root ID diff --git a/src/ModelAPI/CMakeLists.txt b/src/ModelAPI/CMakeLists.txt index fb4db8b55..90006d1d0 100644 --- a/src/ModelAPI/CMakeLists.txt +++ b/src/ModelAPI/CMakeLists.txt @@ -127,4 +127,5 @@ INSTALL(FILES ${SWIG_SCRIPTS} DESTINATION ${SHAPER_INSTALL_SWIG}) ADD_UNIT_TESTS(TestConstants.py TestUndoRedo.py TestDocument.py - Test1064.py) + Test1064.py + TestResults.py) diff --git a/src/ModelAPI/Test/TestResults.py b/src/ModelAPI/Test/TestResults.py new file mode 100755 index 000000000..7ba9cb5ea --- /dev/null +++ b/src/ModelAPI/Test/TestResults.py @@ -0,0 +1,36 @@ +""" + TestResults.py + Cover specific working with the data model results + +""" +#========================================================================= +# Initialization of the test +#========================================================================= +from ModelAPI import * + +__updated__ = "2016-20-16" + +aSession = ModelAPI_Session.get() + +#========================================================================= +# Check getting the initial construction plane by name +#========================================================================= +aPartSet = aSession.moduleDocument() +aSession.startOperation() +aPlaneX = aPartSet.objectByName("Construction", "YOZ"); +assert(aPlaneX) +aColors = aPlaneX.data().intArray("Color") +assert(aColors) +# default colors, not filled array +assert(aColors.size() == 0) +aColors.setSize(3) +aColors.setValue(0, 100) +aColors.setValue(1, 200) +aColors.setValue(2, 250) +assert(aColors.size() == 3) +assert(aColors.value(0) == 100) +assert(aColors.value(1) == 200) +assert(aColors.value(2) == 250) + +aSession.finishOperation() + diff --git a/src/ModelAPI/Test/TestUndoRedo.py b/src/ModelAPI/Test/TestUndoRedo.py index 26f54acb5..1df119f97 100644 --- a/src/ModelAPI/Test/TestUndoRedo.py +++ b/src/ModelAPI/Test/TestUndoRedo.py @@ -12,21 +12,22 @@ aFeature.real("x").setValue(1.) aFeature.real("y").setValue(-1.) aFeature.real("z").setValue(0.) aFeatureName = aFeature.name() -assert(aFeatureName == "Point_1") +# "2" is because Origin is the first point +assert(aFeatureName == "Point_2") aFeature.execute() aSession.finishOperation() -assert(aDoc.size("Construction") == 1) +assert(aDoc.size("Construction") == 8) assert(aSession.canUndo()) assert(not aSession.canRedo()) aSession.undo() -assert(aDoc.size("Construction") == 0) +assert(aDoc.size("Construction") == 7) assert(not aSession.canUndo()) assert(aSession.canRedo()) aSession.redo() -assert(aDoc.size("Construction") == 1) +assert(aDoc.size("Construction") == 8) assert(aSession.canUndo()) assert(not aSession.canRedo()) diff --git a/src/SketchPlugin/SketchPlugin_SketchEntity.cpp b/src/SketchPlugin/SketchPlugin_SketchEntity.cpp index 3d26d3d95..6b5beb942 100644 --- a/src/SketchPlugin/SketchPlugin_SketchEntity.cpp +++ b/src/SketchPlugin/SketchPlugin_SketchEntity.cpp @@ -4,7 +4,6 @@ #include #include -#include SketchPlugin_SketchEntity::SketchPlugin_SketchEntity() : SketchPlugin_Feature() -- 2.39.2