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, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
30
31// Code under test
32#include <file_history.h>
33#include <id.h>
34
35#include <vector>
36
37BOOST_AUTO_TEST_SUITE( FileHistory )
38
40{
41 FILE_HISTORY history( 3, ID_FILE1, ID_FILE_LIST_CLEAR, "Clear" );
42
43 history.AddFileToHistory( "file1" );
44 history.AddFileToHistory( "file2" );
45 history.AddFileToHistory( "file3" );
46
47 BOOST_CHECK_EQUAL( history.GetCount(), 3 );
48 BOOST_CHECK_EQUAL( history.GetHistoryFile( 0 ), wxString( "file3" ) );
49 BOOST_CHECK_EQUAL( history.GetHistoryFile( 2 ), wxString( "file1" ) );
50
51 history.AddFileToHistory( "file4" );
52
53 BOOST_CHECK_EQUAL( history.GetCount(), 3 );
54 BOOST_CHECK_EQUAL( history.GetHistoryFile( 0 ), wxString( "file4" ) );
55 BOOST_CHECK_EQUAL( history.GetHistoryFile( 2 ), wxString( "file2" ) );
56
57 history.RemoveFileFromHistory( 1 );
58 BOOST_CHECK_EQUAL( history.GetCount(), 2 );
59 BOOST_CHECK_EQUAL( history.GetHistoryFile( 1 ), wxString( "file2" ) );
60}
61
63{
64 FILE_HISTORY history( 5, ID_FILE1, ID_FILE_LIST_CLEAR, "Clear" );
65
66 history.AddFileToHistory( "a" );
67 history.AddFileToHistory( "b" );
68 history.AddFileToHistory( "c" );
69
70 std::vector<wxString> saved;
71 history.Save( &saved );
72
73 FILE_HISTORY loaded( 5, ID_FILE1, ID_FILE_LIST_CLEAR, "Clear" );
74 loaded.Load( saved );
75
76 BOOST_CHECK_EQUAL( loaded.GetCount(), 3 );
77 BOOST_CHECK_EQUAL( loaded.GetHistoryFile( 0 ), wxString( "a" ) );
78 BOOST_CHECK_EQUAL( loaded.GetHistoryFile( 2 ), wxString( "c" ) );
79
80 loaded.ClearFileHistory();
81 BOOST_CHECK_EQUAL( loaded.GetCount(), 0 );
82}
83
This class implements a file history object to store a list of files, that can then be added to a men...
Definition: file_history.h:43
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:62
@ ID_FILE1
Definition: id.h:59
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_CHECK_EQUAL(ret, c.m_exp_result)
BOOST_AUTO_TEST_CASE(AddRemove)
BOOST_AUTO_TEST_SUITE_END()