KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_file_history.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 2
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
24
26
27// Code under test
28#include <file_history.h>
29#include <id.h>
30
31#include <vector>
32
33BOOST_AUTO_TEST_SUITE( FileHistory )
34
36{
37 FILE_HISTORY history( 3, ID_FILE1, ID_FILE_LIST_CLEAR, "Clear" );
38
39 history.AddFileToHistory( "file1" );
40 history.AddFileToHistory( "file2" );
41 history.AddFileToHistory( "file3" );
42
43 BOOST_CHECK_EQUAL( history.GetCount(), 3 );
44 BOOST_CHECK_EQUAL( history.GetHistoryFile( 0 ), wxString( "file3" ) );
45 BOOST_CHECK_EQUAL( history.GetHistoryFile( 2 ), wxString( "file1" ) );
46
47 history.AddFileToHistory( "file4" );
48
49 BOOST_CHECK_EQUAL( history.GetCount(), 3 );
50 BOOST_CHECK_EQUAL( history.GetHistoryFile( 0 ), wxString( "file4" ) );
51 BOOST_CHECK_EQUAL( history.GetHistoryFile( 2 ), wxString( "file2" ) );
52
53 history.RemoveFileFromHistory( 1 );
54 BOOST_CHECK_EQUAL( history.GetCount(), 2 );
55 BOOST_CHECK_EQUAL( history.GetHistoryFile( 1 ), wxString( "file2" ) );
56}
57
59{
60 FILE_HISTORY history( 5, ID_FILE1, ID_FILE_LIST_CLEAR, "Clear" );
61
62 history.AddFileToHistory( "a" );
63 history.AddFileToHistory( "b" );
64 history.AddFileToHistory( "c" );
65
66 std::vector<wxString> saved;
67 history.Save( &saved );
68
69 FILE_HISTORY loaded( 5, ID_FILE1, ID_FILE_LIST_CLEAR, "Clear" );
70 loaded.Load( saved );
71
72 BOOST_CHECK_EQUAL( loaded.GetCount(), 3 );
73 BOOST_CHECK_EQUAL( loaded.GetHistoryFile( 0 ), wxString( "a" ) );
74 BOOST_CHECK_EQUAL( loaded.GetHistoryFile( 2 ), wxString( "c" ) );
75
76 loaded.ClearFileHistory();
77 BOOST_CHECK_EQUAL( loaded.GetCount(), 0 );
78}
79
This class implements a file history object to store a list of files, that can then be added to a men...
void AddFileToHistory(const wxString &aFile) override
Adds a file to the history.
void ClearFileHistory()
Clear all entries from the file history.
void Save(APP_SETTINGS_BASE &aSettings)
Saves history into a JSON settings object.
void Load(const APP_SETTINGS_BASE &aSettings)
Loads history from a JSON settings object.
@ ID_FILE_LIST_CLEAR
Definition id.h:58
@ ID_FILE1
Definition id.h:55
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_CASE(AddRemove)
BOOST_AUTO_TEST_SUITE_END()
BOOST_CHECK_EQUAL(result, "25.4")