KiCad PCB EDA Suite
Loading...
Searching...
No Matches
eeschema/test_module.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 (C) 2017 CERN
5 * @author Alejandro GarcĂ­a Montoro <[email protected]>
6 * Copyright (C) 2019-2020 KiCad Developers, see AUTHORS.txt for contributors.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, you may find one here:
20 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21 * or you may search the http://www.gnu.org website for the version 2 license,
22 * or you may write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 */
25
29#include <boost/test/unit_test.hpp>
30#include <kiplatform/app.h>
31
32#include <pgm_base.h>
34#include <eeschema_settings.h>
36#include <wx/app.h>
37#include <wx/init.h>
38#include <mock_pgm_base.h>
39
41
42/*
43 * Simple function to handle a WX assertion and throw a real exception.
44 *
45 * This is useful when you want to check assertions fire in unit tests.
46 */
47void wxAssertThrower( const wxString& aFile, int aLine, const wxString& aFunc,
48 const wxString& aCond, const wxString& aMsg )
49{
50 throw KI_TEST::WX_ASSERT_ERROR( aFile, aLine, aFunc, aCond, aMsg );
51}
52
53
55{
56 SetPgm( new MOCK_PGM_BASE() );
58 boost::unit_test::framework::master_test_suite().p_name.value = "Common Eeschema module tests";
59
60 wxApp::SetInstance( new wxAppConsole );
61
62 bool ok = wxInitialize( boost::unit_test::framework::master_test_suite().argc,
63 boost::unit_test::framework::master_test_suite().argv );
64
65 wxSetAssertHandler( &wxAssertThrower );
66
67 Pgm().InitPgm( true, true, true );
71 return ok;
72}
73
74
75int main( int argc, char* argv[] )
76{
77 int ret = boost::unit_test::unit_test_main( &init_unit_test, argc, argv );
78
79 Pgm().Destroy();
80
81 // This causes some glib warnings on GTK3 (http://trac.wxwidgets.org/ticket/18274)
82 // but without it, Valgrind notices a lot of leaks from WX
83 wxUninitialize();
84
85 return ret;
86}
An exception class to represent a WX assertion.
Definition: wx_assert.h:47
void Destroy()
Definition: pgm_base.cpp:165
bool InitPgm(bool aHeadless=false, bool aSkipPyInit=false, bool aIsUnitTest=false)
Initialize this program.
Definition: pgm_base.cpp:456
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition: pgm_base.h:142
T * RegisterSettings(T *aSettings, bool aLoadNow=true)
Takes ownership of the pointer passed in.
main()
bool init_unit_test()
void wxAssertThrower(const wxString &aFile, int aLine, const wxString &aFunc, const wxString &aCond, const wxString &aMsg)
Main file for the Eeschema tests to be compiled.
bool Init()
Perform application-specific initialization tasks.
Definition: gtk/app.cpp:40
void SetPgm(PGM_BASE *pgm)
Definition: pgm_base.cpp:1071
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: pgm_base.cpp:1059
see class PGM_BASE