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
25#include <exception>
26#include <string>
27
28namespace KI_TEST
29{
30
42class WX_ASSERT_ERROR : public std::exception
43{
44public:
45 WX_ASSERT_ERROR( const wxString& aFile, int aLine, const wxString& aFunc, const wxString& aCond,
46 const wxString& aMsg );
47
48 const char* what() const noexcept override;
49
50 // Public, so catchers can have a look (though be careful as the function
51 // names can change over time!)
52 std::string m_file;
53 int m_line;
54 std::string m_func;
55 std::string m_cond;
56 std::string m_msg;
57
58 std::string m_format_msg;
59};
60
61
62/*
63 * Simple function to handle a WX assertion and throw a real exception.
64 *
65 * This is useful when you want to check assertions fire in unit tests.
66 */
67inline void wxAssertThrower( const wxString& aFile, int aLine, const wxString& aFunc,
68 const wxString& aCond, const wxString& aMsg )
69{
70 throw KI_TEST::WX_ASSERT_ERROR( aFile, aLine, aFunc, aCond, aMsg );
71}
72
73} // namespace KI_TEST
74
75#endif // UNIT_TEST_UTILS_WX_ASSERT__H
An exception class to represent a WX assertion.
Definition wx_assert.h:43
WX_ASSERT_ERROR(const wxString &aFile, int aLine, const wxString &aFunc, const wxString &aCond, const wxString &aMsg)
Definition wx_assert.cpp:26
const char * what() const noexcept override
Definition wx_assert.cpp:43
std::string m_format_msg
Definition wx_assert.h:58
void wxAssertThrower(const wxString &aFile, int aLine, const wxString &aFunc, const wxString &aCond, const wxString &aMsg)
Definition wx_assert.h:67