QA: Eagle test: look up test data in the source tree

Also provide a utility function to get this path, and
a way to override at run time to quickly sub in alternative
data.

The test itself is still broken, as this plugin won't accept
a call to Load() without a KiWay.

(cherry picked from commit 88faac309f)
This commit is contained in:
John Beard 2019-04-02 16:35:25 +01:00
parent 3a5e01c44a
commit e766732020
4 changed files with 128 additions and 11 deletions

View File

@ -38,6 +38,8 @@ add_executable( qa_eeschema
../../common/colors.cpp ../../common/colors.cpp
../../common/observable.cpp ../../common/observable.cpp
eeschema_test_utils.cpp
# The main test entry points # The main test entry points
test_module.cpp test_module.cpp
@ -61,4 +63,9 @@ add_test( NAME eeschema
# Eeschema tests, so pretend to be eeschema (for units, etc) # Eeschema tests, so pretend to be eeschema (for units, etc)
target_compile_definitions( qa_eeschema target_compile_definitions( qa_eeschema
PUBLIC EESCHEMA PUBLIC EESCHEMA
)
# Pass in the default data location
set_source_files_properties( eeschema_test_utils.cpp PROPERTIES
COMPILE_DEFINITIONS "QA_EESCHEMA_DATA_LOCATION=(\"${CMAKE_CURRENT_SOURCE_DIR}/data\")"
) )

View File

@ -0,0 +1,47 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2019 KiCad Developers, see CHANGELOG.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
*/
#include "eeschema_test_utils.h"
wxFileName KI_TEST::GetEeschemaTestDataDir()
{
const char* env = std::getenv( "KICAD_TEST_EESCHEMA_DATA_DIR" );
wxString fn;
if( !env )
{
// Use the compiled-in location of the data dir
// (i.e. where the files were at build time)
fn << QA_EESCHEMA_DATA_LOCATION;
}
else
{
// Use whatever was given in the env var
fn << env;
}
// Ensure the string ends in / to force a directory interpretation
fn << "/";
return wxFileName{ fn };
}

View File

@ -0,0 +1,44 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2019 KiCad Developers, see CHANGELOG.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
*/
#ifndef QA_EESCHEMA_EESCHEMA_TEST_UTILS__H
#define QA_EESCHEMA_EESCHEMA_TEST_UTILS__H
#include <wx/filename.h>
namespace KI_TEST
{
/**
* Get the configured location of Eeschema test data.
*
* By default, this is the test data in the source tree, but can be overriden
* by the KICAD_TEST_EESCHEMA_DATA_DIR environment variable.
*
* @return a filename referring to the test data dir to use.
*/
wxFileName GetEeschemaTestDataDir();
} // namespace KI_TEST
#endif // QA_EESCHEMA_EESCHEMA_TEST_UTILS__H

View File

@ -27,7 +27,7 @@
#include <kiway.h> #include <kiway.h>
#include <sch_io_mgr.h> #include <sch_io_mgr.h>
#include <data/fixtures_eagle_plugin.h> #include "eeschema_test_utils.h"
/** /**
* Checks that the SCH_IO manager finds the Eagle plugin * Checks that the SCH_IO manager finds the Eagle plugin
@ -37,14 +37,33 @@ BOOST_AUTO_TEST_CASE( FindPlugin )
BOOST_CHECK_NE( SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_EAGLE ), nullptr ); BOOST_CHECK_NE( SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_EAGLE ), nullptr );
} }
/**
*
*/
// BOOST_AUTO_TEST_CASE( Load )
// {
// SCH_PLUGIN* pi = SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_EAGLE );
// pi->Load( /**
// "/home/alejandro/Proyectos/kicad/kicad-alejandro/eeschema/qa/data/eagle_schematics/empty.sch", * Get a schematic file from the test data eagle subdir
// NULL ); */
// } static wxFileName getEagleTestSchematic( const wxString& sch_file )
{
wxFileName fn = KI_TEST::GetEeschemaTestDataDir();
fn.AppendDir( "eagle_schematics" );
fn.SetFullName( sch_file );
return fn;
}
/**
* Check that a file can be loaded.
*/
BOOST_AUTO_TEST_CASE( Load )
{
SCH_PLUGIN* pi = SCH_IO_MGR::FindPlugin( SCH_IO_MGR::SCH_EAGLE );
const auto fn = getEagleTestSchematic( "eagle-import-testfile.sch" );
BOOST_TEST_MESSAGE( fn.GetFullPath() );
(void) pi;
// This doesn't work with a null KiWay.
// const SCH_SHEET* sheet = pi->Load( fn.GetFullPath(), nullptr );
// BOOST_CHECK_NE( nullptr, sheet );
}