2004-02-15 10:43:21 -05:00
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// Name: tests/mbconv/main.cpp
|
|
|
|
|
// Purpose: wxMBConv unit test
|
|
|
|
|
// Author: Vadim Zeitlin
|
|
|
|
|
// Created: 14.02.04
|
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
|
// Copyright: (c) 2003 TT-Solutions
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
// headers
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
2004-04-01 02:17:50 -05:00
|
|
|
|
#include "wx/wxprec.h"
|
|
|
|
|
|
|
|
|
|
#ifdef __BORLANDC__
|
|
|
|
|
#pragma hdrstop
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifndef WX_PRECOMP
|
|
|
|
|
#include "wx/wx.h"
|
|
|
|
|
#endif // WX_PRECOMP
|
|
|
|
|
|
2004-02-15 10:43:21 -05:00
|
|
|
|
#include "wx/strconv.h"
|
|
|
|
|
#include "wx/string.h"
|
|
|
|
|
|
2004-06-18 11:44:46 -04:00
|
|
|
|
#if wxUSE_FONTMAP
|
|
|
|
|
#include "wx/fontmap.h"
|
|
|
|
|
#endif // wxUSE_FONTMAP
|
|
|
|
|
|
2004-02-15 10:43:21 -05:00
|
|
|
|
#include "wx/cppunit.h"
|
|
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
// test class
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
class MBConvTestCase : public CppUnit::TestCase
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
MBConvTestCase() { }
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
CPPUNIT_TEST_SUITE( MBConvTestCase );
|
|
|
|
|
CPPUNIT_TEST( WC2CP1250 );
|
2004-06-18 11:44:46 -04:00
|
|
|
|
CPPUNIT_TEST( Charsets );
|
2004-02-15 10:43:21 -05:00
|
|
|
|
CPPUNIT_TEST_SUITE_END();
|
|
|
|
|
|
|
|
|
|
void WC2CP1250();
|
2004-06-18 11:44:46 -04:00
|
|
|
|
void Charsets();
|
2004-02-15 10:43:21 -05:00
|
|
|
|
|
2004-04-01 02:17:50 -05:00
|
|
|
|
DECLARE_NO_COPY_CLASS(MBConvTestCase)
|
2004-02-15 10:43:21 -05:00
|
|
|
|
};
|
|
|
|
|
|
2004-03-03 17:53:52 -05:00
|
|
|
|
// register in the unnamed registry so that these tests are run by default
|
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION( MBConvTestCase );
|
|
|
|
|
|
|
|
|
|
// also include in it's own registry so that these tests can be run alone
|
2004-02-15 10:43:21 -05:00
|
|
|
|
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( MBConvTestCase, "MBConvTestCase" );
|
|
|
|
|
|
|
|
|
|
void MBConvTestCase::WC2CP1250()
|
|
|
|
|
{
|
|
|
|
|
static const struct Data
|
|
|
|
|
{
|
|
|
|
|
const wchar_t *wc;
|
|
|
|
|
const char *cp1250;
|
|
|
|
|
} data[] =
|
|
|
|
|
{
|
|
|
|
|
{ L"hello", "hello" }, // test that it works in simplest case
|
2004-03-03 17:53:52 -05:00
|
|
|
|
{ L"<EFBFBD> of <20> is <20>", NULL }, // this should fail as cp1250 doesn't have 1/2
|
2004-02-15 10:43:21 -05:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
wxCSConv cs1250(wxFONTENCODING_CP1250);
|
|
|
|
|
for ( size_t n = 0; n < WXSIZEOF(data); n++ )
|
|
|
|
|
{
|
|
|
|
|
const Data& d = data[n];
|
2004-03-03 17:53:52 -05:00
|
|
|
|
if (d.cp1250)
|
|
|
|
|
{
|
|
|
|
|
CPPUNIT_ASSERT( strcmp(cs1250.cWC2MB(d.wc), d.cp1250) == 0 );
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2004-03-05 18:14:57 -05:00
|
|
|
|
CPPUNIT_ASSERT( (const char*)cs1250.cWC2MB(d.wc) == NULL );
|
2004-03-03 17:53:52 -05:00
|
|
|
|
}
|
2004-02-15 10:43:21 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
2004-06-18 11:44:46 -04:00
|
|
|
|
|
|
|
|
|
void MBConvTestCase::Charsets()
|
|
|
|
|
{
|
|
|
|
|
#if wxUSE_FONTMAP
|
|
|
|
|
|
|
|
|
|
static const wxChar *charsets[] =
|
|
|
|
|
{
|
|
|
|
|
// some vali charsets
|
|
|
|
|
_T("us-ascii" ),
|
|
|
|
|
_T("iso8859-1" ),
|
|
|
|
|
_T("iso-8859-12" ),
|
|
|
|
|
_T("koi8-r" ),
|
|
|
|
|
_T("utf-7" ),
|
|
|
|
|
_T("cp1250" ),
|
|
|
|
|
_T("windows-1252"),
|
|
|
|
|
|
|
|
|
|
// and now some bogus ones
|
|
|
|
|
_T("" ),
|
|
|
|
|
_T("cp1249" ),
|
|
|
|
|
_T("iso--8859-1" ),
|
|
|
|
|
_T("iso-8859-19" ),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static const wxChar *names[] =
|
|
|
|
|
{
|
|
|
|
|
// some vali charsets
|
|
|
|
|
_T("default" ),
|
|
|
|
|
_T("iso-8859-1" ),
|
|
|
|
|
_T("iso-8859-12" ),
|
|
|
|
|
_T("koi8-r" ),
|
|
|
|
|
_T("utf-7" ),
|
|
|
|
|
_T("windows-1250"),
|
|
|
|
|
_T("windows-1252"),
|
|
|
|
|
|
|
|
|
|
// and now some bogus ones
|
|
|
|
|
_T("default" ),
|
|
|
|
|
_T("unknown--1" ),
|
|
|
|
|
_T("unknown--1" ),
|
|
|
|
|
_T("unknown--1" ),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static const wxChar *descriptions[] =
|
|
|
|
|
{
|
|
|
|
|
// some vali charsets
|
|
|
|
|
_T("Default encoding" ),
|
|
|
|
|
_T("Western European (ISO-8859-1)" ),
|
|
|
|
|
_T("Indian (ISO-8859-12)" ),
|
|
|
|
|
_T("KOI8-R" ),
|
|
|
|
|
_T("Unicode 7 bit (UTF-7)" ),
|
|
|
|
|
_T("Windows Central European (CP 1250)"),
|
|
|
|
|
_T("Windows Western European (CP 1252)"),
|
|
|
|
|
|
|
|
|
|
// and now some bogus ones
|
|
|
|
|
_T("Default encoding" ),
|
|
|
|
|
_T("Unknown encoding (-1)" ),
|
|
|
|
|
_T("Unknown encoding (-1)" ),
|
|
|
|
|
_T("Unknown encoding (-1)" ),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
for ( size_t n = 0; n < WXSIZEOF(charsets); n++ )
|
|
|
|
|
{
|
|
|
|
|
wxFontEncoding enc = wxFontMapper::Get()->CharsetToEncoding(charsets[n]);
|
|
|
|
|
CPPUNIT_ASSERT( wxFontMapper::Get()->GetEncodingName(enc) == names[n] );
|
|
|
|
|
CPPUNIT_ASSERT( wxFontMapper::Get()->GetEncodingDescription(enc) == descriptions[n] );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif // wxUSE_FONTMAP
|
|
|
|
|
}
|