24#include <boost/test/unit_test.hpp>
33#include <wx/filename.h>
34#include <wx/stdpaths.h>
44wxString patchTempDir()
46 static unsigned counter = 0;
47 return wxStandardPaths::Get().GetTempDir() + wxFILE_SEP_PATH
48 + wxString::Format( wxS(
"kicad_patch_%ld_%u" ),
static_cast<long>( wxGetProcessId() ),
124 {
"board", { {
"design_settings", { {
"rule_severities", { {
"old_key",
"warning" } } } } } } },
125 {
"text_variables", { {
"USER_VAR",
"user value" } } },
126 {
"schematic", { {
"legacy_lib_dir",
"/old/path" } } }
130 {
"board", { {
"design_settings", { {
"rule_severities", { {
"new_key",
"error" } } } } } } }
136 BOOST_CHECK_EQUAL( target[
"board"][
"design_settings"][
"rule_severities"][
"new_key"],
"error" );
137 BOOST_CHECK( !target[
"board"][
"design_settings"][
"rule_severities"].contains(
"old_key" ) );
149 json target = { {
"board", { {
"design_settings", { {
"rule_severities", { {
"k",
"warning" } } } } } } } };
153 BOOST_CHECK_EQUAL( target[
"board"][
"design_settings"][
"rule_severities"][
"k"],
"warning" );
161 json target = json::object();
172 {
"net_settings", { {
"classes", json::array() } } },
173 {
"schematic", { {
"preserved",
true } } }
178 {
"classes", { { {
"name",
"HighSpeed" }, {
"priority", 1 } } } },
179 {
"netclass_patterns", { { {
"pattern",
"DDR_*" }, {
"netclass",
"HighSpeed" } } } }
194 {
"pcbnew", { {
"page_layout_descr_file",
"target-pcb.kicad_wks" } } },
195 {
"schematic", { {
"page_layout_descr_file",
"target-sch.kicad_wks" } } }
199 {
"pcbnew", { {
"page_layout_descr_file",
"source-pcb.kicad_wks" } } },
200 {
"schematic", { {
"page_layout_descr_file",
"source-sch.kicad_wks" } } }
205 BOOST_CHECK_EQUAL( target[
"schematic"][
"page_layout_descr_file"],
"source-sch.kicad_wks" );
206 BOOST_CHECK_EQUAL( target[
"pcbnew"][
"page_layout_descr_file"],
"target-pcb.kicad_wks" );
214 wxString tmpDir = patchTempDir();
215 BOOST_REQUIRE( wxFileName::Mkdir( tmpDir, wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL ) );
217 const wxString outputPath = tmpDir + wxFILE_SEP_PATH + wxS(
"test.kicad_pro" );
220 json source = { {
"board", { {
"design_settings", { {
"rule_severities", { {
"k",
"error" } } } } } } } };
227 wxFile in( outputPath );
229 in.ReadAll( &content );
230 json parsed = json::parse( content.ToStdString() );
231 BOOST_CHECK_EQUAL( parsed[
"board"][
"design_settings"][
"rule_severities"][
"k"],
"error" );
234 wxRemoveFile( outputPath );
235 wxFileName::Rmdir( tmpDir );
241 wxString tmpDir = patchTempDir();
242 BOOST_REQUIRE( wxFileName::Mkdir( tmpDir, wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL ) );
244 const wxString outputPath = tmpDir + wxFILE_SEP_PATH + wxS(
"test.kicad_pro" );
247 json source = { {
"text_variables", { {
"USER_VAR",
"source value" } } } };
248 std::set<wxString> docProps;
251 BOOST_CHECK( !wxFileExists( outputPath ) );
253 if( wxFileExists( outputPath ) )
254 wxRemoveFile( outputPath );
256 wxFileName::Rmdir( tmpDir );
264 wxString tmpDir = patchTempDir();
265 BOOST_REQUIRE( wxFileName::Mkdir( tmpDir, wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL ) );
267 const wxString outputPath = tmpDir + wxFILE_SEP_PATH + wxS(
"test.kicad_pro" );
270 {
"text_variables", { {
"USER_VAR",
"user value" } } },
271 {
"board", { {
"design_settings", { {
"rule_severities", { {
"old",
"warning" } } } } } } }
277 BOOST_REQUIRE( out.Write( wxString::FromUTF8( existing.dump( 2 ) ) ) );
280 json source = { {
"board", { {
"design_settings", { {
"rule_severities", { {
"new",
"error" } } } } } } } };
285 wxFile in( outputPath );
287 in.ReadAll( &content );
288 json parsed = json::parse( content.ToStdString() );
290 BOOST_CHECK_EQUAL( parsed[
"board"][
"design_settings"][
"rule_severities"][
"new"],
"error" );
291 BOOST_CHECK( !parsed[
"board"][
"design_settings"][
"rule_severities"].contains(
"old" ) );
295 wxRemoveFile( outputPath );
296 wxFileName::Rmdir( tmpDir );
302 wxString tmpDir = patchTempDir();
303 BOOST_REQUIRE( wxFileName::Mkdir( tmpDir, wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL ) );
305 const wxString outputPath = tmpDir + wxFILE_SEP_PATH + wxS(
"test.kicad_pro" );
307 json existing = { {
"text_variables", { {
"USER_VAR",
"user value" } } } };
312 BOOST_REQUIRE( out.Write( wxString::FromUTF8( existing.dump( 2 ) ) ) );
315 json source = { {
"board", json::object() } };
320 wxFile in( outputPath );
322 in.ReadAll( &content );
323 json parsed = json::parse( content.ToStdString() );
327 wxRemoveFile( outputPath );
328 wxFileName::Rmdir( tmpDir );
340 {
"design_settings", {
341 {
"rule_severities", { {
"copper_edge_clearance",
"error" } } },
342 {
"rules", { {
"min_copper_edge_clearance", 0.5 } } },
343 {
"track_widths", json::array( { 0.2, 0.25 } ) }
346 {
"meta", { {
"filename",
"board.kicad_pro" } } }
351 {
"design_settings", {
352 {
"rule_severities", { {
"copper_edge_clearance",
"warning" } } },
353 {
"rules", { {
"min_copper_edge_clearance", 99.0 } } },
354 {
"track_widths", json::array( { 9.0 } ) }
362 BOOST_CHECK_EQUAL( existing[
"board"][
"design_settings"][
"rule_severities"][
"copper_edge_clearance"],
367 BOOST_CHECK_EQUAL( existing[
"board"][
"design_settings"][
"rules"][
"min_copper_edge_clearance"], 0.5 );
369 json::array( { 0.2, 0.25 } ).dump() );
const wxString DOC_PROP_ERC_SEVERITIES
const wxString DOC_PROP_SYM_LIB_TABLE
const wxString DOC_PROP_NET_CLASSES
bool ApplyProjectFilePatch(nlohmann::json &aTarget, const nlohmann::json &aSource, const wxString &aDocProp, DOC_KIND aKind)
Copy the JSON sub-tree located at the pointer for aDocProp from aSource into aTarget.
const wxString DOC_PROP_CUSTOM_RULES
const wxString DOC_PROP_FP_LIB_TABLE
const wxString DOC_PROP_DRAWING_SHEET
const wxString DOC_PROP_DRC_SEVERITIES
std::optional< std::string > DocPropJsonPointer(const wxString &aDocProp, DOC_KIND aKind)
Return the JSON pointer (RFC 6901, slash-separated) under which aDocProp is persisted in a ....
bool ApplyProjectFilePatches(const wxString &aOutputProPath, const nlohmann::json &aSource, const std::set< wxString > &aDocProps, DOC_KIND aKind)
Higher-level orchestrator: load the existing aOutputProPath as JSON (or start from aSource if the fil...
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(DocPropPointerMappingDrcSeverities)
BOOST_CHECK_EQUAL(result, "25.4")
wxString dump(const wxArrayString &aArray)
Debug helper for printing wxArrayString contents.