KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_wx_filename.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 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, you may find one here:
18
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19
* or you may search the http://www.gnu.org website for the version 2 license,
20
* or you may write to the Free Software Foundation, Inc.,
21
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22
*/
23
28
29
#include <
qa_utils/wx_utils/unit_test_utils.h
>
30
31
// Code under test
32
#include <
wx_filename.h
>
33
37
BOOST_AUTO_TEST_SUITE
( WxFilename )
38
39
40
struct
WX_FILENAME_SPLIT_CASE
41
{
42
// Ctor params
43
std::string
m_path
;
44
std::string
m_name
;
45
46
// Split results
47
std::string
m_exp_name
;
48
std::string
m_exp_full_name
;
49
std::string
m_exp_path
;
50
std::string
m_exp_full_path
;
51
};
52
53
54
// clang-format off
55
static
const
std::vector<WX_FILENAME_SPLIT_CASE>
split_cases
= {
56
{
57
""
,
58
""
,
59
""
,
60
""
,
61
""
,
62
"/"
,
// This doesn't look right...
63
},
64
{
65
""
,
66
"name.ext"
,
67
"name"
,
68
"name.ext"
,
69
""
,
70
"/name.ext"
,
// This doesn't look right...
71
},
72
{
73
"/tmp/example"
,
74
""
,
75
""
,
76
""
,
77
"/tmp/example"
,
78
"/tmp/example/"
,
79
},
80
{
81
"/tmp/example"
,
82
"name.ext"
,
83
"name"
,
84
"name.ext"
,
85
"/tmp/example"
,
86
"/tmp/example/name.ext"
,
87
},
88
{
89
"/tmp/example"
,
90
"name"
,
// no extension
91
"name"
,
92
"name"
,
93
"/tmp/example"
,
94
"/tmp/example/name"
,
95
},
96
{
97
"/tmp/example"
,
98
"name.ext1.ext2"
,
// two extensions
99
"name.ext1"
,
// remove the first one
100
"name.ext1.ext2"
,
101
"/tmp/example"
,
102
"/tmp/example/name.ext1.ext2"
,
103
},
104
};
105
// clang-format on
106
110
BOOST_AUTO_TEST_CASE
( Split )
111
{
112
for
(
const
auto
& c :
split_cases
)
113
{
114
std::stringstream ss;
115
ss << c.m_path <<
", "
<< c.m_name;
116
BOOST_TEST_CONTEXT
( ss.str() )
117
{
118
// Const: all methods called must be const
119
const
WX_FILENAME
wx_fn( c.m_path, c.m_name );
120
121
BOOST_CHECK_EQUAL
( c.m_exp_name, wx_fn.
GetName
() );
122
BOOST_CHECK_EQUAL
( c.m_exp_full_name, wx_fn.
GetFullName
() );
123
BOOST_CHECK_EQUAL
( c.m_exp_path, wx_fn.
GetPath
() );
124
BOOST_CHECK_EQUAL
( c.m_exp_full_path, wx_fn.
GetFullPath
() );
125
}
126
}
127
}
128
129
BOOST_AUTO_TEST_SUITE_END
()
WX_FILENAME
A wrapper around a wxFileName which is much more performant with a subset of the API.
Definition
wx_filename.h:50
WX_FILENAME::GetPath
wxString GetPath() const
Definition
wx_filename.cpp:60
WX_FILENAME::GetName
wxString GetName() const
Definition
wx_filename.cpp:47
WX_FILENAME::GetFullPath
wxString GetFullPath() const
Definition
wx_filename.cpp:66
WX_FILENAME::GetFullName
wxString GetFullName() const
Definition
wx_filename.cpp:54
WX_FILENAME_SPLIT_CASE
Declare the test suite.
Definition
test_wx_filename.cpp:41
WX_FILENAME_SPLIT_CASE::m_exp_name
std::string m_exp_name
Definition
test_wx_filename.cpp:47
WX_FILENAME_SPLIT_CASE::m_path
std::string m_path
Definition
test_wx_filename.cpp:43
WX_FILENAME_SPLIT_CASE::m_name
std::string m_name
Definition
test_wx_filename.cpp:44
WX_FILENAME_SPLIT_CASE::m_exp_path
std::string m_exp_path
Definition
test_wx_filename.cpp:49
WX_FILENAME_SPLIT_CASE::m_exp_full_name
std::string m_exp_full_name
Definition
test_wx_filename.cpp:48
WX_FILENAME_SPLIT_CASE::m_exp_full_path
std::string m_exp_full_path
Definition
test_wx_filename.cpp:50
BOOST_AUTO_TEST_SUITE
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_SUITE_END
BOOST_AUTO_TEST_SUITE_END()
BOOST_TEST_CONTEXT
BOOST_TEST_CONTEXT("Test Clearance")
Definition
test_shape_arc.cpp:656
BOOST_CHECK_EQUAL
BOOST_CHECK_EQUAL(result, "25.4")
split_cases
static const std::vector< WX_FILENAME_SPLIT_CASE > split_cases
Definition
test_wx_filename.cpp:55
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(Split)
Check the various split cases work correctly.
Definition
test_wx_filename.cpp:110
unit_test_utils.h
wx_filename.h
src
qa
tests
common
test_wx_filename.cpp
Generated on Sun Sep 21 2025 01:05:32 for KiCad PCB EDA Suite by
1.13.2