From 88faac309f551c835b88d1e778bc0e33df01fc80 Mon Sep 17 00:00:00 2001 From: John Beard Date: Tue, 2 Apr 2019 16:35:25 +0100 Subject: [PATCH] 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. --- qa/eeschema/CMakeLists.txt | 7 +++++ qa/eeschema/eeschema_test_utils.cpp | 47 +++++++++++++++++++++++++++++ qa/eeschema/eeschema_test_utils.h | 44 +++++++++++++++++++++++++++ qa/eeschema/test_eagle_plugin.cpp | 41 ++++++++++++++++++------- 4 files changed, 128 insertions(+), 11 deletions(-) create mode 100644 qa/eeschema/eeschema_test_utils.cpp create mode 100644 qa/eeschema/eeschema_test_utils.h diff --git a/qa/eeschema/CMakeLists.txt b/qa/eeschema/CMakeLists.txt index b5143bccf8..f1f849207f 100644 --- a/qa/eeschema/CMakeLists.txt +++ b/qa/eeschema/CMakeLists.txt @@ -38,6 +38,8 @@ add_executable( qa_eeschema ../../common/colors.cpp ../../common/observable.cpp + eeschema_test_utils.cpp + # The main test entry points test_module.cpp @@ -61,4 +63,9 @@ add_test( NAME eeschema # Eeschema tests, so pretend to be eeschema (for units, etc) target_compile_definitions( qa_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\")" ) \ No newline at end of file diff --git a/qa/eeschema/eeschema_test_utils.cpp b/qa/eeschema/eeschema_test_utils.cpp new file mode 100644 index 0000000000..4fc072ed71 --- /dev/null +++ b/qa/eeschema/eeschema_test_utils.cpp @@ -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 }; +} \ No newline at end of file diff --git a/qa/eeschema/eeschema_test_utils.h b/qa/eeschema/eeschema_test_utils.h new file mode 100644 index 0000000000..d5637e0fe1 --- /dev/null +++ b/qa/eeschema/eeschema_test_utils.h @@ -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 + +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 \ No newline at end of file diff --git a/qa/eeschema/test_eagle_plugin.cpp b/qa/eeschema/test_eagle_plugin.cpp index 13537fec4f..281100a032 100644 --- a/qa/eeschema/test_eagle_plugin.cpp +++ b/qa/eeschema/test_eagle_plugin.cpp @@ -27,7 +27,7 @@ #include #include -#include +#include "eeschema_test_utils.h" /** * 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_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", -// NULL ); -// } +/** + * Get a schematic file from the test data eagle subdir + */ +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 ); +}