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
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: ü‱☺😕😱"
29{
30};
31
32
36BOOST_FIXTURE_TEST_SUITE( Utf8, Utf8Fixture )
37
38
39
42BOOST_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
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
78{
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
93BOOST_AUTO_TEST_CASE( UniIterIncrement )
94{
95 UTF8 u0 { "inp\ua740t" };
96
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
uni_iter is a non-mutating iterator that walks through unicode code points in the UTF8 encoded string...
Definition utf8.h:226
An 8 bit string that is assuredly encoded in UTF8, and supplies special conversion support to and fro...
Definition utf8.h:67
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE_END()
VECTOR2I end
BOOST_CHECK_EQUAL(result, "25.4")
BOOST_AUTO_TEST_CASE(Utf8AndStdString)
Declares a struct as the Boost test fixture.
Definition test_utf8.cpp:42
#define UTF8_INIT
Definition test_utf8.cpp:27