24#include <boost/test/unit_test.hpp>
33#include <wx/filename.h>
34#include <wx/stdpaths.h>
35#include <wx/datetime.h>
112 {
"board", { {
"design_settings", { {
"rule_severities", { {
"old_key",
"warning" } } } } } } },
113 {
"text_variables", { {
"USER_VAR",
"user value" } } },
114 {
"schematic", { {
"legacy_lib_dir",
"/old/path" } } }
118 {
"board", { {
"design_settings", { {
"rule_severities", { {
"new_key",
"error" } } } } } } }
124 BOOST_CHECK_EQUAL( target[
"board"][
"design_settings"][
"rule_severities"][
"new_key"],
"error" );
125 BOOST_CHECK( !target[
"board"][
"design_settings"][
"rule_severities"].contains(
"old_key" ) );
137 json target = { {
"board", { {
"design_settings", { {
"rule_severities", { {
"k",
"warning" } } } } } } } };
138 json source = { {
"unrelated",
"value" } };
141 BOOST_CHECK_EQUAL( target[
"board"][
"design_settings"][
"rule_severities"][
"k"],
"warning" );
149 json target = json::object();
150 json source = { {
"anything", 1 } };
160 {
"net_settings", { {
"classes", json::array() } } },
161 {
"schematic", { {
"preserved",
true } } }
166 {
"classes", { { {
"name",
"HighSpeed" }, {
"priority", 1 } } } },
167 {
"netclass_patterns", { { {
"pattern",
"DDR_*" }, {
"netclass",
"HighSpeed" } } } }
182 {
"pcbnew", { {
"page_layout_descr_file",
"target-pcb.kicad_wks" } } },
183 {
"schematic", { {
"page_layout_descr_file",
"target-sch.kicad_wks" } } }
187 {
"pcbnew", { {
"page_layout_descr_file",
"source-pcb.kicad_wks" } } },
188 {
"schematic", { {
"page_layout_descr_file",
"source-sch.kicad_wks" } } }
193 BOOST_CHECK_EQUAL( target[
"schematic"][
"page_layout_descr_file"],
"source-sch.kicad_wks" );
194 BOOST_CHECK_EQUAL( target[
"pcbnew"][
"page_layout_descr_file"],
"target-pcb.kicad_wks" );
202 wxString tmpDir = wxStandardPaths::Get().GetTempDir() + wxFILE_SEP_PATH
203 + wxS(
"kicad_patch_" )
204 + wxString::Format( wxS(
"%d" ),
205 static_cast<int>( wxDateTime::Now().GetValue().GetValue() & 0xffffff ) );
206 BOOST_REQUIRE( wxFileName::Mkdir( tmpDir, wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL ) );
208 const wxString outputPath = tmpDir + wxFILE_SEP_PATH + wxS(
"test.kicad_pro" );
211 json source = { {
"board", { {
"design_settings", { {
"rule_severities", { {
"k",
"error" } } } } } } } };
218 wxFile in( outputPath );
220 in.ReadAll( &content );
221 json parsed = json::parse( content.ToStdString() );
222 BOOST_CHECK_EQUAL( parsed[
"board"][
"design_settings"][
"rule_severities"][
"k"],
"error" );
224 wxRemoveFile( outputPath );
225 wxFileName::Rmdir( tmpDir );
231 wxString tmpDir = wxStandardPaths::Get().GetTempDir() + wxFILE_SEP_PATH
232 + wxS(
"kicad_patch_" )
233 + wxString::Format( wxS(
"%d" ),
234 static_cast<int>( wxDateTime::Now().GetValue().GetValue() & 0xffffff ) );
235 BOOST_REQUIRE( wxFileName::Mkdir( tmpDir, wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL ) );
237 const wxString outputPath = tmpDir + wxFILE_SEP_PATH + wxS(
"test.kicad_pro" );
240 json source = { {
"text_variables", { {
"USER_VAR",
"source value" } } } };
241 std::set<wxString> docProps;
244 BOOST_CHECK( !wxFileExists( outputPath ) );
246 if( wxFileExists( outputPath ) )
247 wxRemoveFile( outputPath );
249 wxFileName::Rmdir( tmpDir );
257 wxString tmpDir = wxStandardPaths::Get().GetTempDir() + wxFILE_SEP_PATH
258 + wxS(
"kicad_patch_" )
259 + wxString::Format( wxS(
"%d" ),
260 static_cast<int>( wxDateTime::Now().GetValue().GetValue() & 0xffffff ) );
261 BOOST_REQUIRE( wxFileName::Mkdir( tmpDir, wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL ) );
263 const wxString outputPath = tmpDir + wxFILE_SEP_PATH + wxS(
"test.kicad_pro" );
266 {
"text_variables", { {
"USER_VAR",
"user value" } } },
267 {
"board", { {
"design_settings", { {
"rule_severities", { {
"old",
"warning" } } } } } } }
273 BOOST_REQUIRE( out.Write( wxString::FromUTF8( existing.dump( 2 ) ) ) );
276 json source = { {
"board", { {
"design_settings", { {
"rule_severities", { {
"new",
"error" } } } } } } } };
281 wxFile in( outputPath );
283 in.ReadAll( &content );
284 json parsed = json::parse( content.ToStdString() );
286 BOOST_CHECK_EQUAL( parsed[
"board"][
"design_settings"][
"rule_severities"][
"new"],
"error" );
287 BOOST_CHECK( !parsed[
"board"][
"design_settings"][
"rule_severities"].contains(
"old" ) );
290 wxRemoveFile( outputPath );
291 wxFileName::Rmdir( tmpDir );
297 wxString tmpDir = wxStandardPaths::Get().GetTempDir() + wxFILE_SEP_PATH
298 + wxS(
"kicad_patch_" )
299 + wxString::Format( wxS(
"%d" ),
300 static_cast<int>( wxDateTime::Now().GetValue().GetValue() & 0xffffff ) );
301 BOOST_REQUIRE( wxFileName::Mkdir( tmpDir, wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL ) );
303 const wxString outputPath = tmpDir + wxFILE_SEP_PATH + wxS(
"test.kicad_pro" );
305 json existing = { {
"text_variables", { {
"USER_VAR",
"user value" } } } };
310 BOOST_REQUIRE( out.Write( wxString::FromUTF8( existing.dump( 2 ) ) ) );
313 json source = { {
"board", json::object() } };
318 wxFile in( outputPath );
320 in.ReadAll( &content );
321 json parsed = json::parse( content.ToStdString() );
324 wxRemoveFile( outputPath );
325 wxFileName::Rmdir( tmpDir );
337 {
"design_settings", {
338 {
"rule_severities", { {
"copper_edge_clearance",
"error" } } },
339 {
"rules", { {
"min_copper_edge_clearance", 0.5 } } },
340 {
"track_widths", json::array( { 0.2, 0.25 } ) }
343 {
"meta", { {
"filename",
"board.kicad_pro" } } }
348 {
"design_settings", {
349 {
"rule_severities", { {
"copper_edge_clearance",
"warning" } } },
350 {
"rules", { {
"min_copper_edge_clearance", 99.0 } } },
351 {
"track_widths", json::array( { 9.0 } ) }
359 BOOST_CHECK_EQUAL( existing[
"board"][
"design_settings"][
"rule_severities"][
"copper_edge_clearance"],
364 BOOST_CHECK_EQUAL( existing[
"board"][
"design_settings"][
"rules"][
"min_copper_edge_clearance"], 0.5 );
366 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.