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
26
27// Code under test
28#include <wx_filename.h>
29
33BOOST_AUTO_TEST_SUITE( WxFilename )
34
35
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
51static 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
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
A wrapper around a wxFileName which is much more performant with a subset of the API.
Definition wx_filename.h:46
wxString GetPath() const
wxString GetName() const
wxString GetFullPath() const
wxString GetFullName() const
Declare the test suite.
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_SUITE_END()
BOOST_TEST_CONTEXT("Test Clearance")
BOOST_CHECK_EQUAL(result, "25.4")
static const std::vector< WX_FILENAME_SPLIT_CASE > split_cases
BOOST_AUTO_TEST_CASE(Split)
Check the various split cases work correctly.