KiCad PCB EDA Suite
test_utf8.cpp File Reference
#include <qa_utils/wx_utils/unit_test_utils.h>
#include <utf8.h>
#include <algorithm>
#include <iostream>

Go to the source code of this file.

Classes

struct  Utf8Fixture
 

Macros

#define UTF8_INIT   "This is a test of UTF-8: ü‱☺😕😱"
 

Functions

 BOOST_AUTO_TEST_CASE (Utf8AndStdString)
 Declares a struct as the Boost test fixture. More...
 
 BOOST_AUTO_TEST_CASE (Utf8AndWx)
 Check direct and copy construction from wxString. More...
 
 BOOST_AUTO_TEST_CASE (UniIterNull)
 UTF8::uni_iter null tests. More...
 
 BOOST_AUTO_TEST_CASE (UniIterIncrement)
 UTF8::uni_iter increment tests. More...
 

Macro Definition Documentation

◆ UTF8_INIT

#define UTF8_INIT   "This is a test of UTF-8: ü‱☺😕😱"

Definition at line 31 of file test_utf8.cpp.

Function Documentation

◆ BOOST_AUTO_TEST_CASE() [1/4]

BOOST_AUTO_TEST_CASE ( Utf8AndStdString  )

Declares a struct as the Boost test fixture.

Check direct and copy construction from std::string

Definition at line 46 of file test_utf8.cpp.

47 {
48  std::string str { UTF8_INIT };
49 
50  UTF8 utf8_inited { UTF8_INIT };
51  UTF8 utf8_copied_from_stdstr = str;
52 
53  BOOST_CHECK_EQUAL( utf8_inited, utf8_copied_from_stdstr );
54 
55  UTF8 utf8_copied_from_utf8 = utf8_inited;
56 
57  BOOST_CHECK_EQUAL( utf8_inited, utf8_copied_from_utf8 );
58 }
An 8 bit string that is assuredly encoded in UTF8, and supplies special conversion support to and fro...
Definition: utf8.h:70
#define UTF8_INIT
Definition: test_utf8.cpp:31

References UTF8_INIT.

◆ BOOST_AUTO_TEST_CASE() [2/4]

BOOST_AUTO_TEST_CASE ( Utf8AndWx  )

Check direct and copy construction from wxString.

Definition at line 64 of file test_utf8.cpp.

65 {
66  UTF8 utf8_inited { UTF8_INIT };
67  wxString wx_inited = wxString::FromUTF8( UTF8_INIT );
68 
69  // Check that we can copy convert WxString and compare
70  wxString wx_copied_from_utf8 = utf8_inited;
71  BOOST_CHECK_EQUAL( wx_inited, wx_copied_from_utf8 );
72 
73  // Check we can copy-construct from a WxString
74  UTF8 utf8_copied_from_wxstring = wx_inited;
75  BOOST_CHECK_EQUAL( utf8_inited, utf8_copied_from_wxstring );
76 }
An 8 bit string that is assuredly encoded in UTF8, and supplies special conversion support to and fro...
Definition: utf8.h:70
#define UTF8_INIT
Definition: test_utf8.cpp:31

References UTF8_INIT.

◆ BOOST_AUTO_TEST_CASE() [3/4]

BOOST_AUTO_TEST_CASE ( UniIterNull  )

UTF8::uni_iter null tests.

Definition at line 81 of file test_utf8.cpp.

82 {
83  UTF8::uni_iter it;
84  const UTF8::uni_iter null;
85 
86  // Check nulls are equivalent
87  BOOST_CHECK( it == null );
88 
89  // check null string start == end
90  UTF8 uNull { "" };
91  BOOST_CHECK( uNull.ubegin() == uNull.uend() );
92 }
An 8 bit string that is assuredly encoded in UTF8, and supplies special conversion support to and fro...
Definition: utf8.h:70
BOOST_CHECK(v2.Cross(v1)==1)
uni_iter is a non-mutating iterator that walks through unicode code points in the UTF8 encoded string...
Definition: utf8.h:203

References BOOST_CHECK().

◆ BOOST_AUTO_TEST_CASE() [4/4]

BOOST_AUTO_TEST_CASE ( UniIterIncrement  )

UTF8::uni_iter increment tests.

Definition at line 97 of file test_utf8.cpp.

98 {
99  UTF8 u0 { "inp\ua740t" };
100 
101  UTF8::uni_iter it;
102  const UTF8::uni_iter begin = u0.ubegin();
103  const UTF8::uni_iter end = u0.uend();
104 
105  // Check copy-construction and equality operator
106  it = begin;
107  BOOST_CHECK( it == begin );
108  BOOST_CHECK( it >= begin );
109 
110  // Check de-referencing
111  BOOST_CHECK_EQUAL( *it, 'i' );
112 
113  // postfix increment - normal char and inequality operators
114  it++;
115  BOOST_CHECK( it != begin );
116  BOOST_CHECK( it > begin );
117  BOOST_CHECK( !( begin >= it ) );
118  BOOST_CHECK( it < end );
119  BOOST_CHECK( it <= end );
120  BOOST_CHECK_EQUAL( *it, 'n' );
121 
122  // prefix increment - normal char
123  ++it;
124  BOOST_CHECK_EQUAL( *it, 'p' );
125 
126  // increment to a unicode char
127  ++it;
128  BOOST_CHECK_EQUAL( *it, 0xA740 );
129 
130  // and again to the next char - normal again
131  ++it;
132  BOOST_CHECK_EQUAL( *it, 't' );
133 
134  // and now we should be at the end
135  ++it;
136  BOOST_CHECK( it == end );
137  BOOST_CHECK( it <= end );
138  BOOST_CHECK( !( it < end ) );
139 }
An 8 bit string that is assuredly encoded in UTF8, and supplies special conversion support to and fro...
Definition: utf8.h:70
BOOST_CHECK(v2.Cross(v1)==1)
uni_iter is a non-mutating iterator that walks through unicode code points in the UTF8 encoded string...
Definition: utf8.h:203

References BOOST_CHECK().