mirror of
https://gitlab.com/kicad/code/kicad.git
synced 2025-09-14 02:03:12 +02:00
Add some QA tests for FILE_HISTORY, SEARCH_PATH and FILENAME_RESOLVER
This commit is contained in:
parent
50c7aff3ff
commit
43a9c760b1
@ -38,6 +38,8 @@ set( QA_COMMON_SRCS
|
||||
test_eda_shape.cpp
|
||||
test_eda_text.cpp
|
||||
test_embedded_file_compress.cpp
|
||||
test_file_history.cpp
|
||||
test_filename_resolver.cpp
|
||||
test_increment.cpp
|
||||
test_ki_any.cpp
|
||||
test_lib_table.cpp
|
||||
|
84
qa/tests/common/test_file_history.cpp
Normal file
84
qa/tests/common/test_file_history.cpp
Normal file
@ -0,0 +1,84 @@
|
||||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright The KiCad Developers, see AUTHORS.TXT for contributors.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, you may find one here:
|
||||
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
||||
* or you may search the http://www.gnu.org website for the version 2 license,
|
||||
* or you may write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Test suite for FILE_HISTORY.
|
||||
*/
|
||||
|
||||
#include <qa_utils/wx_utils/unit_test_utils.h>
|
||||
|
||||
// Code under test
|
||||
#include <file_history.h>
|
||||
#include <id.h>
|
||||
|
||||
#include <vector>
|
||||
|
||||
BOOST_AUTO_TEST_SUITE( FileHistory )
|
||||
|
||||
BOOST_AUTO_TEST_CASE( AddRemove )
|
||||
{
|
||||
FILE_HISTORY history( 3, ID_FILE1, ID_FILE_LIST_CLEAR, "Clear" );
|
||||
|
||||
history.AddFileToHistory( "file1" );
|
||||
history.AddFileToHistory( "file2" );
|
||||
history.AddFileToHistory( "file3" );
|
||||
|
||||
BOOST_CHECK_EQUAL( history.GetCount(), 3 );
|
||||
BOOST_CHECK_EQUAL( history.GetHistoryFile( 0 ), wxString( "file3" ) );
|
||||
BOOST_CHECK_EQUAL( history.GetHistoryFile( 2 ), wxString( "file1" ) );
|
||||
|
||||
history.AddFileToHistory( "file4" );
|
||||
|
||||
BOOST_CHECK_EQUAL( history.GetCount(), 3 );
|
||||
BOOST_CHECK_EQUAL( history.GetHistoryFile( 0 ), wxString( "file4" ) );
|
||||
BOOST_CHECK_EQUAL( history.GetHistoryFile( 2 ), wxString( "file2" ) );
|
||||
|
||||
history.RemoveFileFromHistory( 1 );
|
||||
BOOST_CHECK_EQUAL( history.GetCount(), 2 );
|
||||
BOOST_CHECK_EQUAL( history.GetHistoryFile( 1 ), wxString( "file2" ) );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( Persistence )
|
||||
{
|
||||
FILE_HISTORY history( 5, ID_FILE1, ID_FILE_LIST_CLEAR, "Clear" );
|
||||
|
||||
history.AddFileToHistory( "a" );
|
||||
history.AddFileToHistory( "b" );
|
||||
history.AddFileToHistory( "c" );
|
||||
|
||||
std::vector<wxString> saved;
|
||||
history.Save( &saved );
|
||||
|
||||
FILE_HISTORY loaded( 5, ID_FILE1, ID_FILE_LIST_CLEAR, "Clear" );
|
||||
loaded.Load( saved );
|
||||
|
||||
BOOST_CHECK_EQUAL( loaded.GetCount(), 3 );
|
||||
BOOST_CHECK_EQUAL( loaded.GetHistoryFile( 0 ), wxString( "a" ) );
|
||||
BOOST_CHECK_EQUAL( loaded.GetHistoryFile( 2 ), wxString( "c" ) );
|
||||
|
||||
loaded.ClearFileHistory();
|
||||
BOOST_CHECK_EQUAL( loaded.GetCount(), 0 );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
119
qa/tests/common/test_filename_resolver.cpp
Normal file
119
qa/tests/common/test_filename_resolver.cpp
Normal file
@ -0,0 +1,119 @@
|
||||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright The KiCad Developers, see AUTHORS.TXT for contributors.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, you may find one here:
|
||||
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
||||
* or you may search the http://www.gnu.org website for the version 2 license,
|
||||
* or you may write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Tests for FILENAME_RESOLVER and SEARCH_STACK.
|
||||
*/
|
||||
|
||||
#include <qa_utils/wx_utils/unit_test_utils.h>
|
||||
|
||||
// Code under test
|
||||
#include <filename_resolver.h>
|
||||
#include <search_stack.h>
|
||||
|
||||
#include <wx/filename.h>
|
||||
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
BOOST_AUTO_TEST_SUITE( FilenameResolver )
|
||||
|
||||
BOOST_AUTO_TEST_CASE( ResolveAbsoluteAndWorkingPath )
|
||||
{
|
||||
fs::path temp = fs::temp_directory_path() / "fnres_test";
|
||||
fs::create_directories( temp );
|
||||
|
||||
fs::path work = temp / "work";
|
||||
fs::create_directories( work );
|
||||
|
||||
fs::path file = work / "model.txt";
|
||||
std::ofstream( file.string() ) << "dummy";
|
||||
|
||||
FILENAME_RESOLVER resolver;
|
||||
|
||||
wxString absFile = wxString::FromUTF8( file.string() );
|
||||
wxString resolved = resolver.ResolvePath( absFile, wxEmptyString, {} );
|
||||
wxFileName fn( absFile );
|
||||
fn.Normalize( wxPATH_NORM_ABSOLUTE | wxPATH_NORM_DOTS );
|
||||
BOOST_CHECK_EQUAL( resolved, fn.GetFullPath() );
|
||||
|
||||
wxString working = wxString::FromUTF8( work.string() );
|
||||
wxString relResolved = resolver.ResolvePath( wxS( "model.txt" ), working, {} );
|
||||
BOOST_CHECK_EQUAL( relResolved, fn.GetFullPath() );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( ResolveAliasAndErrors )
|
||||
{
|
||||
fs::path temp = fs::temp_directory_path() / "fnres_alias";
|
||||
fs::create_directories( temp );
|
||||
|
||||
fs::path file = temp / "a.txt";
|
||||
std::ofstream( file.string() ) << "dummy";
|
||||
|
||||
FILENAME_RESOLVER resolver;
|
||||
|
||||
SEARCH_PATH sp;
|
||||
sp.m_Alias = wxS( "ALIAS" );
|
||||
sp.m_Pathvar = wxString::FromUTF8( temp.string() );
|
||||
std::vector<SEARCH_PATH> paths = { sp };
|
||||
resolver.UpdatePathList( paths );
|
||||
|
||||
wxString resolved = resolver.ResolvePath( wxS( "ALIAS:a.txt" ), wxEmptyString, {} );
|
||||
BOOST_CHECK_EQUAL( resolved, wxString::FromUTF8( file.string() ) );
|
||||
|
||||
wxString missing = resolver.ResolvePath( wxS( "MISSING:a.txt" ), wxEmptyString, {} );
|
||||
BOOST_CHECK( missing.IsEmpty() );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
||||
BOOST_AUTO_TEST_SUITE( SearchStack )
|
||||
|
||||
BOOST_AUTO_TEST_CASE( RelativePathResolution )
|
||||
{
|
||||
fs::path root = fs::temp_directory_path() / "ss_root";
|
||||
fs::path sub = root / "sub";
|
||||
fs::create_directories( sub );
|
||||
|
||||
fs::path file = sub / "f.txt";
|
||||
std::ofstream( file.string() ) << "dummy";
|
||||
|
||||
SEARCH_STACK stack;
|
||||
stack.AddPaths( wxString::FromUTF8( root.string() ) );
|
||||
|
||||
wxString rel = stack.FilenameWithRelativePathInSearchList( wxString::FromUTF8( file.string() ),
|
||||
wxString::FromUTF8( root.string() ) );
|
||||
BOOST_CHECK_EQUAL( rel, wxString::FromUTF8( ( fs::path( "sub" ) / "f.txt" ).string() ) );
|
||||
|
||||
fs::path outside = fs::temp_directory_path() / "outside.txt";
|
||||
std::ofstream( outside.string() ) << "dummy";
|
||||
|
||||
wxString full = stack.FilenameWithRelativePathInSearchList( wxString::FromUTF8( outside.string() ),
|
||||
wxString::FromUTF8( root.string() ) );
|
||||
BOOST_CHECK_EQUAL( full, wxString::FromUTF8( outside.string() ) );
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
Loading…
x
Reference in New Issue
Block a user