mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-27 15:24:05 +00:00
iconv test case
This commit is contained in:
parent
d1c4611923
commit
4aa51268d3
23
autotests/goldendict-test.pro
Normal file
23
autotests/goldendict-test.pro
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
QT -= gui
|
||||||
|
|
||||||
|
CONFIG += c++11 console
|
||||||
|
CONFIG -= app_bundle
|
||||||
|
CONFIG += qtestlib
|
||||||
|
|
||||||
|
# You can make your code fail to compile if it uses deprecated APIs.
|
||||||
|
# In order to do so, uncomment the following line.
|
||||||
|
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
|
||||||
|
|
||||||
|
HEADERS+= \
|
||||||
|
../iconv.hh \
|
||||||
|
../wstring.hh \
|
||||||
|
../wstring_qt.hh
|
||||||
|
SOURCES += \
|
||||||
|
test-qtextcodec-convert.cpp \
|
||||||
|
../iconv.cc \
|
||||||
|
../wstring_qt.cc
|
||||||
|
|
||||||
|
# Default rules for deployment.
|
||||||
|
qnx: target.path = /tmp/$${TARGET}/bin
|
||||||
|
else: unix:!android: target.path = /opt/$${TARGET}/bin
|
||||||
|
!isEmpty(target.path): INSTALLS += target
|
49
autotests/test-qtextcodec-convert.cpp
Normal file
49
autotests/test-qtextcodec-convert.cpp
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
#include <QTest>
|
||||||
|
#include <QDate>
|
||||||
|
#include "../iconv.hh"
|
||||||
|
#include <string>
|
||||||
|
#include "../wstring_qt.hh"
|
||||||
|
|
||||||
|
//used to test Iconv.cc
|
||||||
|
class testQTextCodec : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
private slots:
|
||||||
|
void testConvert();
|
||||||
|
void testToWstring();
|
||||||
|
void testToUtf8();
|
||||||
|
};
|
||||||
|
|
||||||
|
void testQTextCodec::testConvert()
|
||||||
|
{
|
||||||
|
Iconv conv( "utf-8", Iconv::GdWchar );
|
||||||
|
const char s[] = { 0x61, 0x00, 0x00, 0x00, 0x62, 0x00, 0x00, 0x00, 0x63, 0x00, 0x00, 0x00 };
|
||||||
|
void const * in = &s[ 0 ];
|
||||||
|
size_t len = 12;
|
||||||
|
QString r = conv.convert( in, len );
|
||||||
|
QCOMPARE( r, "abc" );
|
||||||
|
}
|
||||||
|
|
||||||
|
void testQTextCodec::testToWstring()
|
||||||
|
{
|
||||||
|
const char s[] = { 0x00, 0x00, 0x00, 0x61, 0x00, 0x00, 0x00, 0x62, 0x00, 0x00, 0x00, 0x63 };
|
||||||
|
gd::wstring r1 = Iconv::toWstring( "UTF-32BE", s, 12 );
|
||||||
|
|
||||||
|
QCOMPARE( r1.size(), 3 );
|
||||||
|
QCOMPARE( r1, U"abc" );
|
||||||
|
char32_t * arr = (char32_t*)r1.c_str ();
|
||||||
|
QCOMPARE( arr[ 0 ], 0x00000061 );
|
||||||
|
}
|
||||||
|
|
||||||
|
void testQTextCodec::testToUtf8()
|
||||||
|
{
|
||||||
|
const char s[] = { 0x00, 0x00, 0x00, 0x61, 0x00, 0x00, 0x00, 0x62, 0x00, 0x00, 0x00, 0x63 };
|
||||||
|
std::string r1 = Iconv::toUtf8 ( "UTF-32BE", s, 12 );
|
||||||
|
|
||||||
|
QCOMPARE( r1.size(), 3 );
|
||||||
|
QCOMPARE( r1, u8"abc" );
|
||||||
|
char * arr = (char*)r1.c_str ();
|
||||||
|
QCOMPARE( arr[ 0 ], 0x61 );
|
||||||
|
}
|
||||||
|
QTEST_MAIN(testQTextCodec)
|
||||||
|
#include "test-qtextcodec-convert.moc"
|
|
@ -37,7 +37,6 @@ DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x050F00
|
||||||
DEFINES += MAKE_QTMULTIMEDIA_PLAYER
|
DEFINES += MAKE_QTMULTIMEDIA_PLAYER
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
!CONFIG( no_ffmpeg_player ) {
|
!CONFIG( no_ffmpeg_player ) {
|
||||||
DEFINES += MAKE_FFMPEG_PLAYER
|
DEFINES += MAKE_FFMPEG_PLAYER
|
||||||
}
|
}
|
||||||
|
|
5
iconv.cc
5
iconv.cc
|
@ -8,12 +8,7 @@
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include "wstring_qt.hh"
|
#include "wstring_qt.hh"
|
||||||
|
|
||||||
#ifdef __WIN32
|
|
||||||
char const * const Iconv::GdWchar = "UTF-32LE";
|
char const * const Iconv::GdWchar = "UTF-32LE";
|
||||||
#else
|
|
||||||
char const * const Iconv::GdWchar = "UTF-32LE";
|
|
||||||
#endif
|
|
||||||
|
|
||||||
char const * const Iconv::Utf16Le = "UTF-16LE";
|
char const * const Iconv::Utf16Le = "UTF-16LE";
|
||||||
char const * const Iconv::Utf8 = "UTF-8";
|
char const * const Iconv::Utf8 = "UTF-8";
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue