File size: 5,079 Bytes
985c397 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 | // SPDX-License-Identifier: LGPL-2.1-or-later
#include <gtest/gtest.h>
#include "Mod/Part/App/FuzzyHelper.h"
#include "Mod/Part/App/FeaturePartImportBrep.h"
#include <src/App/InitApplication.h>
#include <BRepBuilderAPI_Copy.hxx>
#include <BOPAlgo_ArgumentAnalyzer.hxx>
#include "PartTestHelpers.h"
class FuzzyBooleanTest: public ::testing::Test, public PartTestHelpers::PartTestHelperClass
{
protected:
static void SetUpTestSuite()
{
tests::initApplication();
}
void SetUp() override
{
createTestDoc();
std::string testPath = App::Application::getHomePath() + "/tests/brepfiles/";
_fuse = _doc->addObject<Part::Fuse>();
_cylinder1 = _doc->addObject<Part::ImportBrep>();
_cylinder1->FileName.setValue(testPath + "cylinder1.brep");
_helix1 = _doc->addObject<Part::ImportBrep>();
_helix1->FileName.setValue(testPath + "helix1.brep");
// Load
_cylinder1->execute();
_helix1->execute();
// Arrange
_fuse->Base.setValue(_cylinder1);
_fuse->Tool.setValue(_helix1);
}
void TearDown() override
{}
Part::Fuse* _fuse = nullptr; // NOLINT Can't be private in a test framework
Part::ImportBrep* _cylinder1 = nullptr; // NOLINT Can't be private in a test framework
Part::ImportBrep* _helix1 = nullptr; // NOLINT Can't be private in a test framework
};
TEST_F(FuzzyBooleanTest, testLoadedCorrectly)
{
EXPECT_NEAR(PartTestHelpers::getVolume(_cylinder1->Shape.getValue()), 125.6, 1.0);
EXPECT_NEAR(PartTestHelpers::getVolume(_helix1->Shape.getValue()), 33.32, 1.0);
}
TEST_F(FuzzyBooleanTest, testDefaultFuzzy)
{
// Act
_fuse->execute();
// Verify
EXPECT_NEAR(
PartTestHelpers::getVolume(_fuse->Shape.getValue()),
PartTestHelpers::getVolume(_helix1->Shape.getValue())
+ PartTestHelpers::getVolume(_cylinder1->Shape.getValue()),
0.1
);
// Analyse
Part::TopoShape ts = _fuse->Shape.getValue();
ASSERT_FALSE(ts.isNull());
TopoDS_Shape BOPCopy = BRepBuilderAPI_Copy(ts.getShape()).Shape();
BOPAlgo_ArgumentAnalyzer BOPCheck;
BOPCheck.SetShape1(BOPCopy);
BOPCheck.SelfInterMode() = Standard_True;
BOPCheck.Perform();
// Assert
EXPECT_FALSE(BOPCheck.HasFaulty());
}
TEST_F(FuzzyBooleanTest, testGoodFuzzy)
{
// Act
double oldFuzzy = Part::FuzzyHelper::getBooleanFuzzy();
Part::FuzzyHelper::setBooleanFuzzy(10.0);
_fuse->execute();
EXPECT_FLOAT_EQ(Part::FuzzyHelper::getBooleanFuzzy(), 10.0);
Part::FuzzyHelper::setBooleanFuzzy(oldFuzzy);
// Verify
EXPECT_NEAR(
PartTestHelpers::getVolume(_fuse->Shape.getValue()),
PartTestHelpers::getVolume(_helix1->Shape.getValue())
+ PartTestHelpers::getVolume(_cylinder1->Shape.getValue()),
0.1
);
// Analyse
Part::TopoShape ts = _fuse->Shape.getValue();
ASSERT_FALSE(ts.isNull());
TopoDS_Shape BOPCopy = BRepBuilderAPI_Copy(ts.getShape()).Shape();
BOPAlgo_ArgumentAnalyzer BOPCheck;
BOPCheck.SetShape1(BOPCopy);
BOPCheck.SelfInterMode() = Standard_True;
BOPCheck.Perform();
// Assert
int result = BOPCheck.HasFaulty();
EXPECT_FALSE(result);
}
TEST_F(FuzzyBooleanTest, testFailsTooSmallFuzzy)
{
// Act
double oldFuzzy = Part::FuzzyHelper::getBooleanFuzzy();
Part::FuzzyHelper::setBooleanFuzzy(0.01);
_fuse->execute();
EXPECT_DOUBLE_EQ(Part::FuzzyHelper::getBooleanFuzzy(), 0.01);
Part::FuzzyHelper::setBooleanFuzzy(oldFuzzy);
// Verify
// EXPECT_NEAR(PartTestHelpers::getVolume(_fuse->Shape.getValue()),PartTestHelpers::getVolume(_helix1->Shape.getValue())+PartTestHelpers::getVolume(_cylinder1->Shape.getValue()),0.1);
// // fails on OCCT 7.3 - ignore
// Analyse
Part::TopoShape ts = _fuse->Shape.getValue();
ASSERT_FALSE(ts.isNull());
TopoDS_Shape BOPCopy = BRepBuilderAPI_Copy(ts.getShape()).Shape();
BOPAlgo_ArgumentAnalyzer BOPCheck;
BOPCheck.SetShape1(BOPCopy);
BOPCheck.SelfInterMode() = Standard_True;
BOPCheck.Perform();
// Assert
int result = BOPCheck.HasFaulty();
EXPECT_TRUE(result);
}
TEST_F(FuzzyBooleanTest, testCompletelyFailsTooBigFuzzy)
{
// Act
double oldFuzzy = Part::FuzzyHelper::getBooleanFuzzy();
Part::FuzzyHelper::setBooleanFuzzy(1e10);
int failed = 0;
Part::TopoShape ts;
try {
_fuse->execute();
ts = _fuse->Shape.getValue();
if (ts.isNull()) {
failed = 1;
}
else {
TopoDS_Shape BOPCopy = BRepBuilderAPI_Copy(ts.getShape()).Shape();
BOPAlgo_ArgumentAnalyzer BOPCheck;
BOPCheck.SetShape1(BOPCopy);
BOPCheck.SelfInterMode() = Standard_True;
BOPCheck.Perform();
// Assert
if (BOPCheck.HasFaulty()) {
failed = 1;
}
}
}
catch (...) {
failed = 1;
}
Part::FuzzyHelper::setBooleanFuzzy(oldFuzzy);
EXPECT_EQ(failed, 1);
}
|