qa_eeschema: migrate to common mocks
This commit is contained in:
parent
aa7b65c70d
commit
2583acd1cc
|
@ -71,7 +71,6 @@ include_directories(
|
||||||
${CMAKE_SOURCE_DIR}
|
${CMAKE_SOURCE_DIR}
|
||||||
${CMAKE_SOURCE_DIR}/pcbnew
|
${CMAKE_SOURCE_DIR}/pcbnew
|
||||||
${CMAKE_SOURCE_DIR}/include
|
${CMAKE_SOURCE_DIR}/include
|
||||||
${CMAKE_SOURCE_DIR}/qa/mocks/pcbnew
|
|
||||||
${CMAKE_SOURCE_DIR}/qa/mocks/include
|
${CMAKE_SOURCE_DIR}/qa/mocks/include
|
||||||
${INC_AFTER}
|
${INC_AFTER}
|
||||||
)
|
)
|
||||||
|
|
|
@ -28,13 +28,15 @@ include_directories(
|
||||||
${CMAKE_SOURCE_DIR}
|
${CMAKE_SOURCE_DIR}
|
||||||
${CMAKE_SOURCE_DIR}/include
|
${CMAKE_SOURCE_DIR}/include
|
||||||
${CMAKE_SOURCE_DIR}/pcbnew
|
${CMAKE_SOURCE_DIR}/pcbnew
|
||||||
|
${CMAKE_SOURCE_DIR}/qa/mocks/include
|
||||||
${CMAKE_SOURCE_DIR}/qa/qa_utils
|
${CMAKE_SOURCE_DIR}/qa/qa_utils
|
||||||
${INC_AFTER}
|
${INC_AFTER}
|
||||||
)
|
)
|
||||||
|
|
||||||
set( QA_EESCHEMA_SRCS
|
set( QA_EESCHEMA_SRCS
|
||||||
# need the mock Pgm for many functions
|
# need the mock Pgm for many functions
|
||||||
mocks_eeschema.cpp
|
${CMAKE_SOURCE_DIR}/qa/mocks/kicad/common_mocks.cpp
|
||||||
|
${CMAKE_SOURCE_DIR}/qa/mocks/eeschema/mock_eeschema.cpp
|
||||||
|
|
||||||
eeschema_test_utils.cpp
|
eeschema_test_utils.cpp
|
||||||
uuid_test_utils.cpp
|
uuid_test_utils.cpp
|
||||||
|
|
|
@ -1,131 +0,0 @@
|
||||||
/*
|
|
||||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2019-2021 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
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <kiface_base.h>
|
|
||||||
#include <pgm_base.h>
|
|
||||||
#include <transform.h>
|
|
||||||
|
|
||||||
#include <sch_edit_frame.h>
|
|
||||||
#include <settings/settings_manager.h>
|
|
||||||
|
|
||||||
#include <wx/app.h>
|
|
||||||
|
|
||||||
|
|
||||||
// a transform matrix, to display components in lib editor
|
|
||||||
TRANSFORM DefaultTransform = TRANSFORM( 1, 0, 0, -1 );
|
|
||||||
|
|
||||||
|
|
||||||
static struct IFACE : public KIFACE_BASE
|
|
||||||
{
|
|
||||||
// Of course all are overloads, implementations of the KIFACE.
|
|
||||||
|
|
||||||
IFACE( const char* aName, KIWAY::FACE_T aType ) : KIFACE_BASE( aName, aType )
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
bool OnKifaceStart( PGM_BASE* aProgram, int aCtlBits ) override
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void OnKifaceEnd() override
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
wxWindow* CreateWindow(
|
|
||||||
wxWindow* aParent, int aClassId, KIWAY* aKiway, int aCtlBits = 0 ) override
|
|
||||||
{
|
|
||||||
assert( false );
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return a pointer to the requested object.
|
|
||||||
*
|
|
||||||
* The safest way to use this is to retrieve a pointer to a static instance of an interface,
|
|
||||||
* similar to how the KIFACE interface is exported. But if you know what you are doing
|
|
||||||
* use it to retrieve anything you want.
|
|
||||||
*
|
|
||||||
* @param aDataId identifies which object you want the address of.
|
|
||||||
* @return requested object which must be cast into the know type.
|
|
||||||
*/
|
|
||||||
void* IfaceOrAddress( int aDataId ) override
|
|
||||||
{
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
} kiface( "mock_eeschema", KIWAY::FACE_SCH );
|
|
||||||
|
|
||||||
|
|
||||||
static struct PGM_MOCK_EESCHEMA_FRAME : public PGM_BASE
|
|
||||||
{
|
|
||||||
bool OnPgmInit();
|
|
||||||
|
|
||||||
void OnPgmExit()
|
|
||||||
{
|
|
||||||
Kiway.OnKiwayEnd();
|
|
||||||
|
|
||||||
// Destroy everything in PGM_BASE, especially wxSingleInstanceCheckerImpl
|
|
||||||
// earlier than wxApp and earlier than static destruction would.
|
|
||||||
//PGM_BASE::Destroy();
|
|
||||||
}
|
|
||||||
|
|
||||||
void MacOpenFile( const wxString& aFileName ) override
|
|
||||||
{
|
|
||||||
wxFileName filename( aFileName );
|
|
||||||
|
|
||||||
if( filename.FileExists() )
|
|
||||||
{
|
|
||||||
#if 0
|
|
||||||
// this pulls in EDA_DRAW_FRAME type info, which we don't want in
|
|
||||||
// the single_top link image.
|
|
||||||
KIWAY_PLAYER* frame = dynamic_cast<KIWAY_PLAYER*>( App().GetTopWindow() );
|
|
||||||
#else
|
|
||||||
KIWAY_PLAYER* frame = (KIWAY_PLAYER*) App().GetTopWindow();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if( frame )
|
|
||||||
frame->OpenProjectFiles( std::vector<wxString>( 1, aFileName ) );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} program;
|
|
||||||
|
|
||||||
|
|
||||||
PGM_BASE& Pgm()
|
|
||||||
{
|
|
||||||
return program;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Similar to PGM_BASE& Pgm(), but return nullptr when a *.ki_face is run from
|
|
||||||
// a python script or something else.
|
|
||||||
// Therefore here return always nullptr
|
|
||||||
PGM_BASE* PgmOrNull()
|
|
||||||
{
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
KIFACE_BASE& Kiface()
|
|
||||||
{
|
|
||||||
return kiface;
|
|
||||||
}
|
|
|
@ -30,6 +30,7 @@
|
||||||
#include <kiplatform/app.h>
|
#include <kiplatform/app.h>
|
||||||
|
|
||||||
#include <pgm_base.h>
|
#include <pgm_base.h>
|
||||||
|
#include <wx/app.h>
|
||||||
#include <wx/init.h>
|
#include <wx/init.h>
|
||||||
|
|
||||||
#include <qa_utils/wx_utils/wx_assert.h>
|
#include <qa_utils/wx_utils/wx_assert.h>
|
||||||
|
@ -51,13 +52,15 @@ bool init_unit_test()
|
||||||
KIPLATFORM::APP::Init();
|
KIPLATFORM::APP::Init();
|
||||||
boost::unit_test::framework::master_test_suite().p_name.value = "Common Eeschema module tests";
|
boost::unit_test::framework::master_test_suite().p_name.value = "Common Eeschema module tests";
|
||||||
|
|
||||||
|
wxApp::SetInstance( new wxAppConsole );
|
||||||
|
|
||||||
bool ok = wxInitialize( boost::unit_test::framework::master_test_suite().argc,
|
bool ok = wxInitialize( boost::unit_test::framework::master_test_suite().argc,
|
||||||
boost::unit_test::framework::master_test_suite().argv );
|
boost::unit_test::framework::master_test_suite().argv );
|
||||||
|
|
||||||
Pgm().InitPgm( true ); // Initialize in headless mode
|
|
||||||
|
|
||||||
wxSetAssertHandler( &wxAssertThrower );
|
wxSetAssertHandler( &wxAssertThrower );
|
||||||
|
|
||||||
|
Pgm().InitPgm( true, true );
|
||||||
|
|
||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
/*
|
||||||
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2019-2022 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 common_mocks.cpp
|
||||||
|
* @brief Mock objects for unit tests
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <transform.h>
|
||||||
|
|
||||||
|
|
||||||
|
// a transform matrix, to display components in lib editor
|
||||||
|
TRANSFORM DefaultTransform = TRANSFORM( 1, 0, 0, -1 );
|
||||||
|
|
|
@ -31,15 +31,12 @@ MOCK_BASE_CLASS( MOCK_PGM_BASE, PGM_BASE )
|
||||||
virtual ~MOCK_PGM_BASE() {};
|
virtual ~MOCK_PGM_BASE() {};
|
||||||
|
|
||||||
MOCK_METHOD( MacOpenFile, 1, void( const wxString& ) );
|
MOCK_METHOD( MacOpenFile, 1, void( const wxString& ) );
|
||||||
MOCK_METHOD( GetSettingsManager, 0, SETTINGS_MANAGER&() );
|
|
||||||
MOCK_METHOD( GetCommonSettings, 0, COMMON_SETTINGS*() );
|
MOCK_METHOD( GetCommonSettings, 0, COMMON_SETTINGS*() );
|
||||||
MOCK_METHOD( SetTextEditor, 1, void( const wxString& ) );
|
MOCK_METHOD( SetTextEditor, 1, void( const wxString& ) );
|
||||||
MOCK_METHOD( GetTextEditor, 1, wxString&( bool ) );
|
MOCK_METHOD( GetTextEditor, 1, wxString&( bool ) );
|
||||||
MOCK_METHOD( AskUserForPreferredEditor, 1, wxString&( wxString& ) );
|
MOCK_METHOD( AskUserForPreferredEditor, 1, wxString&( wxString& ) );
|
||||||
MOCK_CONST_METHOD( IsKicadEnvVariableDefined, 0, bool() );
|
MOCK_CONST_METHOD( IsKicadEnvVariableDefined, 0, bool() );
|
||||||
MOCK_CONST_METHOD( GetKicadEnvVariable, 0, const wxString&() );
|
MOCK_CONST_METHOD( GetKicadEnvVariable, 0, const wxString&() );
|
||||||
MOCK_CONST_METHOD( GetExecutablePath, 0, const wxString&() );
|
|
||||||
MOCK_METHOD( GetLocale, 0, wxLocale*() );
|
|
||||||
MOCK_CONST_METHOD( GetPdfBrowserName, 0, const wxString&() );
|
MOCK_CONST_METHOD( GetPdfBrowserName, 0, const wxString&() );
|
||||||
MOCK_METHOD( SetPdfBrowserName, 1, void( const wxString& ) );
|
MOCK_METHOD( SetPdfBrowserName, 1, void( const wxString& ) );
|
||||||
MOCK_CONST_METHOD( UseSystemPdfBrowser, 0, bool() );
|
MOCK_CONST_METHOD( UseSystemPdfBrowser, 0, bool() );
|
||||||
|
@ -47,11 +44,17 @@ MOCK_BASE_CLASS( MOCK_PGM_BASE, PGM_BASE )
|
||||||
MOCK_METHOD( SetLanguage, 2, bool( wxString&, bool ) );
|
MOCK_METHOD( SetLanguage, 2, bool( wxString&, bool ) );
|
||||||
MOCK_METHOD( SetLanguageIdentifier, 1, void( int ) );
|
MOCK_METHOD( SetLanguageIdentifier, 1, void( int ) );
|
||||||
MOCK_CONST_METHOD( GetSelectedLanguageIdentifier, 0, int() );
|
MOCK_CONST_METHOD( GetSelectedLanguageIdentifier, 0, int() );
|
||||||
MOCK_METHOD( SetLanguagePath, 0, void() );
|
|
||||||
MOCK_METHOD( ReadPdfBrowserInfos, 0, void() );
|
MOCK_METHOD( ReadPdfBrowserInfos, 0, void() );
|
||||||
MOCK_METHOD( WritePdfBrowserInfos, 0, void() );
|
MOCK_METHOD( WritePdfBrowserInfos, 0, void() );
|
||||||
MOCK_METHOD( SetLocalEnvVariable, 2, bool( const wxString&, const wxString& ) );
|
MOCK_METHOD( SetLocalEnvVariable, 2, bool( const wxString&, const wxString& ) );
|
||||||
MOCK_METHOD( SetLocalEnvVariables, 0, void() );
|
MOCK_METHOD( SetLocalEnvVariables, 0, void() );
|
||||||
MOCK_CONST_METHOD( GetLocalEnvVariables, 0, ENV_VAR_MAP&() );
|
MOCK_CONST_METHOD( GetLocalEnvVariables, 0, ENV_VAR_MAP&() );
|
||||||
MOCK_METHOD( App, 0, wxApp&() );
|
|
||||||
|
// following functions will not be mocked in order to mimic old qa behavior
|
||||||
|
// MOCK_METHOD( App, 0, wxApp&() );
|
||||||
|
// MOCK_METHOD( GetLocale, 0, wxLocale*() );
|
||||||
|
// MOCK_METHOD( GetSettingsManager, 0, SETTINGS_MANAGER&() );
|
||||||
|
// MOCK_METHOD( SetLanguagePath, 0, void() );
|
||||||
|
// MOCK_CONST_METHOD( GetExecutablePath, 0, const wxString&() );
|
||||||
|
// MOCK_METHOD( GetSettingsManager, 0, SETTINGS_MANAGER&() );
|
||||||
};
|
};
|
||||||
|
|
|
@ -37,6 +37,15 @@ PGM_BASE& Pgm()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Similar to PGM_BASE& Pgm(), but return nullptr when a *.ki_face is run from
|
||||||
|
// a python script or something else.
|
||||||
|
// Therefore here return always nullptr
|
||||||
|
PGM_BASE* PgmOrNull()
|
||||||
|
{
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
KIFACE_BASE& Kiface()
|
KIFACE_BASE& Kiface()
|
||||||
{
|
{
|
||||||
static MOCK_KIFACE_BASE kiface;
|
static MOCK_KIFACE_BASE kiface;
|
||||||
|
|
|
@ -24,7 +24,6 @@ find_package( Boost COMPONENTS unit_test_framework filesystem system REQUIRED )
|
||||||
set( QA_UTIL_COMMON_SRC
|
set( QA_UTIL_COMMON_SRC
|
||||||
stdstream_line_reader.cpp
|
stdstream_line_reader.cpp
|
||||||
utility_program.cpp
|
utility_program.cpp
|
||||||
mock_pgm.cpp
|
|
||||||
|
|
||||||
geometry/line_chain_construction.cpp
|
geometry/line_chain_construction.cpp
|
||||||
geometry/poly_set_construction.cpp
|
geometry/poly_set_construction.cpp
|
||||||
|
|
|
@ -43,103 +43,6 @@
|
||||||
FP_LIB_TABLE GFootprintTable;
|
FP_LIB_TABLE GFootprintTable;
|
||||||
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
|
|
||||||
static struct IFACE : public KIFACE_BASE
|
|
||||||
{
|
|
||||||
// Of course all are overloads, implementations of the KIFACE.
|
|
||||||
|
|
||||||
IFACE( const char* aName, KIWAY::FACE_T aType ) :
|
|
||||||
KIFACE_BASE( aName, aType )
|
|
||||||
{}
|
|
||||||
|
|
||||||
bool OnKifaceStart( PGM_BASE* aProgram, int aCtlBits ) override
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void OnKifaceEnd() override {}
|
|
||||||
|
|
||||||
wxWindow* CreateWindow( wxWindow* aParent, int aClassId, KIWAY* aKiway, int aCtlBits = 0 ) override
|
|
||||||
{
|
|
||||||
assert( false );
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Function IfaceOrAddress
|
|
||||||
* return a pointer to the requested object. The safest way to use this
|
|
||||||
* is to retrieve a pointer to a static instance of an interface, similar to
|
|
||||||
* how the KIFACE interface is exported. But if you know what you are doing
|
|
||||||
* use it to retrieve anything you want.
|
|
||||||
*
|
|
||||||
* @param aDataId identifies which object you want the address of.
|
|
||||||
*
|
|
||||||
* @return void* - and must be cast into the know type.
|
|
||||||
*/
|
|
||||||
void* IfaceOrAddress( int aDataId ) override
|
|
||||||
{
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
kiface( "pcb_test_frame", KIWAY::FACE_PCB );
|
|
||||||
|
|
||||||
static struct PGM_TEST_FRAME : public PGM_BASE
|
|
||||||
{
|
|
||||||
bool OnPgmInit();
|
|
||||||
|
|
||||||
void OnPgmExit()
|
|
||||||
{
|
|
||||||
Kiway.OnKiwayEnd();
|
|
||||||
|
|
||||||
// Destroy everything in PGM_BASE, especially wxSingleInstanceCheckerImpl
|
|
||||||
// earlier than wxApp and earlier than static destruction would.
|
|
||||||
PGM_BASE::Destroy();
|
|
||||||
}
|
|
||||||
|
|
||||||
void MacOpenFile( const wxString& aFileName ) override
|
|
||||||
{
|
|
||||||
wxFileName filename( aFileName );
|
|
||||||
|
|
||||||
if( filename.FileExists() )
|
|
||||||
{
|
|
||||||
#if 0
|
|
||||||
// this pulls in EDA_DRAW_FRAME type info, which we don't want in
|
|
||||||
// the single_top link image.
|
|
||||||
KIWAY_PLAYER* frame = dynamic_cast<KIWAY_PLAYER*>( App().GetTopWindow() );
|
|
||||||
#else
|
|
||||||
KIWAY_PLAYER* frame = (KIWAY_PLAYER*) App().GetTopWindow();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if( frame )
|
|
||||||
frame->OpenProjectFiles( std::vector<wxString>( 1, aFileName ) );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
program;
|
|
||||||
|
|
||||||
PGM_BASE& Pgm()
|
|
||||||
{
|
|
||||||
return program;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Similar to PGM_BASE& Pgm(), but return nullptr when a *.ki_face
|
|
||||||
// is run from a python script, mot from a Kicad application
|
|
||||||
PGM_BASE* PgmOrNull()
|
|
||||||
{
|
|
||||||
return nullptr; //&program;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
KIFACE_BASE& Kiface()
|
|
||||||
{
|
|
||||||
return kiface;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// FP_LIB_TABLE GFootprintTable;
|
|
||||||
|
|
||||||
DIALOG_FIND::DIALOG_FIND( PCB_BASE_FRAME* aParent ) : DIALOG_FIND_BASE( aParent )
|
DIALOG_FIND::DIALOG_FIND( PCB_BASE_FRAME* aParent ) : DIALOG_FIND_BASE( aParent )
|
||||||
{
|
{
|
||||||
// these members are initialized to avoid warnings about non initialized vars
|
// these members are initialized to avoid warnings about non initialized vars
|
||||||
|
|
Loading…
Reference in New Issue