KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_erc_lib_symbol_field_position.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
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 3
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU 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, you may find one at
18 * http://www.gnu.org/licenses/
19 */
20
21#include <boost/test/unit_test.hpp>
22#include <lib_symbol.h>
23#include <sch_field.h>
24#include <sch_item.h>
26
27// Issue #24657: a pure field position change must not trip the ERC lib-symbol
28// mismatch check, matching the behavior when the field is moved in the schematic.
29
30BOOST_AUTO_TEST_SUITE( ERCLibSymbolFieldPosition )
31
32
33BOOST_AUTO_TEST_CASE( Issue24657FieldPositionIgnoredForERC )
34{
35 LIB_SYMBOL original( "R" );
36
37 original.GetValueField().SetText( wxS( "R" ) );
38 original.GetValueField().SetTextPos( VECTOR2I( 0, 0 ) );
39
40 // Move only the value field's position, leaving everything else untouched.
41 LIB_SYMBOL moved( original );
42 moved.GetValueField().SetTextPos( VECTOR2I( 0, 254000 ) );
43
44 int flags = ~SCH_ITEM::COMPARE_FLAGS::UUID;
45 flags &= ~SCH_ITEM::COMPARE_FLAGS::UNIT;
46 flags &= ~SCH_ITEM::COMPARE_FLAGS::IDENTITY;
47 flags &= ~SCH_ITEM::COMPARE_FLAGS::FIELD_POSITIONS;
48
49 int result = original.Compare( moved, flags );
50
51 BOOST_CHECK_MESSAGE( result == 0,
52 "ERC lib-symbol comparison flagged a pure field position change "
53 "(Compare returned " << result << "); expected 0 to match the "
54 "schematic-side move behavior (issue #24657)." );
55
56 // And, one more time to check the less-used case (where the user *does* want it to
57 // flag field position changes).
58 flags = ~SCH_ITEM::COMPARE_FLAGS::UUID;
59 flags &= ~SCH_ITEM::COMPARE_FLAGS::UNIT;
60 flags &= ~SCH_ITEM::COMPARE_FLAGS::IDENTITY;
61
62 result = original.Compare( moved, flags );
63
64 BOOST_CHECK_MESSAGE( result != 0,
65 "ERC lib-symbol comparison failed to flag a pure field position "
66 "change when asked to check positions." );
67}
68
69
virtual void SetTextPos(const VECTOR2I &aPoint)
Definition eda_text.cpp:539
Define a library symbol object.
Definition lib_symbol.h:119
SCH_FIELD & GetValueField()
Return reference to the value field.
Definition lib_symbol.h:437
int Compare(const LIB_SYMBOL &aRhs, int aCompareFlags=~COMPARE_FLAGS::UNIT, REPORTER *aReporter=nullptr) const
Comparison test that can be used for operators.
void SetText(const wxString &aText) override
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition sch_item.h:165
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_SUITE_END()
bool moved
wxString result
Test unit parsing edge cases and error handling.
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683