KiCad PCB EDA Suite
Loading...
Searching...
No Matches
wx_assert.h
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 The KiCad Developers, see AUTHORS.TXT for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20#ifndef UNIT_TEST_UTILS_WX_ASSERT__H
21#define UNIT_TEST_UTILS_WX_ASSERT__H
22
23#include <wx/string.h>
24#include <wx/thread.h>
25
26#include <exception>
27#include <string>
28
29namespace KI_TEST
30{
31
43class WX_ASSERT_ERROR : public std::exception
44{
45public:
46 WX_ASSERT_ERROR( const wxString& aFile, int aLine, const wxString& aFunc, const wxString& aCond,
47 const wxString& aMsg );
48
49 const char* what() const noexcept override;
50
51 // Public, so catchers can have a look (though be careful as the function
52 // names can change over time!)
53 std::string m_file;
54 int m_line;
55 std::string m_func;
56 std::string m_cond;
57 std::string m_msg;
58
59 std::string m_format_msg;
60};
61
62
72[[noreturn]] void ReportAssertOffMainThread( const wxString& aFile, int aLine,
73 const wxString& aFunc, const wxString& aCond,
74 const wxString& aMsg );
75
76/*
77 * Simple function to handle a WX assertion and throw a real exception.
78 *
79 * This is useful when you want to check assertions fire in unit tests.
80 */
81inline void wxAssertThrower( const wxString& aFile, int aLine, const wxString& aFunc,
82 const wxString& aCond, const wxString& aMsg )
83{
84 if( !wxThread::IsMain() )
85 ReportAssertOffMainThread( aFile, aLine, aFunc, aCond, aMsg );
86
87 throw KI_TEST::WX_ASSERT_ERROR( aFile, aLine, aFunc, aCond, aMsg );
88}
89
90} // namespace KI_TEST
91
92#endif // UNIT_TEST_UTILS_WX_ASSERT__H
An exception class to represent a WX assertion.
Definition wx_assert.h:44
WX_ASSERT_ERROR(const wxString &aFile, int aLine, const wxString &aFunc, const wxString &aCond, const wxString &aMsg)
Definition wx_assert.cpp:36
const char * what() const noexcept override
Definition wx_assert.cpp:53
std::string m_format_msg
Definition wx_assert.h:59
void wxAssertThrower(const wxString &aFile, int aLine, const wxString &aFunc, const wxString &aCond, const wxString &aMsg)
Definition wx_assert.h:81
void ReportAssertOffMainThread(const wxString &aFile, int aLine, const wxString &aFunc, const wxString &aCond, const wxString &aMsg)
Print a wx assertion that fired outside the main thread, then exit the process.
Definition wx_assert.cpp:59