KiCad PCB EDA Suite
test_altium_parser.cpp File Reference

Test suite for ALTIUM_PARSER. More...

Go to the source code of this file.

Classes

struct  ALTIUM_PARSER_FIXTURE
 
struct  ALTIUM_TO_KICAD_UNIT_CASE
 Declares the struct as the Boost test fixture. More...
 
struct  READ_KICAD_UNIT_CASE
 
struct  READ_PROPERTIES_CASE
 

Functions

 BOOST_AUTO_TEST_CASE (ConvertToKicadUnit)
 Test conversation from Altium internal units into KiCad internal units. More...
 
 BOOST_AUTO_TEST_CASE (PropertiesReadKicadUnit)
 Test conversation from Unit property into KiCad internal units. More...
 
 BOOST_AUTO_TEST_CASE (ReadProperties)
 Test conversation from binary to properties. More...
 

Variables

static const std::vector< ALTIUM_TO_KICAD_UNIT_CASEaltium_to_kicad_unit
 A list of valid internal unit conversation factors Rem: altium to kicad importer rounds coordinates to the near 10 nm value when converting altium values in 0.01 mil to pcbnew units (1 nm) More...
 
static const std::vector< READ_KICAD_UNIT_CASEread_kicad_unit_property
 A list of valid test strings and the expected results. More...
 
static const std::vector< READ_PROPERTIES_CASEread_properties
 A list of valid test strings and the expected result map. More...
 

Detailed Description

Test suite for ALTIUM_PARSER.

Definition in file test_altium_parser.cpp.

Function Documentation

◆ BOOST_AUTO_TEST_CASE() [1/3]

BOOST_AUTO_TEST_CASE ( ConvertToKicadUnit  )

Test conversation from Altium internal units into KiCad internal units.

Definition at line 129 of file test_altium_parser.cpp.

130{
131 for( const auto& c : altium_to_kicad_unit )
132 {
133 BOOST_TEST_CONTEXT( wxString::Format( wxT( "%i -> %i" ), c.input, c.exp_result ) )
134 {
135 int result = ALTIUM_PARSER::ConvertToKicadUnit( c.input );
136
137 // These are all valid
138 BOOST_CHECK_EQUAL( result, c.exp_result );
139 }
140 }
141}
static int32_t ConvertToKicadUnit(const double aValue)
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
static const std::vector< ALTIUM_TO_KICAD_UNIT_CASE > altium_to_kicad_unit
A list of valid internal unit conversation factors Rem: altium to kicad importer rounds coordinates t...
#define BOOST_TEST_CONTEXT(A)

References altium_to_kicad_unit, BOOST_TEST_CONTEXT, ALTIUM_PARSER::ConvertToKicadUnit(), and Format().

◆ BOOST_AUTO_TEST_CASE() [2/3]

BOOST_AUTO_TEST_CASE ( PropertiesReadKicadUnit  )

Test conversation from Unit property into KiCad internal units.

Definition at line 204 of file test_altium_parser.cpp.

205{
206 for( const auto& c : read_kicad_unit_property )
207 {
208 BOOST_TEST_CONTEXT( c.input + " -> " + wxString::Format( wxT( "%i" ), c.exp_result ) )
209 {
210 std::map<wxString, wxString> properties = { { "TEST", c.input } };
211
212 int result = ALTIUM_PARSER::ReadKicadUnit( properties, "TEST", "0mil" );
213
214 // These are all valid
215 BOOST_CHECK_EQUAL( result, c.exp_result );
216 }
217 }
218}
int32_t ReadKicadUnit()
static const std::vector< READ_KICAD_UNIT_CASE > read_kicad_unit_property
A list of valid test strings and the expected results.

References BOOST_TEST_CONTEXT, Format(), read_kicad_unit_property, and ALTIUM_PARSER::ReadKicadUnit().

◆ BOOST_AUTO_TEST_CASE() [3/3]

BOOST_AUTO_TEST_CASE ( ReadProperties  )

Test conversation from binary to properties.

Definition at line 278 of file test_altium_parser.cpp.

279{
280 for( const auto& c : read_properties )
281 {
282 BOOST_TEST_CONTEXT( wxString::Format( wxT( "'%s'" ), c.input ) )
283 {
284 size_t size = 4 + c.input.size();
285 std::unique_ptr<char[]> content = std::make_unique<char[]>( size );
286
287 *content.get() = c.input.size();
288 std::memcpy( content.get() + 4, c.input.c_str(), c.input.size() );
289
290 ALTIUM_PARSER parser( content, size );
291
292 std::map<wxString, wxString> result = parser.ReadProperties();
293
294 BOOST_CHECK_EQUAL( parser.HasParsingError(), false );
295 BOOST_CHECK_EQUAL( parser.GetRemainingBytes(), 0 );
296
297 BOOST_CHECK_EQUAL( result.size(), c.exp_result.size() );
298 for( const auto& kv : c.exp_result )
299 {
300 BOOST_CHECK_EQUAL( 1, result.count( kv.first ) );
301 BOOST_CHECK_EQUAL( result.at( kv.first ), kv.second );
302 }
303 }
304 }
305}
static const std::vector< READ_PROPERTIES_CASE > read_properties
A list of valid test strings and the expected result map.
#define kv

References BOOST_TEST_CONTEXT, Format(), ALTIUM_PARSER::GetRemainingBytes(), ALTIUM_PARSER::HasParsingError(), kv, read_properties, and ALTIUM_PARSER::ReadProperties().

Variable Documentation

◆ altium_to_kicad_unit

const std::vector<ALTIUM_TO_KICAD_UNIT_CASE> altium_to_kicad_unit
static

A list of valid internal unit conversation factors Rem: altium to kicad importer rounds coordinates to the near 10 nm value when converting altium values in 0.01 mil to pcbnew units (1 nm)

Definition at line 55 of file test_altium_parser.cpp.

Referenced by BOOST_AUTO_TEST_CASE().

◆ read_kicad_unit_property

const std::vector<READ_KICAD_UNIT_CASE> read_kicad_unit_property
static

A list of valid test strings and the expected results.

Definition at line 152 of file test_altium_parser.cpp.

Referenced by BOOST_AUTO_TEST_CASE().

◆ read_properties

const std::vector<READ_PROPERTIES_CASE> read_properties
static

A list of valid test strings and the expected result map.

Definition at line 229 of file test_altium_parser.cpp.

Referenced by BOOST_AUTO_TEST_CASE().