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 (C) 2019 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
30
31// Code under test
32#include <wx_filename.h>
33
37BOOST_AUTO_TEST_SUITE( WxFilename )
38
39
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
55static 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
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
A wrapper around a wxFileName which is much more performant with a subset of the API.
Definition: wx_filename.h:50
wxString GetPath() const
Definition: wx_filename.cpp:60
wxString GetName() const
Definition: wx_filename.cpp:47
wxString GetFullPath() const
Definition: wx_filename.cpp:66
wxString GetFullName() const
Definition: wx_filename.cpp:54
Declare the test suite.
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_SUITE_END()
static const std::vector< WX_FILENAME_SPLIT_CASE > split_cases
BOOST_AUTO_TEST_CASE(Split)
Check the various split cases work correctly.