diff --git a/src/konsole_wcwidth.cpp b/src/konsole_wcwidth.cpp index ba5e06a8..356a3504 100644 --- a/src/konsole_wcwidth.cpp +++ b/src/konsole_wcwidth.cpp @@ -68,6 +68,7 @@ // Own #include "konsole_wcwidth.h" +#include "konsole_export.h" struct interval { unsigned long first; @@ -125,7 +126,7 @@ static int bisearch(unsigned long ucs, const struct interval* table, int max) * in ISO 10646. */ -int konsole_wcwidth(quint16 oucs) +int KONSOLEPRIVATE_EXPORT konsole_wcwidth(quint16 oucs) { /* NOTE: It is not possible to compare quint16 with the new last four lines of characters, * therefore this cast is now necessary. diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt index 1705eed8..9d402990 100644 --- a/src/tests/CMakeLists.txt +++ b/src/tests/CMakeLists.txt @@ -18,6 +18,9 @@ endif() kde4_add_unit_test(CharacterColorTest CharacterColorTest.cpp) target_link_libraries(CharacterColorTest ${KONSOLE_TEST_LIBS}) +kde4_add_unit_test(CharacterWidthTest CharacterWidthTest.cpp) +target_link_libraries(CharacterWidthTest ${KONSOLE_TEST_LIBS}) + if (NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin") kde4_add_unit_test(DBusTest DBusTest.cpp) target_link_libraries(DBusTest ${KONSOLE_TEST_LIBS}) diff --git a/src/tests/CharacterWidthTest.cpp b/src/tests/CharacterWidthTest.cpp new file mode 100644 index 00000000..771232ed --- /dev/null +++ b/src/tests/CharacterWidthTest.cpp @@ -0,0 +1,71 @@ +/* + Copyright 2014 by Kurt Hindenburg + + 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, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301 USA. +*/ + +// Own +#include "CharacterWidthTest.h" + +// KDE +#include + +#include "../konsole_wcwidth.h" +#include "../konsole_export.h" + +using namespace Konsole; + +void CharacterWidthTest::testWidth_data() +{ + QTest::addColumn("character"); + QTest::addColumn("width"); + + /* This is a work in progress.... */ + + /* konsole_wcwidth uses -1 C0/C1 and DEL */ + QTest::newRow("0xE007F") << quint16(0xE007F) << -1; + + QTest::newRow("0x0300") << quint16(0x0300) << 0; + QTest::newRow("0x070F") << quint16(0x070F) << 0; + QTest::newRow("0x1160") << quint16(0x1160) << 0; + QTest::newRow("0x10300") << quint16(0x10300) << 0; + + QTest::newRow("a") << quint16('a') << 1; + QTest::newRow("0x00AD") << quint16(0x00AD) << 1; + QTest::newRow("0x00A0") << quint16(0x00A0) << 1; + QTest::newRow("0x10FB") << quint16(0x10FB) << 1; + QTest::newRow("0xFF76") << quint16(0xFF76) << 1; + QTest::newRow("0x103A0") << quint16(0x103A0) << 1; + QTest::newRow("0x10A06") << quint16(0x10A06) << 1; + + QTest::newRow("0x3000") << quint16(0x3000) << 2; + QTest::newRow("0xFF01") << quint16(0xFF01) << 2; + QTest::newRow("0xFF60") << quint16(0xFF60) << 2; + QTest::newRow("0xFFe0") << quint16(0xFFe6) << 2; +} + +void CharacterWidthTest::testWidth() +{ + QFETCH(quint16, character); + + QEXPECT_FAIL("0xFF60", "0xFF60 is FULLWIDTH RIGHT WHITE PARENTHESIS and should be 2 wide", Continue); + QTEST(konsole_wcwidth(character), "width"); +} + +QTEST_KDEMAIN_CORE(CharacterWidthTest) + +#include "CharacterWidthTest.moc" + diff --git a/src/tests/CharacterWidthTest.h b/src/tests/CharacterWidthTest.h new file mode 100644 index 00000000..0f9c87ed --- /dev/null +++ b/src/tests/CharacterWidthTest.h @@ -0,0 +1,42 @@ +/* + Copyright 2014 by Kurt Hindenburg + + 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, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301 USA. +*/ + +#ifndef CHARACTERTWIDTHTEST_H +#define CHARACTERTWIDTHTEST_H + +#include + +namespace Konsole +{ + +class CharacterWidthTest : public QObject +{ + Q_OBJECT + +private slots: + + void testWidth_data(); + void testWidth(); + +}; + +} + +#endif // CHARACTERTWIDTHTEST_H +