2018-09-25 12:41:20 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2021-10-06 02:46:53 +00:00
|
|
|
* Copyright (C) 2018 KiCad Developers, see AUTHORS.TXT for contributors.
|
2018-09-25 12:41:20 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2021-02-06 22:20:31 +00:00
|
|
|
#include <qa_utils/wx_utils/unit_test_utils.h>
|
2018-09-25 12:41:20 +00:00
|
|
|
|
|
|
|
#include <utf8.h>
|
|
|
|
|
|
|
|
#include <algorithm>
|
2018-10-18 14:39:32 +00:00
|
|
|
#include <iostream>
|
2018-09-25 12:41:20 +00:00
|
|
|
|
2018-10-18 14:39:32 +00:00
|
|
|
#define UTF8_INIT "This is a test of UTF-8: ü‱☺😕😱"
|
2018-09-25 12:41:20 +00:00
|
|
|
struct Utf8Fixture
|
|
|
|
{
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Declares a struct as the Boost test fixture.
|
|
|
|
*/
|
|
|
|
BOOST_FIXTURE_TEST_SUITE( Utf8, Utf8Fixture )
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check direct and copy construction from std::string
|
|
|
|
*/
|
|
|
|
BOOST_AUTO_TEST_CASE( Utf8AndStdString )
|
|
|
|
{
|
2018-10-18 14:39:32 +00:00
|
|
|
std::string str { UTF8_INIT };
|
2018-09-25 12:41:20 +00:00
|
|
|
|
2018-10-18 14:39:32 +00:00
|
|
|
UTF8 utf8_inited { UTF8_INIT };
|
2018-09-25 12:41:20 +00:00
|
|
|
UTF8 utf8_copied_from_stdstr = str;
|
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL( utf8_inited, utf8_copied_from_stdstr );
|
|
|
|
|
|
|
|
UTF8 utf8_copied_from_utf8 = utf8_inited;
|
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL( utf8_inited, utf8_copied_from_utf8 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check direct and copy construction from wxString
|
|
|
|
*/
|
|
|
|
BOOST_AUTO_TEST_CASE( Utf8AndWx )
|
|
|
|
{
|
2018-10-18 14:39:32 +00:00
|
|
|
UTF8 utf8_inited { UTF8_INIT };
|
|
|
|
wxString wx_inited = wxString::FromUTF8( UTF8_INIT );
|
2018-09-25 12:41:20 +00:00
|
|
|
|
|
|
|
// Check that we can copy convert WxString and compare
|
|
|
|
wxString wx_copied_from_utf8 = utf8_inited;
|
|
|
|
BOOST_CHECK_EQUAL( wx_inited, wx_copied_from_utf8 );
|
|
|
|
|
|
|
|
// Check we can copy-construct from a WxString
|
|
|
|
UTF8 utf8_copied_from_wxstring = wx_inited;
|
|
|
|
BOOST_CHECK_EQUAL( utf8_inited, utf8_copied_from_wxstring );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* UTF8::uni_iter null tests
|
|
|
|
*/
|
|
|
|
BOOST_AUTO_TEST_CASE( UniIterNull )
|
|
|
|
{
|
|
|
|
UTF8::uni_iter it;
|
|
|
|
const UTF8::uni_iter null;
|
|
|
|
|
|
|
|
// Check nulls are equivalent
|
|
|
|
BOOST_CHECK( it == null );
|
|
|
|
|
|
|
|
// check null string start == end
|
|
|
|
UTF8 uNull { "" };
|
|
|
|
BOOST_CHECK( uNull.ubegin() == uNull.uend() );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* UTF8::uni_iter increment tests
|
|
|
|
*/
|
|
|
|
BOOST_AUTO_TEST_CASE( UniIterIncrement )
|
|
|
|
{
|
|
|
|
UTF8 u0 { "inp\ua740t" };
|
|
|
|
|
|
|
|
UTF8::uni_iter it;
|
|
|
|
const UTF8::uni_iter begin = u0.ubegin();
|
|
|
|
const UTF8::uni_iter end = u0.uend();
|
|
|
|
|
|
|
|
// Check copy-construction and equality operator
|
|
|
|
it = begin;
|
|
|
|
BOOST_CHECK( it == begin );
|
|
|
|
BOOST_CHECK( it >= begin );
|
|
|
|
|
|
|
|
// Check de-referencing
|
|
|
|
BOOST_CHECK_EQUAL( *it, 'i' );
|
|
|
|
|
|
|
|
// postfix increment - normal char and inequality operators
|
|
|
|
it++;
|
|
|
|
BOOST_CHECK( it != begin );
|
|
|
|
BOOST_CHECK( it > begin );
|
|
|
|
BOOST_CHECK( !( begin >= it ) );
|
|
|
|
BOOST_CHECK( it < end );
|
|
|
|
BOOST_CHECK( it <= end );
|
|
|
|
BOOST_CHECK_EQUAL( *it, 'n' );
|
|
|
|
|
|
|
|
// prefix increment - normal char
|
|
|
|
++it;
|
|
|
|
BOOST_CHECK_EQUAL( *it, 'p' );
|
|
|
|
|
|
|
|
// increment to a unicode char
|
|
|
|
++it;
|
|
|
|
BOOST_CHECK_EQUAL( *it, 0xA740 );
|
|
|
|
|
|
|
|
// and again to the next char - normal again
|
|
|
|
++it;
|
|
|
|
BOOST_CHECK_EQUAL( *it, 't' );
|
|
|
|
|
|
|
|
// and now we should be at the end
|
|
|
|
++it;
|
|
|
|
BOOST_CHECK( it == end );
|
|
|
|
BOOST_CHECK( it <= end );
|
|
|
|
BOOST_CHECK( !( it < end ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_SUITE_END()
|