KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_io_error.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 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
18#define BOOST_TEST_NO_MAIN
19#include <boost/test/unit_test.hpp>
20
21#include <vector>
22
23#include <ki_exception.h>
24
25
26BOOST_AUTO_TEST_SUITE( IOErrorTest )
27
28
29BOOST_AUTO_TEST_CASE( WhatRetainsUtf8Message )
30{
31 const wxString message = wxString::FromUTF8( "Could not read \xe2\x80\x9c"
32 "board"
33 "\xe2\x80\x9d" );
34 IO_ERROR error( message, __FILE__, __FUNCTION__, __LINE__ );
35 const char* what = error.what();
36 std::string expected = message.utf8_string();
37
38 std::vector<std::string> allocations( 1000, expected );
39
40 BOOST_CHECK_EQUAL( allocations.front(), expected );
41 BOOST_CHECK_EQUAL( std::string( what ), expected );
42}
43
44
45BOOST_AUTO_TEST_CASE( DerivedErrorsUpdateWhatMessage )
46{
47 PARSE_ERROR parseError( wxS( "Invalid token" ), __FILE__, __FUNCTION__, __LINE__, wxS( "example.kicad_pcb" ),
48 "invalid", 10, 4 );
49 BOOST_CHECK_EQUAL( std::string( parseError.what() ), parseError.Problem().utf8_string() );
50
51 FUTURE_FORMAT_ERROR futureError( parseError, wxS( "20261012" ) );
52 BOOST_CHECK_EQUAL( std::string( futureError.what() ), futureError.Problem().utf8_string() );
53}
54
55
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
virtual const wxString Problem() const
what was the problem?
virtual const char * what() const override
std::exception interface, returned as UTF-8
std::string message
Variant of PARSE_ERROR indicating that a syntax or related error was likely caused by a file generate...
A filename or source description, a problem input line, a line number, a byte offset,...
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_CHECK_EQUAL(std::any_cast< std::string >(rows[0].at("val")), "12345678901234567.89")
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(WhatRetainsUtf8Message)
VECTOR3I expected(15, 30, 45)