167 lines
7.1 KiB
C++
167 lines
7.1 KiB
C++
|
|
#include <gtest/gtest.h>
|
|||
|
|
#include "vde/brep/brep.h"
|
|||
|
|
#include "vde/brep/modeling.h"
|
|||
|
|
#include "vde/brep/step_export.h"
|
|||
|
|
#include <fstream>
|
|||
|
|
#include <sstream>
|
|||
|
|
#include <algorithm>
|
|||
|
|
|
|||
|
|
using namespace vde::brep;
|
|||
|
|
using namespace vde::core;
|
|||
|
|
|
|||
|
|
// ═══════════════════════════════════════════════════════════
|
|||
|
|
// STEP export basic tests
|
|||
|
|
// ═══════════════════════════════════════════════════════════
|
|||
|
|
|
|||
|
|
TEST(StepExportTest, ExportBox_ProducesValidStructure) {
|
|||
|
|
auto box = make_box(2, 3, 4);
|
|||
|
|
std::string step = export_step({box});
|
|||
|
|
|
|||
|
|
// Must start with ISO-10303-21 header
|
|||
|
|
EXPECT_TRUE(step.find("ISO-10303-21;") != std::string::npos);
|
|||
|
|
|
|||
|
|
// Must contain HEADER section
|
|||
|
|
EXPECT_TRUE(step.find("HEADER;") != std::string::npos);
|
|||
|
|
EXPECT_TRUE(step.find("ENDSEC;") != std::string::npos);
|
|||
|
|
|
|||
|
|
// Must contain DATA section
|
|||
|
|
EXPECT_TRUE(step.find("DATA;") != std::string::npos);
|
|||
|
|
|
|||
|
|
// Must contain CARTESIAN_POINT entities
|
|||
|
|
EXPECT_TRUE(step.find("CARTESIAN_POINT") != std::string::npos);
|
|||
|
|
|
|||
|
|
// Must contain topology entities
|
|||
|
|
EXPECT_TRUE(step.find("CLOSED_SHELL") != std::string::npos ||
|
|||
|
|
step.find("ADVANCED_FACE") != std::string::npos);
|
|||
|
|
|
|||
|
|
// Must end properly
|
|||
|
|
EXPECT_TRUE(step.find("END-ISO-10303-21;") != std::string::npos);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
TEST(StepExportTest, ExportBox_ContainsManifoldSolidBrep) {
|
|||
|
|
auto box = make_box(1, 1, 1);
|
|||
|
|
std::string step = export_step({box});
|
|||
|
|
|
|||
|
|
EXPECT_TRUE(step.find("MANIFOLD_SOLID_BREP") != std::string::npos);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
TEST(StepExportTest, ExportBox_ContainsPlanes) {
|
|||
|
|
auto box = make_box(2, 2, 2);
|
|||
|
|
std::string step = export_step({box});
|
|||
|
|
|
|||
|
|
// Box faces are degree 1×1 → should export as PLANE
|
|||
|
|
EXPECT_TRUE(step.find("PLANE") != std::string::npos ||
|
|||
|
|
step.find("B_SPLINE_SURFACE") != std::string::npos);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
TEST(StepExportTest, ExportBox_ContainsEdgeCurve) {
|
|||
|
|
auto box = make_box(1, 1, 1);
|
|||
|
|
std::string step = export_step({box});
|
|||
|
|
|
|||
|
|
EXPECT_TRUE(step.find("EDGE_CURVE") != std::string::npos);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
TEST(StepExportTest, ExportBox_ContainsOrientedEdge) {
|
|||
|
|
auto box = make_box(1, 1, 1);
|
|||
|
|
std::string step = export_step({box});
|
|||
|
|
|
|||
|
|
EXPECT_TRUE(step.find("ORIENTED_EDGE") != std::string::npos);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
TEST(StepExportTest, ExportBox_HasProperEntityNumbering) {
|
|||
|
|
auto box = make_box(1, 1, 1);
|
|||
|
|
std::string step = export_step({box});
|
|||
|
|
|
|||
|
|
// Should have at least entity #1
|
|||
|
|
EXPECT_TRUE(step.find("#1 =") != std::string::npos);
|
|||
|
|
|
|||
|
|
// Count entity occurrences to ensure numbering is sequential
|
|||
|
|
int entity_count = 0;
|
|||
|
|
size_t pos = 0;
|
|||
|
|
while ((pos = step.find("= ", pos)) != std::string::npos) {
|
|||
|
|
entity_count++;
|
|||
|
|
pos += 2;
|
|||
|
|
}
|
|||
|
|
EXPECT_GT(entity_count, 5);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// ═══════════════════════════════════════════════════════════
|
|||
|
|
// Sphere STEP export
|
|||
|
|
// ═══════════════════════════════════════════════════════════
|
|||
|
|
|
|||
|
|
TEST(StepExportTest, ExportSphere_ProducesValidOutput) {
|
|||
|
|
auto sphere = make_sphere(2.0);
|
|||
|
|
std::string step = export_step({sphere});
|
|||
|
|
|
|||
|
|
EXPECT_TRUE(step.find("ISO-10303-21;") != std::string::npos);
|
|||
|
|
EXPECT_TRUE(step.find("CARTESIAN_POINT") != std::string::npos);
|
|||
|
|
EXPECT_TRUE(step.find("MANIFOLD_SOLID_BREP") != std::string::npos ||
|
|||
|
|
step.find("CLOSED_SHELL") != std::string::npos);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// ═══════════════════════════════════════════════════════════
|
|||
|
|
// Cylinder STEP export
|
|||
|
|
// ═══════════════════════════════════════════════════════════
|
|||
|
|
|
|||
|
|
TEST(StepExportTest, ExportCylinder_ProducesValidOutput) {
|
|||
|
|
auto cyl = make_cylinder(1.0, 4.0);
|
|||
|
|
std::string step = export_step({cyl});
|
|||
|
|
|
|||
|
|
EXPECT_TRUE(step.find("ISO-10303-21;") != std::string::npos);
|
|||
|
|
EXPECT_TRUE(step.find("CARTESIAN_POINT") != std::string::npos);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// ═══════════════════════════════════════════════════════════
|
|||
|
|
// Multiple bodies
|
|||
|
|
// ═══════════════════════════════════════════════════════════
|
|||
|
|
|
|||
|
|
TEST(StepExportTest, ExportMultipleBodies_ProducesValidOutput) {
|
|||
|
|
auto box1 = make_box(1, 1, 1);
|
|||
|
|
auto box2 = make_box(2, 2, 2);
|
|||
|
|
std::string step = export_step({box1, box2});
|
|||
|
|
|
|||
|
|
EXPECT_TRUE(step.find("ISO-10303-21;") != std::string::npos);
|
|||
|
|
EXPECT_TRUE(step.find("MANIFOLD_SOLID_BREP") != std::string::npos);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// ═══════════════════════════════════════════════════════════
|
|||
|
|
// File export
|
|||
|
|
// ═══════════════════════════════════════════════════════════
|
|||
|
|
|
|||
|
|
TEST(StepExportTest, ExportFile_WritesToDisk) {
|
|||
|
|
auto box = make_box(1, 1, 1);
|
|||
|
|
std::string path = "/tmp/test_vde_export.stp";
|
|||
|
|
export_step_file(path, {box});
|
|||
|
|
|
|||
|
|
std::ifstream in(path);
|
|||
|
|
EXPECT_TRUE(in.good());
|
|||
|
|
std::string content((std::istreambuf_iterator<char>(in)),
|
|||
|
|
std::istreambuf_iterator<char>());
|
|||
|
|
EXPECT_TRUE(content.find("ISO-10303-21;") != std::string::npos);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// ═══════════════════════════════════════════════════════════
|
|||
|
|
// Empty model
|
|||
|
|
// ═══════════════════════════════════════════════════════════
|
|||
|
|
|
|||
|
|
TEST(StepExportTest, ExportEmptyModel_ProducesMinimalOutput) {
|
|||
|
|
BrepModel empty;
|
|||
|
|
std::string step = export_step({empty});
|
|||
|
|
|
|||
|
|
EXPECT_TRUE(step.find("ISO-10303-21;") != std::string::npos);
|
|||
|
|
EXPECT_TRUE(step.find("DATA;") != std::string::npos);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// ═══════════════════════════════════════════════════════════
|
|||
|
|
// AP214 schema check
|
|||
|
|
// ═══════════════════════════════════════════════════════════
|
|||
|
|
|
|||
|
|
TEST(StepExportTest, UsesAP214Schema) {
|
|||
|
|
auto box = make_box(1, 1, 1);
|
|||
|
|
std::string step = export_step({box});
|
|||
|
|
|
|||
|
|
EXPECT_TRUE(step.find("AUTOMOTIVE_DESIGN") != std::string::npos ||
|
|||
|
|
step.find("AP214") != std::string::npos ||
|
|||
|
|
step.find("10303 214") != std::string::npos);
|
|||
|
|
}
|