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, see <https://www.gnu.org/licenses/>.
18
*/
19
24
25
#include <
qa_utils/wx_utils/unit_test_utils.h
>
26
27
// Code under test
28
#include <
wx_filename.h
>
29
33
BOOST_AUTO_TEST_SUITE
( WxFilename )
34
35
36
struct
WX_FILENAME_SPLIT_CASE
37
{
38
// Ctor params
39
std::string
m_path
;
40
std::string
m_name
;
41
42
// Split results
43
std::string
m_exp_name
;
44
std::string
m_exp_full_name
;
45
std::string
m_exp_path
;
46
std::string
m_exp_full_path
;
47
};
48
49
50
// clang-format off
51
static
const
std::vector<WX_FILENAME_SPLIT_CASE>
split_cases
= {
52
{
53
""
,
54
""
,
55
""
,
56
""
,
57
""
,
58
"/"
,
// This doesn't look right...
59
},
60
{
61
""
,
62
"name.ext"
,
63
"name"
,
64
"name.ext"
,
65
""
,
66
"/name.ext"
,
// This doesn't look right...
67
},
68
{
69
"/tmp/example"
,
70
""
,
71
""
,
72
""
,
73
"/tmp/example"
,
74
"/tmp/example/"
,
75
},
76
{
77
"/tmp/example"
,
78
"name.ext"
,
79
"name"
,
80
"name.ext"
,
81
"/tmp/example"
,
82
"/tmp/example/name.ext"
,
83
},
84
{
85
"/tmp/example"
,
86
"name"
,
// no extension
87
"name"
,
88
"name"
,
89
"/tmp/example"
,
90
"/tmp/example/name"
,
91
},
92
{
93
"/tmp/example"
,
94
"name.ext1.ext2"
,
// two extensions
95
"name.ext1"
,
// remove the first one
96
"name.ext1.ext2"
,
97
"/tmp/example"
,
98
"/tmp/example/name.ext1.ext2"
,
99
},
100
};
101
// clang-format on
102
106
BOOST_AUTO_TEST_CASE
( Split )
107
{
108
for
(
const
auto
& c :
split_cases
)
109
{
110
std::stringstream ss;
111
ss << c.m_path <<
", "
<< c.m_name;
112
BOOST_TEST_CONTEXT
( ss.str() )
113
{
114
// Const: all methods called must be const
115
const
WX_FILENAME
wx_fn( c.m_path, c.m_name );
116
117
BOOST_CHECK_EQUAL
( c.m_exp_name, wx_fn.
GetName
() );
118
BOOST_CHECK_EQUAL
( c.m_exp_full_name, wx_fn.
GetFullName
() );
119
BOOST_CHECK_EQUAL
( c.m_exp_path, wx_fn.
GetPath
() );
120
BOOST_CHECK_EQUAL
( c.m_exp_full_path, wx_fn.
GetFullPath
() );
121
}
122
}
123
}
124
125
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:46
WX_FILENAME::GetPath
wxString GetPath() const
Definition
wx_filename.cpp:56
WX_FILENAME::GetName
wxString GetName() const
Definition
wx_filename.cpp:43
WX_FILENAME::GetFullPath
wxString GetFullPath() const
Definition
wx_filename.cpp:62
WX_FILENAME::GetFullName
wxString GetFullName() const
Definition
wx_filename.cpp:50
WX_FILENAME_SPLIT_CASE
Declare the test suite.
Definition
test_wx_filename.cpp:37
WX_FILENAME_SPLIT_CASE::m_exp_name
std::string m_exp_name
Definition
test_wx_filename.cpp:43
WX_FILENAME_SPLIT_CASE::m_path
std::string m_path
Definition
test_wx_filename.cpp:39
WX_FILENAME_SPLIT_CASE::m_name
std::string m_name
Definition
test_wx_filename.cpp:40
WX_FILENAME_SPLIT_CASE::m_exp_path
std::string m_exp_path
Definition
test_wx_filename.cpp:45
WX_FILENAME_SPLIT_CASE::m_exp_full_name
std::string m_exp_full_name
Definition
test_wx_filename.cpp:44
WX_FILENAME_SPLIT_CASE::m_exp_full_path
std::string m_exp_full_path
Definition
test_wx_filename.cpp:46
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:654
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:51
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(Split)
Check the various split cases work correctly.
Definition
test_wx_filename.cpp:106
unit_test_utils.h
wx_filename.h
src
qa
tests
common
test_wx_filename.cpp
Generated on Fri Jun 26 2026 00:05:43 for KiCad PCB EDA Suite by
1.13.2