KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_utf8.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
20
#include <
qa_utils/wx_utils/unit_test_utils.h
>
21
22
#include <
core/utf8.h
>
23
24
#include <algorithm>
25
#include <iostream>
26
27
#define UTF8_INIT "This is a test of UTF-8: ü‱☺😕😱"
28
struct
Utf8Fixture
29
{
30
};
31
32
36
BOOST_FIXTURE_TEST_SUITE( Utf8,
Utf8Fixture
)
37
38
39
42
BOOST_AUTO_TEST_CASE
( Utf8AndStdString )
43
{
44
std::string str {
UTF8_INIT
};
45
46
UTF8
utf8_inited {
UTF8_INIT
};
47
UTF8
utf8_copied_from_stdstr = str;
48
49
BOOST_CHECK_EQUAL
( utf8_inited, utf8_copied_from_stdstr );
50
51
UTF8
utf8_copied_from_utf8 = utf8_inited;
52
53
BOOST_CHECK_EQUAL
( utf8_inited, utf8_copied_from_utf8 );
54
}
55
56
60
BOOST_AUTO_TEST_CASE
( Utf8AndWx )
61
{
62
UTF8
utf8_inited {
UTF8_INIT
};
63
wxString wx_inited = wxString::FromUTF8(
UTF8_INIT
);
64
65
// Check that we can copy convert WxString and compare
66
wxString wx_copied_from_utf8 = utf8_inited;
67
BOOST_CHECK_EQUAL
( wx_inited, wx_copied_from_utf8 );
68
69
// Check we can copy-construct from a WxString
70
UTF8
utf8_copied_from_wxstring = wx_inited;
71
BOOST_CHECK_EQUAL
( utf8_inited, utf8_copied_from_wxstring );
72
}
73
77
BOOST_AUTO_TEST_CASE
( UniIterNull )
78
{
79
UTF8::uni_iter
it;
80
const
UTF8::uni_iter
null;
81
82
// Check nulls are equivalent
83
BOOST_CHECK( it == null );
84
85
// check null string start == end
86
UTF8
uNull {
""
};
87
BOOST_CHECK( uNull.ubegin() == uNull.uend() );
88
}
89
93
BOOST_AUTO_TEST_CASE
( UniIterIncrement )
94
{
95
UTF8
u0 {
"inp\ua740t"
};
96
97
UTF8::uni_iter
it;
98
const
UTF8::uni_iter
begin = u0.ubegin();
99
const
UTF8::uni_iter
end
= u0.uend();
100
101
// Check copy-construction and equality operator
102
it = begin;
103
BOOST_CHECK( it == begin );
104
BOOST_CHECK( it >= begin );
105
106
// Check de-referencing
107
BOOST_CHECK_EQUAL
( *it,
'i'
);
108
109
// postfix increment - normal char and inequality operators
110
it++;
111
BOOST_CHECK( it != begin );
112
BOOST_CHECK( it > begin );
113
BOOST_CHECK( !( begin >= it ) );
114
BOOST_CHECK( it <
end
);
115
BOOST_CHECK( it <=
end
);
116
BOOST_CHECK_EQUAL
( *it,
'n'
);
117
118
// prefix increment - normal char
119
++it;
120
BOOST_CHECK_EQUAL
( *it,
'p'
);
121
122
// increment to a unicode char
123
++it;
124
BOOST_CHECK_EQUAL
( *it, 0xA740 );
125
126
// and again to the next char - normal again
127
++it;
128
BOOST_CHECK_EQUAL
( *it,
't'
);
129
130
// and now we should be at the end
131
++it;
132
BOOST_CHECK( it ==
end
);
133
BOOST_CHECK( it <=
end
);
134
BOOST_CHECK( !( it <
end
) );
135
}
136
137
138
BOOST_AUTO_TEST_SUITE_END
()
UTF8::uni_iter
uni_iter is a non-mutating iterator that walks through unicode code points in the UTF8 encoded string...
Definition
utf8.h:226
UTF8
An 8 bit string that is assuredly encoded in UTF8, and supplies special conversion support to and fro...
Definition
utf8.h:67
Utf8Fixture
Definition
test_utf8.cpp:29
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
Definition
test_api_enums.cpp:71
BOOST_AUTO_TEST_SUITE_END
BOOST_AUTO_TEST_SUITE_END()
end
VECTOR2I end
Definition
test_shape_arc.cpp:622
BOOST_CHECK_EQUAL
BOOST_CHECK_EQUAL(result, "25.4")
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(Utf8AndStdString)
Declares a struct as the Boost test fixture.
Definition
test_utf8.cpp:42
UTF8_INIT
#define UTF8_INIT
Definition
test_utf8.cpp:27
unit_test_utils.h
utf8.h
src
qa
tests
common
test_utf8.cpp
Generated on Fri Jun 26 2026 00:05:43 for KiCad PCB EDA Suite by
1.13.2