KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_pads_sch_binary_reader.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your option)
9 * any later version.
10 */
11
12#include <boost/test/unit_test.hpp>
14
16
17#include <ki_exception.h>
18
19namespace
20{
22
23wxString fixture( const wxString& aName )
24{
25 return wxString::FromUTF8( KI_TEST::GetEeschemaTestDataDir() ) + wxS( "/plugins/pads/binary/" ) + aName
26 + wxS( ".sch" );
27}
28
29
30std::vector<uint8_t> fixtureBytes( const wxString& aName )
31{
32 std::vector<uint8_t> bytes;
33 BOOST_REQUIRE( PADS_SCH_BINARY_READER::ReadFile( fixture( aName ), bytes ) );
34 return bytes;
35}
36}
37
38
39BOOST_AUTO_TEST_SUITE( PadsSchBinaryReader )
40
41
42BOOST_AUTO_TEST_CASE( RecognizesFamilyIndependentlyOfVersionSupport )
43{
44 std::vector<uint8_t> bytes = fixtureBytes( wxS( "minimal_v13" ) );
45 BOOST_CHECK( PADS_SCH_BINARY_READER::IsBinaryFamily( bytes ) );
46 BOOST_CHECK( PADS_SCH_BINARY_READER::IsBinarySch( bytes ) );
47 BOOST_CHECK( PADS_SCH_BINARY_READER::IsSupportedVersion( 0x000C ) );
48 BOOST_CHECK( PADS_SCH_BINARY_READER::IsSupportedVersion( 0x000D ) );
49
50 bytes[2] = 0x00;
51 bytes[3] = 0xFE;
52 BOOST_CHECK( PADS_SCH_BINARY_READER::IsBinaryFamily( bytes ) );
53 BOOST_CHECK( PADS_SCH_BINARY_READER::IsBinarySch( bytes ) );
54 BOOST_CHECK( !PADS_SCH_BINARY_READER::IsSupportedVersion( 0xFE00 ) );
55
56 bytes[1] = 0xFF;
57 BOOST_CHECK( !PADS_SCH_BINARY_READER::IsBinaryFamily( bytes ) );
58 BOOST_CHECK( !PADS_SCH_BINARY_READER::IsBinarySch( bytes ) );
59 BOOST_CHECK( !PADS_SCH_BINARY_READER::IsBinaryFamily( { 0x00 } ) );
60 BOOST_CHECK( PADS_SCH_BINARY_READER::IsBinaryFamily( { 0x00, 0xFE } ) );
61 BOOST_CHECK( PADS_SCH_BINARY_READER::IsBinaryFamily( { 0x00, 0xFE, 0x0D } ) );
62 BOOST_CHECK( PADS_SCH_BINARY_READER::IsBinaryFamily( { 0x00, 0xFE, 0x0D, 0x00 } ) );
63 BOOST_CHECK( !PADS_SCH_BINARY_READER::IsBinaryFamily( std::vector<uint8_t>( 31, 0x00 ) ) );
64
65 std::vector<uint8_t> truncatedHeader( 31, 0x00 );
66 truncatedHeader[1] = 0xFE;
67 BOOST_CHECK( PADS_SCH_BINARY_READER::IsBinaryFamily( truncatedHeader ) );
68}
69
70
71BOOST_AUTO_TEST_CASE( OwnsTypedParserModel )
72{
73 PADS_SCH_BINARY_READER reader;
74 std::vector<uint8_t> bytes = fixtureBytes( wxS( "connectivity_topology" ) );
75 BOOST_REQUIRE( reader.Parse( bytes, fixture( wxS( "connectivity_topology" ) ) ) );
76 BOOST_CHECK_EQUAL( reader.GetModel().version, 0x000D );
77 BOOST_CHECK( !reader.GetModel().sheets.empty() );
78 BOOST_CHECK( !reader.GetModel().nets.empty() );
79 BOOST_CHECK( !reader.GetModel().buses.empty() );
80 BOOST_CHECK( !reader.GetModel().labels.empty() );
81}
82
83
84BOOST_AUTO_TEST_CASE( ParseRejectsMalformedAndReportsUnsupportedVersion )
85{
86 PADS_SCH_BINARY_READER reader;
87 BOOST_CHECK_THROW( reader.Parse( { 0x00, 0xFE }, wxS( "truncated.sch" ) ), IO_ERROR );
88 BOOST_CHECK_THROW( reader.GetModel(), IO_ERROR );
89
90 std::vector<uint8_t> bytes = fixtureBytes( wxS( "minimal_v13" ) );
91 bytes[2] = 0x00;
92 bytes[3] = 0xFE;
93 wxString message;
94
95 try
96 {
97 reader.Parse( bytes, wxS( "unsupported.sch" ) );
98 BOOST_FAIL( "unsupported binary schematic was accepted" );
99 }
100 catch( const IO_ERROR& error )
101 {
102 message = error.What();
103 }
104
105 BOOST_CHECK( message.Contains( wxS( "v0xFE00" ) ) );
106 BOOST_CHECK( message.Contains( wxS( "unsupported PADS Logic binary version" ) ) );
107 BOOST_CHECK_THROW( reader.GetModel(), IO_ERROR );
108}
109
110
111BOOST_AUTO_TEST_CASE( ParseReplacesOwnedModel )
112{
113 PADS_SCH_BINARY_READER reader;
114 BOOST_REQUIRE( reader.Parse( fixtureBytes( wxS( "minimal_v13" ) ), fixture( wxS( "minimal_v13" ) ) ) );
115 const size_t firstPlacements = reader.GetModel().placements.size();
117 reader.Parse( fixtureBytes( wxS( "placement_transform" ) ), fixture( wxS( "placement_transform" ) ) ) );
118 BOOST_CHECK_NE( reader.GetModel().placements.size(), firstPlacements );
119 BOOST_CHECK_EQUAL( reader.GetModel().settings.source.file, fixture( wxS( "placement_transform" ) ) );
120}
121
122
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
virtual const wxString What() const
A composite of Problem() and Where()
std::string GetEeschemaTestDataDir()
Get the configured location of Eeschema test data.
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(RecognizesFamilyIndependentlyOfVersionSupport)
BOOST_CHECK_EQUAL(result, "25.4")