KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_connectivity_claims.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 <algorithm>
24#include <vector>
25
26using namespace SCH_CONNECTIVITY;
27
28BOOST_AUTO_TEST_SUITE( ConnectivityClaims )
29
30BOOST_AUTO_TEST_CASE( AliasContainmentCannotCreateComparatorCycles )
31{
32 SESSION_KEYS keys;
33 const INST_ID instance = keys.InternInstance( KIID_PATH() );
34 std::vector<CLAIM> claims;
35 const BUS_ALIASES aliases{ { "A", { "D0" } }, { "B", { "D1" } }, { "C", { "D0", "D2" } } };
36
37 for( const wxString& name : { wxString( "{A}" ), wxString( "{B}" ), wxString( "{C}" ) } )
38 {
39 CLAIM claim;
41 claim.source = { niluuid, instance };
42 claim.path = keys.InternName( wxString() );
43 claim.name = claim.ncName = claim.fullName = keys.InternName( name );
44 claim.schema = std::make_shared<const BUS_SCHEMA>( *BUS_SCHEMA::Parse( name, aliases ) );
45 claims.push_back( std::move( claim ) );
46 }
47
48 const CLAIM_LESS less{ keys };
49 BOOST_CHECK( less( claims[1], claims[0] ) );
50 BOOST_CHECK( less( claims[2], claims[0] ) );
51 BOOST_CHECK( less( claims[2], claims[1] ) );
52 const std::vector<NAME_ID> expected{ claims[0].name, claims[1].name, claims[2].name };
53 std::vector<size_t> order{ 0, 1, 2 };
54
55 do
56 {
57 std::vector<CLAIM> permuted;
58
59 for( size_t i : order )
60 permuted.push_back( claims[i] );
61
62 std::sort( permuted.begin(), permuted.end(),
63 [&]( const CLAIM& a, const CLAIM& b )
64 {
65 return less( b, a );
66 } );
67
68 for( size_t i = 0; i < expected.size(); ++i )
69 BOOST_CHECK_EQUAL( permuted[i].name, expected[i] );
70 } while( std::next_permutation( order.begin(), order.end() ) );
71
72 claims[0].depth = 1;
73 claims[2].depth = 2;
74 BOOST_CHECK( less( claims[2], claims[0] ) );
75 claims[2].priority = PRIORITY::GLOBAL;
76 BOOST_CHECK( less( claims[0], claims[2] ) );
77}
78
const char * name
Session IDs are dense handles, never a canonical ordering.
Definition conn_keys.h:146
INST_ID InternInstance(const KIID_PATH &aPath)
Definition conn_keys.h:152
NAME_ID InternName(const wxString &aText)
Definition conn_keys.h:153
KIID niluuid(0)
Value keys and the key session of the schematic connectivity engine.
std::map< wxString, std::vector< wxString > > BUS_ALIASES
Bus alias table, from alias name to member texts.
Definition conn_bus.h:40
uint32_t INST_ID
Session handle of a sheet instance KIID_PATH.
Definition conn_keys.h:41
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
Strict weak order on claims by value.
Definition conn_claims.h:77
The claim of one item for the name of its island.
Definition conn_claims.h:53
ITEM_KEY source
The claiming item, the last tie-break.
Definition conn_claims.h:60
NAME_ID ncName
Name of an unconnected pin net.
Definition conn_claims.h:58
NAME_ID name
Item text without the sheet prefix.
Definition conn_claims.h:57
std::shared_ptr< const BUS_SCHEMA > schema
Parsed bus, or null for a signal.
Definition conn_claims.h:65
NAME_ID path
Sheet prefix, or the empty name if unscoped.
Definition conn_claims.h:56
NAME_ID fullName
path followed by name.
Definition conn_claims.h:59
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_SUITE_END()
VECTOR3I expected(15, 30, 45)
BOOST_CHECK_EQUAL(result, "25.4")