/
spivag
/
command_occ
Обзор
Документация
Войти
/
spivag
/
command_occ
Код
Запросы
1
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
initial
tests/test_face_manipulate_serialization.cpp
279 строк
11 KB
Spivakov
Initial
10 апр 2026, 13:45
10 апр 2026, 13:45
b2ad868
Код
Авторство
О чём код?
/// @file test_face_manipulate_serialization.cpp /// @brief Тесты сериализации/десериализации команд манипуляции гранями /// @project gtests /// /// (c) Alexander Spivakov on 15.12.2025. /// #include <gtest/gtest.h> #include <nlohmann-json/shape_deserialize.h> #include <nlohmann-json/shape_serialize.h> #include <demo_blend_edges.hxx> #include <demo_faces_conjugate.hxx> #include <demo_faces_manipulate.hxx> #include <sstream> /// @brief Тест сериализации и десериализации BuildOffsetFaces TEST( FaceManipulateSerialization, OffsetFaces ) { // Создать оригинальный шейп auto originalShape = demo::OffsetFace::SingleFace(); ASSERT_NE( nullptr, originalShape ); // Выполнить для проверки валидности originalShape->Execute(); std::string originalMessage = originalShape->ExecutionMessage(); EXPECT_TRUE( originalMessage.empty() || originalMessage.find( "Success" ) != std::string::npos ) << "Original execution failed: " << originalMessage; // Сериализовать json_impl jShapes = json_impl::array(); ShapeSerializeProvider serializer{ jShapes }; size_t shapeId = serializer.GetSerialId( originalShape ); EXPECT_GT( shapeId, 0 ); EXPECT_FALSE( jShapes.empty() ); // Десериализовать auto shapesMap = MakeShapes( jShapes ); ASSERT_FALSE( shapesMap.empty() ); ASSERT_TRUE( shapesMap.count( shapeId ) > 0 ); auto restoredShape = shapesMap[shapeId]; ASSERT_NE( nullptr, restoredShape ); // Выполнить восстановленный шейп restoredShape->Execute(); std::string restoredMessage = restoredShape->ExecutionMessage(); EXPECT_TRUE( restoredMessage.empty() || restoredMessage.find( "Success" ) != std::string::npos ) << "Restored execution failed: " << restoredMessage; } /// @brief Тест сериализации и десериализации BuildChamfer TEST( FaceManipulateSerialization, Chamfer ) { // Создать оригинальный шейп auto originalShape = demo::BlendEdges::CreateChamfer(); ASSERT_NE( nullptr, originalShape ); // Выполнить для проверки валидности originalShape->Execute(); std::string originalMessage = originalShape->ExecutionMessage(); EXPECT_TRUE( originalMessage.empty() || originalMessage.find( "Success" ) != std::string::npos ) << "Original execution failed: " << originalMessage; // Сериализовать json_impl jShapes = json_impl::array(); ShapeSerializeProvider serializer{ jShapes }; size_t shapeId = serializer.GetSerialId( originalShape ); EXPECT_GT( shapeId, 0 ); EXPECT_FALSE( jShapes.empty() ); // Десериализовать auto shapesMap = MakeShapes( jShapes ); ASSERT_FALSE( shapesMap.empty() ); ASSERT_TRUE( shapesMap.count( shapeId ) > 0 ); auto restoredShape = shapesMap[shapeId]; ASSERT_NE( nullptr, restoredShape ); // Выполнить восстановленный шейп restoredShape->Execute(); std::string restoredMessage = restoredShape->ExecutionMessage(); EXPECT_TRUE( restoredMessage.empty() || restoredMessage.find( "Success" ) != std::string::npos ) << "Restored execution failed: " << restoredMessage; } /// @brief Тест сериализации и десериализации BuildFillet с радиусом TEST( FaceManipulateSerialization, FilletRadius ) { // Создать оригинальный шейп auto originalShape = demo::BlendEdges::CreateFilletRadius(); ASSERT_NE( nullptr, originalShape ); // Выполнить для проверки валидности originalShape->Execute(); std::string originalMessage = originalShape->ExecutionMessage(); EXPECT_TRUE( originalMessage.empty() || originalMessage.find( "Success" ) != std::string::npos ) << "Original execution failed: " << originalMessage; // Сериализовать json_impl jShapes = json_impl::array(); ShapeSerializeProvider serializer{ jShapes }; size_t shapeId = serializer.GetSerialId( originalShape ); EXPECT_GT( shapeId, 0 ); EXPECT_FALSE( jShapes.empty() ); // Десериализовать auto shapesMap = MakeShapes( jShapes ); ASSERT_FALSE( shapesMap.empty() ); ASSERT_TRUE( shapesMap.count( shapeId ) > 0 ); auto restoredShape = shapesMap[shapeId]; ASSERT_NE( nullptr, restoredShape ); // Выполнить восстановленный шейп restoredShape->Execute(); std::string restoredMessage = restoredShape->ExecutionMessage(); EXPECT_TRUE( restoredMessage.empty() || restoredMessage.find( "Success" ) != std::string::npos ) << "Restored execution failed: " << restoredMessage; } /// @brief Тест сериализации и десериализации BuildFillet с shape factor TEST( FaceManipulateSerialization, FilletRadiusWithShapeFactor ) { // Создать оригинальный шейп auto originalShape = demo::BlendEdges::CreateFilletRadius02(); ASSERT_NE( nullptr, originalShape ); // Выполнить для проверки валидности originalShape->Execute(); std::string originalMessage = originalShape->ExecutionMessage(); EXPECT_TRUE( originalMessage.empty() || originalMessage.find( "Success" ) != std::string::npos ) << "Original execution failed: " << originalMessage; // Сериализовать json_impl jShapes = json_impl::array(); ShapeSerializeProvider serializer{ jShapes }; size_t shapeId = serializer.GetSerialId( originalShape ); EXPECT_GT( shapeId, 0 ); EXPECT_FALSE( jShapes.empty() ); // Десериализовать auto shapesMap = MakeShapes( jShapes ); ASSERT_FALSE( shapesMap.empty() ); ASSERT_TRUE( shapesMap.count( shapeId ) > 0 ); auto restoredShape = shapesMap[shapeId]; ASSERT_NE( nullptr, restoredShape ); // Выполнить восстановленный шейп restoredShape->Execute(); std::string restoredMessage = restoredShape->ExecutionMessage(); EXPECT_TRUE( restoredMessage.empty() || restoredMessage.find( "Success" ) != std::string::npos ) << "Restored execution failed: " << restoredMessage; } /// @brief Тест сериализации и десериализации BuildChamfer с параметрами FaceFace (несимметричная) TEST( FaceManipulateSerialization, ChamferDistanceDistance ) { // Создать оригинальный шейп - несимметричная фаска с параметрами FaceFace auto originalShape = demo::ConjugateFaces::CreateChamferDistanceDistance(); ASSERT_NE( nullptr, originalShape ); // Выполнить для проверки валидности originalShape->Execute(); std::string originalMessage = originalShape->ExecutionMessage(); EXPECT_TRUE( originalMessage.empty() || originalMessage.find( "Success" ) != std::string::npos ) << "Original execution failed: " << originalMessage; // Сериализовать json_impl jShapes = json_impl::array(); ShapeSerializeProvider serializer{ jShapes }; size_t shapeId = serializer.GetSerialId( originalShape ); EXPECT_GT( shapeId, 0 ); EXPECT_FALSE( jShapes.empty() ); // Проверить, что в JSON есть поля для несимметричной фаски bool foundChamfer = false; for ( auto const& jShape : jShapes ) { if ( jShape.contains( "shape_builder" ) && jShape["shape_builder"] == "BuildChamfer" ) { foundChamfer = true; EXPECT_TRUE( jShape.contains( "chamfer_type" ) ); EXPECT_EQ( jShape["chamfer_type"], "non_symmetric" ); EXPECT_TRUE( jShape.contains( "distance_base_face" ) ); EXPECT_TRUE( jShape.contains( "distance_other_face" ) ); EXPECT_TRUE( jShape.contains( "face_face" ) ); // Проверить структуру face_face if ( jShape.contains( "face_face" ) ) { EXPECT_TRUE( jShape["face_face"].is_object() ); EXPECT_TRUE( jShape["face_face"].contains( "base_face" ) ); EXPECT_TRUE( jShape["face_face"].contains( "co_face" ) ); } break; } } EXPECT_TRUE( foundChamfer ) << "Chamfer not found in serialized JSON"; // Десериализовать auto shapesMap = MakeShapes( jShapes ); ASSERT_FALSE( shapesMap.empty() ); ASSERT_TRUE( shapesMap.count( shapeId ) > 0 ); auto restoredShape = shapesMap[shapeId]; ASSERT_NE( nullptr, restoredShape ); // Выполнить восстановленный шейп restoredShape->Execute(); std::string restoredMessage = restoredShape->ExecutionMessage(); EXPECT_TRUE( restoredMessage.empty() || restoredMessage.find( "Success" ) != std::string::npos ) << "Restored execution failed: " << restoredMessage; } /// @brief Тест для просмотра JSON сериализации фаски CreateChamferDistanceDistance TEST( FaceManipulateSerialization, ChamferDistanceDistanceJsonOutput ) { auto originalShape = demo::ConjugateFaces::CreateChamferDistanceDistance(); ASSERT_NE( nullptr, originalShape ); // Сериализовать json_impl jShapes = json_impl::array(); ShapeSerializeProvider serializer{ jShapes }; size_t shapeId = serializer.GetSerialId( originalShape ); // // Вывести JSON (будет видно в выводе теста при запуске с --gtest_print_test_names) // std::cout << "\n=== Chamfer JSON Output ===" << std::endl; // std::cout << jShapes.dump( 2 ) << std::endl; // // Проверить структуру JSON // bool foundChamfer = false; // for ( auto const& jShape : jShapes ) // { // if ( jShape.contains( "shape_builder" ) && jShape["shape_builder"] == "BuildChamfer" ) // { // foundChamfer = true; // std::cout << "\n=== Chamfer Details ===" << std::endl; // std::cout << "chamfer_type: " << jShape.value( "chamfer_type", "N/A" ) << std::endl; // std::cout << "distance_base_face: " << jShape.value( "distance_base_face", 0.0 ) << std::endl; // std::cout << "distance_other_face: " << jShape.value( "distance_other_face", 0.0 ) << std::endl; // std::cout << "has 'faces': " << ( jShape.contains( "faces" ) ? "YES" : "NO" ) << std::endl; // if ( jShape.contains( "faces" ) && jShape["faces"].is_array() ) // { // std::cout << "faces count: " << jShape["faces"].size() << std::endl; // } // } // } // EXPECT_TRUE( foundChamfer ); } /// @brief Тест проверки ExecutionMessage для всех команд TEST( FaceManipulateSerialization, ExecutionMessageCheck ) { std::vector< std::pair< std::string, std::shared_ptr< IShapeBuilder > > > shapes = { { "OffsetFaces", demo::OffsetFace::SingleFace() }, { "Chamfer", demo::BlendEdges::CreateChamfer() }, { "FilletRadius", demo::BlendEdges::CreateFilletRadius() }, { "FilletRadius02", demo::BlendEdges::CreateFilletRadius02() }, { "FilletRadius08", demo::BlendEdges::CreateFilletRadius08() }, { "ChamferDistanceDistance", demo::ConjugateFaces::CreateChamferDistanceDistance() } }; for ( auto const& [name, shape] : shapes ) { ASSERT_NE( nullptr, shape ) << "Shape " << name << " is null"; // Выполнить shape->Execute(); std::string message = shape->ExecutionMessage(); // Проверить, что сообщение не содержит ошибок EXPECT_TRUE( message.empty() || message.find( "error" ) == std::string::npos || message.find( "Success" ) != std::string::npos ) << "Shape " << name << " execution message: " << message; } }