KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_file_checklist_ctrl.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
21
23
24
25static FILE_CHECKLIST_ENTRY makeEntry( const wxString& aSection, const wxString& aPath, bool aChecked )
26{
28 entry.section = aSection;
29 entry.path = aPath;
30 entry.label = aPath.AfterLast( '/' );
31 entry.status = wxT( "Modified" );
33 entry.checked = aChecked;
34 return entry;
35}
36
37
38BOOST_AUTO_TEST_SUITE( FileChecklistData )
39
40
41BOOST_AUTO_TEST_CASE( SectionsAndRowsKeepInsertionOrder )
42{
44 data.SetEntries( {
45 makeEntry( wxT( "Changes" ), wxT( "proj/a.kicad_pcb" ), true ),
46 makeEntry( wxT( "Shared libraries" ), wxT( "libs/x.kicad_sym" ), true ),
47 makeEntry( wxT( "Changes" ), wxT( "proj/b.kicad_sch" ), true ),
48 } );
49
50 BOOST_REQUIRE_EQUAL( data.Sections().size(), 2 );
51 BOOST_CHECK_EQUAL( data.Sections()[0], wxT( "Changes" ) );
52 BOOST_CHECK_EQUAL( data.Sections()[1], wxT( "Shared libraries" ) );
53
54 const std::vector<FILE_CHECKLIST_ENTRY>& changes = data.Rows( wxT( "Changes" ) );
55 BOOST_REQUIRE_EQUAL( changes.size(), 2 );
56 BOOST_CHECK_EQUAL( changes[0].path, wxT( "proj/a.kicad_pcb" ) );
57 BOOST_CHECK_EQUAL( changes[1].path, wxT( "proj/b.kicad_sch" ) );
58}
59
60
61BOOST_AUTO_TEST_CASE( CheckedPathsReflectToggles )
62{
64 data.SetEntries( {
65 makeEntry( wxT( "Changes" ), wxT( "a" ), true ),
66 makeEntry( wxT( "Changes" ), wxT( "b" ), false ),
67 makeEntry( wxT( "Changes" ), wxT( "c" ), true ),
68 } );
69
70 std::vector<wxString> checked = data.CheckedPaths();
71 BOOST_REQUIRE_EQUAL( checked.size(), 2 );
72 BOOST_CHECK_EQUAL( checked[0], wxT( "a" ) );
73 BOOST_CHECK_EQUAL( checked[1], wxT( "c" ) );
74
75 data.SetChecked( wxT( "b" ), true );
76 data.SetChecked( wxT( "a" ), false );
77
78 checked = data.CheckedPaths();
79 BOOST_REQUIRE_EQUAL( checked.size(), 2 );
80 BOOST_CHECK_EQUAL( checked[0], wxT( "b" ) );
81 BOOST_CHECK_EQUAL( checked[1], wxT( "c" ) );
82}
83
84
85// The header checkbox is ticked only when the whole section is, so a partly ticked section
86// reads the same as an empty one.
87BOOST_AUTO_TEST_CASE( SectionIsCheckedOnlyWhenEveryRowIs )
88{
90 data.SetEntries( {
91 makeEntry( wxT( "G" ), wxT( "a" ), true ),
92 makeEntry( wxT( "G" ), wxT( "b" ), true ),
93 } );
94
95 BOOST_CHECK( data.IsSectionChecked( wxT( "G" ) ) );
96
97 data.SetChecked( wxT( "a" ), false );
98 BOOST_CHECK( !data.IsSectionChecked( wxT( "G" ) ) );
99
100 data.SetChecked( wxT( "b" ), false );
101 BOOST_CHECK( !data.IsSectionChecked( wxT( "G" ) ) );
102}
103
104
105BOOST_AUTO_TEST_CASE( SetSectionCheckedTogglesWholeGroup )
106{
108 data.SetEntries( {
109 makeEntry( wxT( "G" ), wxT( "a" ), false ),
110 makeEntry( wxT( "G" ), wxT( "b" ), false ),
111 makeEntry( wxT( "H" ), wxT( "c" ), false ),
112 } );
113
114 data.SetSectionChecked( wxT( "G" ), true );
115
116 BOOST_CHECK( data.IsSectionChecked( wxT( "G" ) ) );
117 BOOST_CHECK( !data.IsSectionChecked( wxT( "H" ) ) );
118
119 std::vector<wxString> checked = data.CheckedPaths();
120 BOOST_REQUIRE_EQUAL( checked.size(), 2 );
121 BOOST_CHECK_EQUAL( checked[0], wxT( "a" ) );
122 BOOST_CHECK_EQUAL( checked[1], wxT( "b" ) );
123}
124
125
126BOOST_AUTO_TEST_CASE( UnknownSectionReadsAsEmpty )
127{
129 BOOST_CHECK( !data.IsSectionChecked( wxT( "missing" ) ) );
130 BOOST_CHECK( data.Rows( wxT( "missing" ) ).empty() );
131 BOOST_CHECK( data.CheckedPaths().empty() );
132}
133
134
The rows and tick states behind FILE_CHECKLIST_CTRL.
const std::vector< wxString > & Sections() const
Section headings in the order they were added.
std::vector< wxString > CheckedPaths() const
Paths of every ticked row, in the order they were added.
void SetEntries(const std::vector< FILE_CHECKLIST_ENTRY > &aEntries)
void SetSectionChecked(const wxString &aSection, bool aChecked)
void SetChecked(const wxString &aPath, bool aChecked)
bool IsSectionChecked(const wxString &aSection) const
True when the section has rows and every one of them is ticked.
const std::vector< FILE_CHECKLIST_ENTRY > & Rows(const wxString &aSection) const
Rows under a section, in the order they were added. Empty for an unknown section.
static bool empty(const wxTextEntryBase *aCtrl)
One file row in a FILE_CHECKLIST_CTRL.
wxString label
Shown in place of the path.
BITMAPS icon
wxString path
Row identity.
wxString section
wxString status
Free text, e.g. "Modified".
bool checked
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_CASE(SectionsAndRowsKeepInsertionOrder)
static FILE_CHECKLIST_ENTRY makeEntry(const wxString &aSection, const wxString &aPath, bool aChecked)
BOOST_AUTO_TEST_SUITE_END()
std::string path
BOOST_CHECK_EQUAL(result, "25.4")