20#include <boost/test/unit_test.hpp>
48 wxString( wxS(
"bom-.csv" ) ) );
51 wxString( wxS(
"out-A_B.zip" ) ) );
53 wxString( wxS(
"bom-A/B.csv" ) ) );
59 job.
FromJson( nlohmann::json{ {
"variant",
"Variant A" } } );
77 nlohmann::json missingKeys = nlohmann::json::object();
81 nlohmann::json odbJson;
85 BOOST_CHECK( !odbJson.at(
"check_zones" ).get<
bool>() );
86 BOOST_CHECK( odbJson.at(
"board_metadata" ).get<
bool>() );
91 nlohmann::json ipcJson;
95 BOOST_CHECK( !ipcJson.value(
"check_zones",
true ) );
99 nlohmann::json emptyVariant = { {
"variant",
"" } };
112 std::ifstream odbFile( fixtureDir /
"odb_job_v10.json" );
113 std::ifstream ipcFile( fixtureDir /
"ipc2581_job_v10.json" );
116 nlohmann::json odbV10 = nlohmann::json::parse( odbFile );
117 nlohmann::json ipcV10 = nlohmann::json::parse( ipcFile );
121 nlohmann::json odbRoundTrip;
122 odb.
ToJson( odbRoundTrip );
124 for(
auto it = odbV10.begin(); it != odbV10.end(); ++it )
126 BOOST_CHECK_MESSAGE( odbRoundTrip.at( it.key() ) == it.value(),
"ODB key " << it.key() );
131 nlohmann::json ipcRoundTrip;
132 ipc.
ToJson( ipcRoundTrip );
134 for(
auto it = ipcV10.begin(); it != ipcV10.end(); ++it )
136 BOOST_CHECK_MESSAGE( ipcRoundTrip.at( it.key() ) == it.value(),
"IPC key " << it.key() );
139 BOOST_CHECK( odbRoundTrip.contains(
"variant_names" ) );
140 BOOST_CHECK( ipcRoundTrip.contains(
"variant_names" ) );
161 job.
FromJson( nlohmann::json{ {
"mode",
"FABRICATION" },
162 {
"sections",
"KE" },
163 {
"net_names",
"anonymize" },
164 {
"ref_des",
"omit" } } );
165 BOOST_CHECK( job.
m_dataSet == DATA_SET::FABRICATION );
174 BOOST_CHECK( !
json.contains(
"mode" ) );
178 BOOST_CHECK( reloaded.
m_dataSet == DATA_SET::FABRICATION );
181 unset.
FromJson( nlohmann::json{ {
"mode",
"" }, {
"net_names",
"" }, {
"ref_des",
"" } } );
182 BOOST_CHECK( unset.
m_dataSet == DATA_SET::USERDEF );
188 bogus.
FromJson( nlohmann::json{ {
"mode",
"bogus" } } );
189 BOOST_CHECK( bogus.
m_dataSet == DATA_SET::COUNT );
195 bogusOdb.
FromJson( nlohmann::json{ {
"data_set",
"bogus" } } );
196 BOOST_CHECK( bogusOdb.
m_dataSet == DATA_SET::COUNT );
213 ipc.
FromJson( nlohmann::json{ {
"field_bom_map.mfg_pn",
"IPC-MPN" } } );
214 nlohmann::json ipcJson;
216 BOOST_CHECK_EQUAL( ipcJson.at(
"field_bom_map.mfg_pn" ).get<std::string>(),
"IPC-MPN" );
222 nlohmann::json options = { {
"origin",
"aux" },
223 {
"product_name",
"Fab Rev A" },
224 {
"data_set",
"assembly" },
225 {
"sections",
"ACOP" },
226 {
"board_metadata",
false },
227 {
"net_names",
"anonymize" },
228 {
"layers", nlohmann::json::array( { { {
"layer",
"F.Cu" },
229 {
"include",
false },
230 {
"odb_name",
"front_copper" },
231 {
"odb_type",
"SIGNAL" } } } ) } };
237 for(
auto it = options.begin(); it != options.end(); ++it )
238 BOOST_CHECK_MESSAGE(
roundTrip.contains( it.key() ) &&
roundTrip[it.key()] == it.value(), it.key() );
242 nlohmann::json again;
252 {
"layers", nlohmann::json::array( { { {
"layer",
"F.Cu" }, {
"include",
"not-a-boolean" } },
253 { {
"layer",
"B.Cu" }, {
"odb_name", 12 } },
254 { {
"layer",
"In1.Cu" }, {
"odb_type",
false } } } ) } } );
266 job.
m_layerOverrides.push_back( {
F_Cu,
true, wxString::FromUTF8(
"Résumé_日本" ), wxS(
"SIGNAL" ) } );
270 struct RESTORE_LOCALE
272 std::string m_previous = std::setlocale( LC_CTYPE,
nullptr );
273 ~RESTORE_LOCALE() { std::setlocale( LC_CTYPE, m_previous.c_str() ); }
287 nlohmann::json options = { {
"check_zones",
true } };
291 BOOST_CHECK(
roundTrip.value(
"check_zones",
false ) );
308 BOOST_CHECK( loaded.
m_variant == wxS(
"var-A" ) );
325 BOOST_CHECK( loaded.
m_variant == wxS(
"VarPlot" ) );
368 job.
FromJson( nlohmann::json{ {
"mode",
"USERDEF" }, {
"sections",
"" }, {
"custom_sections",
true } } );
370 nlohmann::json saved;
372 BOOST_CHECK( saved.value(
"custom_sections",
false ) );
379 BOOST_CHECK(
roundTrip.value(
"custom_sections",
false ) );
382 legacy.
FromJson( nlohmann::json{ {
"sections",
"" } } );
383 nlohmann::json legacyJson;
384 legacy.
ToJson( legacyJson );
385 BOOST_CHECK( !legacyJson.value(
"custom_sections",
false ) );
389 legacyNonempty.
FromJson( nlohmann::json{ {
"sections",
"K" } } );
407 BOOST_CHECK( loaded.
m_variant == wxS(
"VarRender" ) );
void FromJson(const nlohmann::json &aJson) override
DATA_SET
Columns of the IPC-2581C function mode table, Table 4 p 80.
static std::string DataSetToken(DATA_SET aDataSet)
Lower case token that the job file and the CLI use for aDataSet Empty when it has none.
void ToJson(nlohmann::json &aJson) const override
std::optional< wxString > m_sections
Section key that replaces the optional sections of the data set Unset lets the data set select them a...
std::vector< wxString > m_variantNames
void FromJson(const nlohmann::json &aJson) override
VARIANT_PACKAGING m_variantPackaging
std::vector< ODB_LAYER_OVERRIDE > m_layerOverrides
std::vector< wxString > m_variantNames
std::vector< wxString > m_variantNames
virtual void FromJson(const nlohmann::json &j)
virtual void ToJson(nlohmann::json &j) const
static bool empty(const wxTextEntryBase *aCtrl)
std::string GetTestDataRootDir()
wxString GetDefaultVariantName()
wxString ExpandVariantOutputPath(const wxString &aPath, const wxString &aVariantToken)
wxString GetVariantFileToken(const wxString &aVariantName)
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
static void roundTrip(const DIFF_VALUE &aValue)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(OdbVariantFileTokenKeepsNamesAndRemovesSeparators)
BOOST_CHECK_EQUAL(result, "25.4")