KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_connectivity_bus.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
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
22
23#include <limits>
24
25using namespace SCH_CONNECTIVITY;
26
27BOOST_AUTO_TEST_SUITE( ConnectivityBus )
28
29BOOST_AUTO_TEST_CASE( PreservesFormattedVectorNames )
30{
31 const auto schema = BUS_SCHEMA::Parse( "~{BE[0..3]}" );
32 BOOST_REQUIRE( schema );
33 BOOST_CHECK( schema->shape == BUS_SCHEMA::SHAPE::VECTOR );
34 BOOST_REQUIRE_EQUAL( schema->leaves.size(), 4 );
35 BOOST_CHECK_EQUAL( schema->leaves[0].name, wxString( "~{BE0}" ) );
36 BOOST_CHECK_EQUAL( schema->leaves[3].name, wxString( "~{BE3}" ) );
37
38 const auto subscript = BUS_SCHEMA::Parse( "D_{[1..2]}" );
39 BOOST_REQUIRE( subscript );
40 BOOST_CHECK_EQUAL( subscript->leaves[0].name, wxString( "D1" ) );
41}
42
43BOOST_AUTO_TEST_CASE( PreservesZeroPaddedMemberIdentity )
44{
45 const auto schema = BUS_SCHEMA::Parse( "D[01..03]" );
46 BOOST_REQUIRE( schema );
47 BOOST_REQUIRE_EQUAL( schema->leaves.size(), 3 );
48 BOOST_CHECK_EQUAL( schema->leaves[0].name, wxString( "D01" ) );
49 BOOST_CHECK_EQUAL( schema->leaves[2].name, wxString( "D03" ) );
50
51 const auto group = BUS_SCHEMA::Parse( "BUS{D01 D1 D01}" );
53 BOOST_REQUIRE_EQUAL( group->leaves.size(), 3 );
54 BOOST_CHECK_EQUAL( group->leaves[0].name, wxString( "BUS.D01" ) );
55 BOOST_CHECK_EQUAL( group->leaves[1].name, wxString( "BUS.D1" ) );
56 BOOST_CHECK( group->leaves[0] == group->leaves[2] );
57}
58
59BOOST_AUTO_TEST_CASE( PreservesQuotingEscapingAndFormatting )
60{
61 const auto quoted = BUS_SCHEMA::Parse( "\"Data Bus\"[1..2]" );
62 const auto escaped = BUS_SCHEMA::Parse( "Data\\ Bus[1..2]" );
63 BOOST_REQUIRE( quoted );
64 BOOST_REQUIRE( escaped );
65 BOOST_CHECK( quoted->leaves == escaped->leaves );
66 BOOST_CHECK_EQUAL( quoted->leaves[0].name, wxString( "Data Bus1" ) );
67
68 const auto group = BUS_SCHEMA::Parse( "I^{2}C{R{slash}~{W} D01}" );
70 BOOST_CHECK_EQUAL( group->leaves[0].name, wxString( "I^{2}C.R{slash}~{W}" ) );
71}
72
73BOOST_AUTO_TEST_CASE( RejectsAliasCycles )
74{
75 BOOST_CHECK( !BUS_SCHEMA::Parse( "{A}", { { "A", { "B" } }, { "B", { "A" } } } ) );
76 BOOST_CHECK( !BUS_SCHEMA::Parse( "{A}", { { "A", { "A" } } } ) );
77}
78
79BOOST_AUTO_TEST_CASE( RejectsScalarAndInvalidGroupText )
80{
81 BOOST_CHECK( !BUS_SCHEMA::Parse( "D01" ) );
82 BOOST_CHECK( !BUS_SCHEMA::Parse( "Data Bus[0..3]" ) );
83 BOOST_CHECK( !BUS_SCHEMA::Parse( "BUS{A B" ) );
84}
85
86BOOST_AUTO_TEST_CASE( ParsesQuotedAndEscapedGroupMembersOnce )
87{
88 const auto schema = BUS_SCHEMA::Parse( "BUS{\"Net One\" Net\\ Two R{slash}W}" );
89 BOOST_REQUIRE( schema );
90 BOOST_REQUIRE_EQUAL( schema->leaves.size(), 3 );
91 BOOST_CHECK_EQUAL( schema->leaves[0].name, wxString( "BUS.Net One" ) );
92 BOOST_CHECK_EQUAL( schema->leaves[1].name, wxString( "BUS.Net Two" ) );
93 BOOST_CHECK_EQUAL( schema->leaves[2].name, wxString( "BUS.R{slash}W" ) );
94}
95
96BOOST_AUTO_TEST_CASE( RejectsMalformedAndOverflowingVectorRanges )
97{
98 BOOST_CHECK( !BUS_SCHEMA::Parse( "D[-1..2]" ) );
99 BOOST_CHECK( !BUS_SCHEMA::Parse( "D[1..-2]" ) );
100 BOOST_CHECK( !BUS_SCHEMA::Parse( "D[..2]" ) );
101 BOOST_CHECK( !BUS_SCHEMA::Parse( "D[1..]" ) );
102 BOOST_CHECK( !BUS_SCHEMA::Parse( "D[1..2" ) );
103 BOOST_CHECK( !BUS_SCHEMA::Parse( "D[1..999999999999999999999999999999]" ) );
104 const wxString largest = wxString::Format( "%ld", std::numeric_limits<long>::max() );
105 BOOST_CHECK( !BUS_SCHEMA::Parse( "D[1.." + largest + "0]" ) );
106}
107
Value keys and the key session of the schematic connectivity engine.
@ VECTOR
A range such as D[0..3]. Members align by ordinal.
Definition conn_bus.h:51
static std::optional< BUS_SCHEMA > Parse(const wxString &aText, const BUS_ALIASES &aAliases={})
Parse a vector or group bus text.
Definition conn_bus.cpp:186
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_CASE(PreservesFormattedVectorNames)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END()
BOOST_CHECK_EQUAL(result, "25.4")