KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_snapping_options.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, see <https://www.gnu.org/licenses/>.
18 */
19
20#define BOOST_TEST_NO_MAIN
21#include <boost/test/unit_test.hpp>
22
23#include <algorithm>
24
26
27
28BOOST_AUTO_TEST_SUITE( SnappingOptions )
29
30
31BOOST_AUTO_TEST_CASE( RoutingEditorsOfferTheRouterOnlyMode )
32{
33 std::vector<MAGNETIC_OPTIONS> routing = MagneticSnapOptions( true );
34 std::vector<MAGNETIC_OPTIONS> plain = MagneticSnapOptions( false );
35
36 BOOST_CHECK_EQUAL( routing.size(), 3u );
37 BOOST_CHECK_EQUAL( plain.size(), 2u );
38
39 BOOST_CHECK( routing[1] == MAGNETIC_OPTIONS::CAPTURE_CURSOR_IN_TRACK_TOOL );
40 BOOST_CHECK( std::find( plain.begin(), plain.end(), MAGNETIC_OPTIONS::CAPTURE_CURSOR_IN_TRACK_TOOL )
41 == plain.end() );
42}
43
44
45BOOST_AUTO_TEST_CASE( EveryOfferedOptionRoundTrips )
46{
47 for( bool routing : { false, true } )
48 {
49 std::vector<MAGNETIC_OPTIONS> options = MagneticSnapOptions( routing );
50
51 for( MAGNETIC_OPTIONS option : options )
52 {
53 int index = MagneticSnapIndex( options, option );
54 BOOST_CHECK( MagneticSnapValue( options, index ) == option );
55 }
56 }
57}
58
59
60BOOST_AUTO_TEST_CASE( UnofferedOptionReadsBackAsNever )
61{
62 // The footprint editor has no router, and its grid helper snaps to pads only in the "always"
63 // mode, so a router-only value left in the config must not read back as any kind of snapping.
64 std::vector<MAGNETIC_OPTIONS> options = MagneticSnapOptions( false );
66
67 BOOST_CHECK( MagneticSnapValue( options, index ) == MAGNETIC_OPTIONS::NO_EFFECT );
68}
69
70
71BOOST_AUTO_TEST_CASE( OutOfRangeIndexIsNever )
72{
73 std::vector<MAGNETIC_OPTIONS> options = MagneticSnapOptions( true );
74
75 // wxChoice reports wxNOT_FOUND when nothing is selected.
76 BOOST_CHECK( MagneticSnapValue( options, -1 ) == MAGNETIC_OPTIONS::NO_EFFECT );
77 BOOST_CHECK( MagneticSnapValue( options, 3 ) == MAGNETIC_OPTIONS::NO_EFFECT );
78}
79
80
int index
int MagneticSnapIndex(const std::vector< MAGNETIC_OPTIONS > &aOptions, MAGNETIC_OPTIONS aValue)
The position of aValue in aOptions, falling back to the "never" entry for a value the editor does not...
std::vector< MAGNETIC_OPTIONS > MagneticSnapOptions(bool aRouting)
The object snapping modes an editor offers.
MAGNETIC_OPTIONS MagneticSnapValue(const std::vector< MAGNETIC_OPTIONS > &aOptions, int aIndex)
The mode at aIndex, or "never" if the index is out of range.
MAGNETIC_OPTIONS
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(RoutingEditorsOfferTheRouterOnlyMode)
BOOST_CHECK_EQUAL(result, "25.4")