|
| 1 | +#include <gtest/gtest.h> |
| 2 | + |
| 3 | +#include <Standard_Transient.hxx> |
| 4 | +#include <StepBasic_MeasureWithUnit.hxx> |
| 5 | +#include <StepRepr_ReprItemAndMeasureWithUnit.hxx> |
| 6 | + |
| 7 | +#include <StepBasic_ConversionBasedUnit.hxx> |
| 8 | +#include <StepBasic_DimensionalExponents.hxx> |
| 9 | +#include <StepBasic_SiUnit.hxx> |
| 10 | +#include <StepBasic_MeasureValueMember.hxx> |
| 11 | +#include <StepBasic_SiPrefix.hxx> |
| 12 | +#include <StepBasic_SiUnitName.hxx> |
| 13 | + |
| 14 | +#include <StepDimTol_GeometricTolerance.hxx> |
| 15 | +#include <StepRepr_MakeFromUsageOption.hxx> |
| 16 | +#include <StepRepr_ParallelOffset.hxx> |
| 17 | +#include <StepRepr_QuantifiedAssemblyComponentUsage.hxx> |
| 18 | +#include <StepShape_MeasureQualification.hxx> |
| 19 | +#include <StepData_Logical.hxx> |
| 20 | +#include <StepRepr_ProductDefinitionShape.hxx> |
| 21 | +#include <StepBasic_ProductDefinition.hxx> |
| 22 | +#include <StepDimTol_GeometricToleranceTarget.hxx> |
| 23 | +#include <StepShape_HArray1OfValueQualifier.hxx> |
| 24 | + |
| 25 | +#include <TCollection_HAsciiString.hxx> |
| 26 | + |
| 27 | +// Helper functions to create test objects |
| 28 | +namespace |
| 29 | +{ |
| 30 | + |
| 31 | +// Create a MeasureWithUnit |
| 32 | +Handle(StepBasic_MeasureWithUnit) CreateMeasureWithUnit(const Standard_Real theValue) |
| 33 | +{ |
| 34 | + Handle(StepBasic_MeasureWithUnit) aMeasure = new StepBasic_MeasureWithUnit(); |
| 35 | + |
| 36 | + // Set value component |
| 37 | + Handle(StepBasic_MeasureValueMember) aValueMember = new StepBasic_MeasureValueMember(); |
| 38 | + aValueMember->SetName("POSITIVE_LENGTH_MEASURE"); |
| 39 | + aValueMember->SetReal(theValue); |
| 40 | + aMeasure->SetValueComponentMember(aValueMember); |
| 41 | + |
| 42 | + // Create a dummy SiUnit for unit component |
| 43 | + Handle(StepBasic_SiUnit) aSiUnit = new StepBasic_SiUnit(); |
| 44 | + aSiUnit->Init(Standard_False, |
| 45 | + StepBasic_SiPrefix::StepBasic_spMilli, |
| 46 | + StepBasic_SiUnitName::StepBasic_sunMetre); |
| 47 | + StepBasic_Unit aUnit; |
| 48 | + aUnit.SetValue(aSiUnit); |
| 49 | + aMeasure->SetUnitComponent(aUnit); |
| 50 | + |
| 51 | + return aMeasure; |
| 52 | +} |
| 53 | + |
| 54 | +// Create a ReprItemAndMeasureWithUnit |
| 55 | +Handle(StepRepr_ReprItemAndMeasureWithUnit) CreateReprItemAndMeasureWithUnit( |
| 56 | + const Standard_Real theValue) |
| 57 | +{ |
| 58 | + Handle(StepRepr_ReprItemAndMeasureWithUnit) aReprMeasure = |
| 59 | + new StepRepr_ReprItemAndMeasureWithUnit(); |
| 60 | + Handle(StepBasic_MeasureWithUnit) aMeasure = CreateMeasureWithUnit(theValue); |
| 61 | + aReprMeasure->SetMeasureWithUnit(aMeasure); |
| 62 | + |
| 63 | + // Set other required fields |
| 64 | + Handle(TCollection_HAsciiString) aName = new TCollection_HAsciiString("TestReprItem"); |
| 65 | + aReprMeasure->SetName(aName); |
| 66 | + |
| 67 | + return aReprMeasure; |
| 68 | +} |
| 69 | +} // namespace |
| 70 | + |
| 71 | +// Test fixture for all transient replacement tests |
| 72 | +class StepTransientReplacements : public ::testing::Test |
| 73 | +{ |
| 74 | +protected: |
| 75 | + void SetUp() override |
| 76 | + { |
| 77 | + // Create common test objects |
| 78 | + myMeasureWithUnit = CreateMeasureWithUnit(5.0); |
| 79 | + myReprItemAndMeasureWithUnit = CreateReprItemAndMeasureWithUnit(10.0); |
| 80 | + |
| 81 | + // Create dimensional exponents |
| 82 | + myDimensionalExponents = new StepBasic_DimensionalExponents(); |
| 83 | + myDimensionalExponents->Init(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0); |
| 84 | + |
| 85 | + // Create name string |
| 86 | + myName = new TCollection_HAsciiString("TestName"); |
| 87 | + |
| 88 | + // Create description string |
| 89 | + myDescription = new TCollection_HAsciiString("TestDescription"); |
| 90 | + |
| 91 | + // Create product definition |
| 92 | + myProductDefinition = new StepBasic_ProductDefinition(); |
| 93 | + |
| 94 | + // Create product definition shape |
| 95 | + myProductDefinitionShape = new StepRepr_ProductDefinitionShape(); |
| 96 | + |
| 97 | + // Create qualifiers array |
| 98 | + myQualifiers = new StepShape_HArray1OfValueQualifier(1, 1); |
| 99 | + } |
| 100 | + |
| 101 | + // Common test objects |
| 102 | + Handle(StepBasic_MeasureWithUnit) myMeasureWithUnit; |
| 103 | + Handle(StepRepr_ReprItemAndMeasureWithUnit) myReprItemAndMeasureWithUnit; |
| 104 | + Handle(StepBasic_DimensionalExponents) myDimensionalExponents; |
| 105 | + Handle(TCollection_HAsciiString) myName; |
| 106 | + Handle(TCollection_HAsciiString) myDescription; |
| 107 | + Handle(StepBasic_ProductDefinition) myProductDefinition; |
| 108 | + Handle(StepRepr_ProductDefinitionShape) myProductDefinitionShape; |
| 109 | + Handle(StepShape_HArray1OfValueQualifier) myQualifiers; |
| 110 | +}; |
| 111 | + |
| 112 | +// Test ConversionBasedUnit with different transient types |
| 113 | +TEST_F(StepTransientReplacements, ConversionBasedUnit_WorksWithBothTypes) |
| 114 | +{ |
| 115 | + // Create ConversionBasedUnit |
| 116 | + Handle(StepBasic_ConversionBasedUnit) aUnit = new StepBasic_ConversionBasedUnit(); |
| 117 | + |
| 118 | + // Test with MeasureWithUnit |
| 119 | + aUnit->Init(myDimensionalExponents, myName, myMeasureWithUnit); |
| 120 | + EXPECT_FALSE(aUnit->ConversionFactor().IsNull()); |
| 121 | + EXPECT_TRUE(aUnit->ConversionFactor()->IsKind(STANDARD_TYPE(StepBasic_MeasureWithUnit))); |
| 122 | + |
| 123 | + Handle(StepBasic_MeasureWithUnit) aMeasure = |
| 124 | + Handle(StepBasic_MeasureWithUnit)::DownCast(aUnit->ConversionFactor()); |
| 125 | + EXPECT_FALSE(aMeasure.IsNull()); |
| 126 | + EXPECT_NEAR(aMeasure->ValueComponent(), 5.0, 1e-7); |
| 127 | + |
| 128 | + // Test with ReprItemAndMeasureWithUnit |
| 129 | + aUnit->SetConversionFactor(myReprItemAndMeasureWithUnit); |
| 130 | + EXPECT_FALSE(aUnit->ConversionFactor().IsNull()); |
| 131 | + EXPECT_TRUE( |
| 132 | + aUnit->ConversionFactor()->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndMeasureWithUnit))); |
| 133 | + |
| 134 | + Handle(StepRepr_ReprItemAndMeasureWithUnit) aReprMeasure = |
| 135 | + Handle(StepRepr_ReprItemAndMeasureWithUnit)::DownCast(aUnit->ConversionFactor()); |
| 136 | + EXPECT_FALSE(aReprMeasure.IsNull()); |
| 137 | + Handle(StepBasic_MeasureWithUnit) aExtractedMeasure = aReprMeasure->GetMeasureWithUnit(); |
| 138 | + EXPECT_NEAR(aExtractedMeasure->ValueComponent(), 10.0, 1e-7); |
| 139 | +} |
| 140 | + |
| 141 | +// Test GeometricTolerance with different transient types |
| 142 | +TEST_F(StepTransientReplacements, GeometricTolerance_WorksWithBothTypes) |
| 143 | +{ |
| 144 | + // Create GeometricTolerance |
| 145 | + Handle(StepDimTol_GeometricTolerance) aTolerance = new StepDimTol_GeometricTolerance(); |
| 146 | + |
| 147 | + // Create a dummy tolerance target |
| 148 | + StepDimTol_GeometricToleranceTarget aTarget; |
| 149 | + |
| 150 | + // Test with MeasureWithUnit |
| 151 | + aTolerance->Init(myName, myDescription, myMeasureWithUnit, aTarget); |
| 152 | + EXPECT_FALSE(aTolerance->Magnitude().IsNull()); |
| 153 | + EXPECT_TRUE(aTolerance->Magnitude()->IsKind(STANDARD_TYPE(StepBasic_MeasureWithUnit))); |
| 154 | + |
| 155 | + Handle(StepBasic_MeasureWithUnit) aMeasure = |
| 156 | + Handle(StepBasic_MeasureWithUnit)::DownCast(aTolerance->Magnitude()); |
| 157 | + EXPECT_FALSE(aMeasure.IsNull()); |
| 158 | + EXPECT_NEAR(aMeasure->ValueComponent(), 5.0, 1e-7); |
| 159 | + |
| 160 | + // Test with ReprItemAndMeasureWithUnit |
| 161 | + aTolerance->SetMagnitude(myReprItemAndMeasureWithUnit); |
| 162 | + EXPECT_FALSE(aTolerance->Magnitude().IsNull()); |
| 163 | + EXPECT_TRUE(aTolerance->Magnitude()->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndMeasureWithUnit))); |
| 164 | + |
| 165 | + Handle(StepRepr_ReprItemAndMeasureWithUnit) aReprMeasure = |
| 166 | + Handle(StepRepr_ReprItemAndMeasureWithUnit)::DownCast(aTolerance->Magnitude()); |
| 167 | + EXPECT_FALSE(aReprMeasure.IsNull()); |
| 168 | + Handle(StepBasic_MeasureWithUnit) aExtractedMeasure = aReprMeasure->GetMeasureWithUnit(); |
| 169 | + EXPECT_NEAR(aExtractedMeasure->ValueComponent(), 10.0, 1e-7); |
| 170 | +} |
| 171 | + |
| 172 | +// Test MakeFromUsageOption with different transient types |
| 173 | +TEST_F(StepTransientReplacements, MakeFromUsageOption_WorksWithBothTypes) |
| 174 | +{ |
| 175 | + // Create MakeFromUsageOption |
| 176 | + Handle(StepRepr_MakeFromUsageOption) aMakeFromUsage = new StepRepr_MakeFromUsageOption(); |
| 177 | + |
| 178 | + // Test with MeasureWithUnit |
| 179 | + // Use proper function signature for Init |
| 180 | + Standard_Boolean hasDescription = Standard_True; |
| 181 | + aMakeFromUsage->Init(myName, |
| 182 | + myName, |
| 183 | + hasDescription, |
| 184 | + myDescription, |
| 185 | + myProductDefinition, |
| 186 | + myProductDefinition, |
| 187 | + 1, |
| 188 | + myDescription, |
| 189 | + myMeasureWithUnit); |
| 190 | + |
| 191 | + EXPECT_FALSE(aMakeFromUsage->Quantity().IsNull()); |
| 192 | + EXPECT_TRUE(aMakeFromUsage->Quantity()->IsKind(STANDARD_TYPE(StepBasic_MeasureWithUnit))); |
| 193 | + |
| 194 | + Handle(StepBasic_MeasureWithUnit) aMeasure = |
| 195 | + Handle(StepBasic_MeasureWithUnit)::DownCast(aMakeFromUsage->Quantity()); |
| 196 | + EXPECT_FALSE(aMeasure.IsNull()); |
| 197 | + EXPECT_NEAR(aMeasure->ValueComponent(), 5.0, 1e-7); |
| 198 | + |
| 199 | + // Test with ReprItemAndMeasureWithUnit |
| 200 | + aMakeFromUsage->SetQuantity(myReprItemAndMeasureWithUnit); |
| 201 | + EXPECT_FALSE(aMakeFromUsage->Quantity().IsNull()); |
| 202 | + EXPECT_TRUE( |
| 203 | + aMakeFromUsage->Quantity()->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndMeasureWithUnit))); |
| 204 | + |
| 205 | + Handle(StepRepr_ReprItemAndMeasureWithUnit) aReprMeasure = |
| 206 | + Handle(StepRepr_ReprItemAndMeasureWithUnit)::DownCast(aMakeFromUsage->Quantity()); |
| 207 | + EXPECT_FALSE(aReprMeasure.IsNull()); |
| 208 | + Handle(StepBasic_MeasureWithUnit) aExtractedMeasure = aReprMeasure->GetMeasureWithUnit(); |
| 209 | + EXPECT_NEAR(aExtractedMeasure->ValueComponent(), 10.0, 1e-7); |
| 210 | +} |
| 211 | + |
| 212 | +// Test ParallelOffset with different transient types |
| 213 | +TEST_F(StepTransientReplacements, ParallelOffset_WorksWithBothTypes) |
| 214 | +{ |
| 215 | + // Create ParallelOffset |
| 216 | + Handle(StepRepr_ParallelOffset) aParallelOffset = new StepRepr_ParallelOffset(); |
| 217 | + |
| 218 | + // Test with MeasureWithUnit |
| 219 | + aParallelOffset->Init(myName, |
| 220 | + myDescription, |
| 221 | + myProductDefinitionShape, |
| 222 | + StepData_LTrue, |
| 223 | + myMeasureWithUnit); |
| 224 | + |
| 225 | + EXPECT_FALSE(aParallelOffset->Offset().IsNull()); |
| 226 | + EXPECT_TRUE(aParallelOffset->Offset()->IsKind(STANDARD_TYPE(StepBasic_MeasureWithUnit))); |
| 227 | + |
| 228 | + Handle(StepBasic_MeasureWithUnit) aMeasure = |
| 229 | + Handle(StepBasic_MeasureWithUnit)::DownCast(aParallelOffset->Offset()); |
| 230 | + EXPECT_FALSE(aMeasure.IsNull()); |
| 231 | + EXPECT_NEAR(aMeasure->ValueComponent(), 5.0, 1e-7); |
| 232 | + |
| 233 | + // Test with ReprItemAndMeasureWithUnit |
| 234 | + aParallelOffset->SetOffset(myReprItemAndMeasureWithUnit); |
| 235 | + EXPECT_FALSE(aParallelOffset->Offset().IsNull()); |
| 236 | + EXPECT_TRUE( |
| 237 | + aParallelOffset->Offset()->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndMeasureWithUnit))); |
| 238 | + |
| 239 | + Handle(StepRepr_ReprItemAndMeasureWithUnit) aReprMeasure = |
| 240 | + Handle(StepRepr_ReprItemAndMeasureWithUnit)::DownCast(aParallelOffset->Offset()); |
| 241 | + EXPECT_FALSE(aReprMeasure.IsNull()); |
| 242 | + Handle(StepBasic_MeasureWithUnit) aExtractedMeasure = aReprMeasure->GetMeasureWithUnit(); |
| 243 | + EXPECT_NEAR(aExtractedMeasure->ValueComponent(), 10.0, 1e-7); |
| 244 | +} |
| 245 | + |
| 246 | +// Test QuantifiedAssemblyComponentUsage with different transient types |
| 247 | +TEST_F(StepTransientReplacements, QuantifiedAssemblyComponentUsage_WorksWithBothTypes) |
| 248 | +{ |
| 249 | + // Create QuantifiedAssemblyComponentUsage |
| 250 | + Handle(StepRepr_QuantifiedAssemblyComponentUsage) aUsage = |
| 251 | + new StepRepr_QuantifiedAssemblyComponentUsage(); |
| 252 | + |
| 253 | + // Test with MeasureWithUnit |
| 254 | + // Use proper function signature for Init |
| 255 | + Standard_Boolean hasDescription = Standard_True; |
| 256 | + Standard_Boolean hasReferenceDesignator = Standard_True; |
| 257 | + aUsage->Init(myName, |
| 258 | + myName, |
| 259 | + hasDescription, |
| 260 | + myDescription, |
| 261 | + myProductDefinition, |
| 262 | + myProductDefinition, |
| 263 | + hasReferenceDesignator, |
| 264 | + myName, |
| 265 | + myMeasureWithUnit); |
| 266 | + |
| 267 | + EXPECT_FALSE(aUsage->Quantity().IsNull()); |
| 268 | + EXPECT_TRUE(aUsage->Quantity()->IsKind(STANDARD_TYPE(StepBasic_MeasureWithUnit))); |
| 269 | + |
| 270 | + Handle(StepBasic_MeasureWithUnit) aMeasure = |
| 271 | + Handle(StepBasic_MeasureWithUnit)::DownCast(aUsage->Quantity()); |
| 272 | + EXPECT_FALSE(aMeasure.IsNull()); |
| 273 | + EXPECT_NEAR(aMeasure->ValueComponent(), 5.0, 1e-7); |
| 274 | + |
| 275 | + // Test with ReprItemAndMeasureWithUnit |
| 276 | + aUsage->SetQuantity(myReprItemAndMeasureWithUnit); |
| 277 | + EXPECT_FALSE(aUsage->Quantity().IsNull()); |
| 278 | + EXPECT_TRUE(aUsage->Quantity()->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndMeasureWithUnit))); |
| 279 | + |
| 280 | + Handle(StepRepr_ReprItemAndMeasureWithUnit) aReprMeasure = |
| 281 | + Handle(StepRepr_ReprItemAndMeasureWithUnit)::DownCast(aUsage->Quantity()); |
| 282 | + EXPECT_FALSE(aReprMeasure.IsNull()); |
| 283 | + Handle(StepBasic_MeasureWithUnit) aExtractedMeasure = aReprMeasure->GetMeasureWithUnit(); |
| 284 | + EXPECT_NEAR(aExtractedMeasure->ValueComponent(), 10.0, 1e-7); |
| 285 | +} |
| 286 | + |
| 287 | +// Test MeasureQualification with different transient types |
| 288 | +TEST_F(StepTransientReplacements, MeasureQualification_WorksWithBothTypes) |
| 289 | +{ |
| 290 | + // Create MeasureQualification |
| 291 | + Handle(StepShape_MeasureQualification) aQualification = new StepShape_MeasureQualification(); |
| 292 | + |
| 293 | + // Test with MeasureWithUnit |
| 294 | + aQualification->Init(myName, myDescription, myMeasureWithUnit, myQualifiers); |
| 295 | + |
| 296 | + EXPECT_FALSE(aQualification->QualifiedMeasure().IsNull()); |
| 297 | + EXPECT_TRUE(aQualification->QualifiedMeasure()->IsKind(STANDARD_TYPE(StepBasic_MeasureWithUnit))); |
| 298 | + |
| 299 | + Handle(StepBasic_MeasureWithUnit) aMeasure = |
| 300 | + Handle(StepBasic_MeasureWithUnit)::DownCast(aQualification->QualifiedMeasure()); |
| 301 | + EXPECT_FALSE(aMeasure.IsNull()); |
| 302 | + EXPECT_NEAR(aMeasure->ValueComponent(), 5.0, 1e-7); |
| 303 | + |
| 304 | + // Test with ReprItemAndMeasureWithUnit |
| 305 | + aQualification->SetQualifiedMeasure(myReprItemAndMeasureWithUnit); |
| 306 | + EXPECT_FALSE(aQualification->QualifiedMeasure().IsNull()); |
| 307 | + EXPECT_TRUE( |
| 308 | + aQualification->QualifiedMeasure()->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndMeasureWithUnit))); |
| 309 | + |
| 310 | + Handle(StepRepr_ReprItemAndMeasureWithUnit) aReprMeasure = |
| 311 | + Handle(StepRepr_ReprItemAndMeasureWithUnit)::DownCast(aQualification->QualifiedMeasure()); |
| 312 | + EXPECT_FALSE(aReprMeasure.IsNull()); |
| 313 | + Handle(StepBasic_MeasureWithUnit) aExtractedMeasure = aReprMeasure->GetMeasureWithUnit(); |
| 314 | + EXPECT_NEAR(aExtractedMeasure->ValueComponent(), 10.0, 1e-7); |
| 315 | +} |
| 316 | + |
| 317 | +// Test GetMeasureWithUnit helper function from STEPCAFControl_Reader namespace |
| 318 | +TEST_F(StepTransientReplacements, GetMeasureWithUnit_ExtractsCorrectly) |
| 319 | +{ |
| 320 | + // This tests the helper function that was added in STEPCAFControl_Reader.cxx |
| 321 | + // We recreate the function here for testing |
| 322 | + |
| 323 | + auto GetMeasureWithUnit = |
| 324 | + [](const Handle(Standard_Transient)& theMeasure) -> Handle(StepBasic_MeasureWithUnit) { |
| 325 | + if (theMeasure.IsNull()) |
| 326 | + { |
| 327 | + return nullptr; |
| 328 | + } |
| 329 | + |
| 330 | + Handle(StepBasic_MeasureWithUnit) aMeasureWithUnit; |
| 331 | + if (theMeasure->IsKind(STANDARD_TYPE(StepBasic_MeasureWithUnit))) |
| 332 | + { |
| 333 | + aMeasureWithUnit = Handle(StepBasic_MeasureWithUnit)::DownCast(theMeasure); |
| 334 | + } |
| 335 | + else if (theMeasure->IsKind(STANDARD_TYPE(StepRepr_ReprItemAndMeasureWithUnit))) |
| 336 | + { |
| 337 | + Handle(StepRepr_ReprItemAndMeasureWithUnit) aReprMeasureItem = |
| 338 | + Handle(StepRepr_ReprItemAndMeasureWithUnit)::DownCast(theMeasure); |
| 339 | + aMeasureWithUnit = aReprMeasureItem->GetMeasureWithUnit(); |
| 340 | + } |
| 341 | + return aMeasureWithUnit; |
| 342 | + }; |
| 343 | + |
| 344 | + // Test with null |
| 345 | + Handle(Standard_Transient) aNullTransient; |
| 346 | + Handle(StepBasic_MeasureWithUnit) aExtracted = GetMeasureWithUnit(aNullTransient); |
| 347 | + EXPECT_TRUE(aExtracted.IsNull()); |
| 348 | + |
| 349 | + // Test with MeasureWithUnit |
| 350 | + aExtracted = GetMeasureWithUnit(myMeasureWithUnit); |
| 351 | + EXPECT_FALSE(aExtracted.IsNull()); |
| 352 | + EXPECT_NEAR(aExtracted->ValueComponent(), 5.0, 1e-7); |
| 353 | + |
| 354 | + // Test with ReprItemAndMeasureWithUnit |
| 355 | + aExtracted = GetMeasureWithUnit(myReprItemAndMeasureWithUnit); |
| 356 | + EXPECT_FALSE(aExtracted.IsNull()); |
| 357 | + EXPECT_NEAR(aExtracted->ValueComponent(), 10.0, 1e-7); |
| 358 | + |
| 359 | + // Test with unrelated type |
| 360 | + Handle(Standard_Transient) anUnrelatedTransient = myName; |
| 361 | + aExtracted = GetMeasureWithUnit(anUnrelatedTransient); |
| 362 | + EXPECT_TRUE(aExtracted.IsNull()); |
| 363 | +} |
0 commit comments