22#include <boost/test/unit_test.hpp>
26#include <api/common/commands/editor_commands.pb.h>
27#include <api/common/envelope.pb.h>
29#include <api/schematic/schematic_types.pb.h>
39struct API_HANDLER_SCH_FIXTURE
41 SETTINGS_MANAGER m_settingsManager;
42 std::unique_ptr<SCHEMATIC> m_schematic;
44 std::shared_ptr<HEADLESS_SCH_CONTEXT> m_context;
46 SCHEMATIC* loadSchematic(
const wxString& aRelPath )
49 m_schematicSlot = m_schematic.get();
50 m_context = std::make_shared<HEADLESS_SCH_CONTEXT>( &m_schematicSlot,
51 &m_settingsManager.Prj() );
52 return m_schematic.get();
57kiapi::common::types::DocumentSpecifier makeDocument(
const SCHEMATIC& aSchematic )
59 kiapi::common::types::DocumentSpecifier document;
60 document.set_type( kiapi::common::types::DocumentType::DOCTYPE_SCHEMATIC );
67kiapi::common::ApiRequest makeBeginCommitRequest(
const SCHEMATIC& aSchematic )
69 kiapi::common::commands::BeginCommit command;
70 *command.mutable_header()->mutable_document() = makeDocument( aSchematic );
72 kiapi::common::ApiRequest request;
73 request.mutable_header()->set_client_name(
"kicad.qa" );
74 BOOST_REQUIRE( request.mutable_message()->PackFrom( command ) );
80kiapi::common::ApiRequest makeRevertRequest(
const SCHEMATIC& aSchematic )
82 kiapi::common::commands::RevertDocument command;
83 *command.mutable_document() = makeDocument( aSchematic );
85 kiapi::common::ApiRequest request;
86 request.mutable_header()->set_client_name(
"kicad.qa" );
87 BOOST_REQUIRE( request.mutable_message()->PackFrom( command ) );
96BOOST_FIXTURE_TEST_SUITE( ApiHandlerSch, API_HANDLER_SCH_FIXTURE )
105 kiapi::common::ApiRequest beginRequest = makeBeginCommitRequest( *
schematic );
108 kiapi::common::ApiRequest request = makeRevertRequest( *
schematic );
113 BOOST_CHECK(
result.error().error_message().find(
"commit" ) != std::string::npos );
123 ApiRequest beginRequest = makeBeginCommitRequest( *
schematic );
126 commands::CreateItems command;
127 command.mutable_header()->mutable_document()->CopyFrom( makeDocument( *
schematic ) );
129 schematic::types::SchematicLine line;
130 line.mutable_id()->set_value(
"83618809-06d6-4cbe-ba0e-ec60fe58921c" );
131 line.set_type( schematic::types::SchematicLineType::SLT_WIRE );
132 line.add_custom_properties()->set_key(
"linE Width" );
133 line.add_custom_properties()->set_key(
"start X" );
135 command.add_items()->PackFrom( line );
138 request.mutable_header()->set_client_name(
"kicad.qa" );
139 BOOST_REQUIRE( request.mutable_message()->PackFrom( command ) );
144 commands::CreateItemsResponse response;
146 BOOST_REQUIRE_EQUAL( response.created_items_size(), 1 );
148 const commands::ItemStatus& status = response.created_items( 0 ).status();
151 BOOST_CHECK_EQUAL( status.code(), kiapi::common::commands::ItemStatusCode::ISC_INVALID_DATA );
152 BOOST_CHECK_NE( status.error_message().find(
"Invalid custom properties" ), std::string::npos );
161 ApiRequest beginRequest = makeBeginCommitRequest( *
schematic );
164 commands::CreateItems command;
165 command.mutable_header()->mutable_document()->CopyFrom( makeDocument( *
schematic ) );
167 schematic::types::SchematicSymbolInstance symbol;
168 symbol.mutable_id()->set_value(
"f8688bac-2fcb-4184-ab0e-0cf46a139c43" );
169 symbol.mutable_transform()->set_orientation( schematic::types::SchematicSymbolOrientation::SSO_0 );
171 schematic::types::SchematicField* field = symbol.add_user_fields();
172 field->set_name(
"MPN" );
173 field->mutable_text()->set_text(
"123" );
175 types::CustomProperty* prop = symbol.add_custom_properties();
176 prop->set_key(
"MPN" );
177 prop->set_value(
"456" );
179 command.add_items()->PackFrom( symbol );
182 request.mutable_header()->set_client_name(
"kicad.qa" );
183 BOOST_REQUIRE( request.mutable_message()->PackFrom( command ) );
188 commands::CreateItemsResponse response;
190 BOOST_REQUIRE_EQUAL( response.created_items_size(), 1 );
192 const commands::ItemStatus& status = response.created_items( 0 ).status();
195 BOOST_CHECK_EQUAL( status.code(), kiapi::common::commands::ItemStatusCode::ISC_INVALID_DATA );
196 BOOST_CHECK_NE( status.error_message().find(
"MPN" ), std::string::npos );
tl::expected< ApiResponse, ApiResponseStatus > API_RESULT
API_RESULT Handle(ApiRequest &aMsg)
Attempt to handle the given API request, if a handler exists in this class for the message.
Holds all the data relating to one schematic.
PROJECT & Project() const
Return a reference to the project this schematic is part of.
void LoadSchematic(SETTINGS_MANAGER &aSettingsManager, const wxString &aRelPath, std::unique_ptr< SCHEMATIC > &aSchematic)
KICOMMON_API void PackProject(types::ProjectSpecifier &aOutput, const PROJECT &aInput)
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(RevertDocumentRejectedWithOpenCommit)
wxString result
Test unit parsing edge cases and error handling.
BOOST_CHECK_EQUAL(result, "25.4")