Commit Graph

55 Commits

Author SHA1 Message Date
Vadim Zeitlin
5bc208df3c Correct UTF-8 encoding of U+FFFF
Overlong (and hence invalid) 4-byte encoding was used for this character
instead of the correct 3-byte 0xEF 0xBF 0xBF sequence.

Fix this by using 3 bytes for the code points up to 0xFFFF included,
instead of excluding it as was done before.

Closes #17920.
2018-01-29 00:48:56 +01:00
Vadim Zeitlin
9d5ff447e1 Add subsections to MBConvTestCase::NonBMPCharTests()
This allows to immediately see which of the tests failed just looking at
the logs instead of having to check the failure line number manually.

No real changes.
2017-11-09 23:38:03 +01:00
Vadim Zeitlin
0425b8b7f0 Properly terminate UTF-16 strings in cMB2WC() unit test
Such strings must have 2 NUL bytes at the end, just the one added
implicitly to all C strings isn't enough.
2017-11-05 17:18:58 +01:00
Vadim Zeitlin
c47acbeb52 Fix wxMBConv::cWC2MB() and cMB2WC() returned buffer length
This commit refactors the overloads of cMB2WC() and cWC2MB() methods
taking raw pointers and buffers to reuse the same code and fixes the
wrong length of the buffer returned by cWC2MB(wchar_t*) overload for
conversions using multiple bytes to represent the NUL terminator
character (it previously was wrong for UTF-16 and UTF-32 conversions due
to wrongly subtracting 1 from the length when creating it instead of
correctly subtracting GetMBNulLen()) and the wrong length of the buffer
returned from cMB2WC(char*) overload where no adjustment for the
trailing NUL was done at all.

Also return simple default-constructed buffers from these methods in
case of failure instead of using wxScopedCharBuffer::CreateNonOwned()
which is less obvious and less efficient (even if the latter probably
doesn't matter here because it's only done in case of an error).

Finally, add tests checking that using WC2MB() or either of cWC2MB()
overloads returns the buffers of the same length and with the same
contents.
2017-11-03 23:26:39 +01:00
Vadim Zeitlin
e70fc11ef1 Replace CppUnit with Catch for unit tests
Drop the legacy CppUnit testing framework used for the unit tests.
Replacing it with Catch has the advantage of not requiring CppUnit
libraries to be installed on the system in order to be able to run
tests (Catch is header-only and a copy of it is now included in the
main repository itself) and, in the future, of being able to write
the tests in a much more natural way.

For now, however, avoid changing the existing tests code as much as
[reasonably] possible to avoid introducing bugs in them and provide
the CppUnit compatibility macros in the new wx/catch_cppunit.h header
which allow to preserve the 99% of the existing code unchanged. Some
of the required changes are:

 - Decompose asserts using "a && b" conditions into multiple asserts
   checking "a" and "b" independently. This would have been better
   even with CppUnit (to know which part of condition exactly failed)
   and is required with Catch.

 - Use extra parentheses around such conditions when they can't be
   easily decomposed in the arrays test, due to the use of macros.
   This is not ideal from the point of view of messages given when
   the tests fail but will do for now.

 - Rewrite asserts using "a || b" as a combination of condition
   checks and assert macros. Again, this is better anyhow, and is
   required with Catch. Incidentally, this allowed to fix a bug in
   the "exec" unit test which didn't leave enough time for the new
   process to be launched before trying to kill it.

 - Remove multiple CPPUNIT_TEST_SUITE_NAMED_REGISTRATION() macros,
   our emulation of this macro can be used only once.

 - Provide string conversions using Catch-specific StringMaker for
   a couple of types.

 - Replace custom wxImage comparison with a Catch-specific matcher
   class.

 - Remove most of test running logic from test.cpp, in particular don't
   parse command line ourselves any longer but use Catch built-in
   command line parser. This is a source of a minor regression:
   previously, both "Foo" and "FooTestCase" could be used as the name of
   the test to run, but now only the latter is accepted.
2017-11-02 01:53:16 +01:00
Cătălin Răceanu
e8207c8c59 Fix building tests with wxUSE_UNSAFE_WXSTRING_CONV==0
Avoid relying on implicit conversions to std::string in the tests code.
2017-02-24 15:37:37 +01:00
ARATA Mizuki
0c02d70fa5 Add a test checking that conversions involving surrogates work
After the fixes in the previous commits conversions between wchar_t containing
surrogates and UTF-{8,16,32} work correctly, so add a test ensuring that this
is the case.

Notice that other conversions are still broken in presence of surrogates.

See #17070.
2015-11-13 20:32:24 +01:00
Vadim Zeitlin
37dd89a0da Don't rely on wxMBConv::cWC2MB(NULL) returning the exact byte count
UTF-32 conversions use a useful optimization by avoiding the extra scan of the
input wchar_t string in their FromWChar() and cWC2MB() implementation when
they are only asked to compute the required buffer size without actually doing
the conversion. However this means that for an input string containing UTF-16
surrogates (which is possible under MSW where wchar_t is 16 bits) the actual
size of the output string can be smaller than that returned by FromWChar(NULL).

Document that this may happen and avoid relying on the exact equality in the
tests.

See #17070.
2015-11-13 19:36:33 +01:00
Vadim Zeitlin
048ba4b509 Fail to convert wide string with incomplete surrogates to UTF-8
Correctly fail if the wide string being converted is UTF-16 encoded (which can
only happen on platforms using 16 bit wchar_t, i.e. MSW) and ends in the
middle of a surrogate pair.

Notice that other conversions still wrongly encode invalid wchar_t sequences
such as 0xd800 not followed by anything, this will need to be fixed in the
future, but for now at least make it work for the most commonly used
conversion.

See #17070.
2015-11-13 19:36:32 +01:00
Dimitri Schoolwerth
8f8d58d193 Use wx-prefixed macros throughout the repository.
Change {DECLARE,IMPLEMENT}_*CLASS and {DECLARE,BEGIN,END}_EVENT_TABLE
occurrences to use the wx-prefixed version of the macros.
2015-04-23 22:00:35 +04:00
Vadim Zeitlin
3f66f6a5b3 Remove all lines containing cvs/svn "$Id$" keyword.
This keyword is not expanded by Git which means it's not replaced with the
correct revision value in the releases made using git-based scripts and it's
confusing to have lines with unexpanded "$Id$" in the released files. As
expanding them with Git is not that simple (it could be done with git archive
and export-subst attribute) and there are not many benefits in having them in
the first place, just remove all these lines.

If nothing else, this will make an eventual transition to Git simpler.

Closes #14487.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@74602 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
2013-07-26 16:02:46 +00:00
Dimitri Schoolwerth
e3778b4d9c No code changes, fixed some typos.
Changed several occurrences of "it's" where "its" is meant, as well as a few other minor typos.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@67656 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
2011-04-30 10:57:04 +00:00
Vadim Zeitlin
87f528f15b Disable unit tests which can't work in ANSI build.
Disable unit tests involving operations (such as conversions between UTF and
anything but plain ASCII) not available in ANSI build.

This fixes the test suite for non-Unicode build under Unix.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@66103 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
2010-11-10 13:53:49 +00:00
Vadim Zeitlin
dbd92d3d0c No real changes, just fix a warning in the test suite.
Don't assign wxNO_LEN to int variable, this results in gcc warnings about
overflow in implicit constant conversion.

Use size_t for the variable containing string length to fix it.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@65838 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
2010-10-17 13:59:55 +00:00
Vadim Zeitlin
12249b199d Run MBConvTestCase::LibcTests() only for MSVC and not other Windows compilers.
This test fails for MinGW, probably because its CRT doesn't use the same
locale names as MSVC CRT. Just disable it for now, as it was already disabled
for non-MSW platforms.

Also use LocaleSetter class (extracted from CLocaleSetter) to change the
locale for this test duration only to avoid affecting any tests running after
it.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@65743 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
2010-10-03 17:15:46 +00:00
Vadim Zeitlin
5d509cacfb Show the failing string when conversion fails in MBConvTestCase.
No real changes, just give more information when a test fails in
MBConvTestCase::TestDecoder().

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@65742 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
2010-10-03 17:15:37 +00:00
Vadim Zeitlin
cbc2233eb9 No real changes, just simplify some MBConvTestCase code.
Remove unnecessary casts and initialize the variable with its contents
directly instead of using strange looking wxWCharBuffer ctor from size_t (even
if it did work, it was unnecessary).

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@65741 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
2010-10-03 17:15:31 +00:00
Vadim Zeitlin
9334ad1727 Correct wxConvAuto::ToWChar() behaviour with wxNO_LEN input size.
We didn't handle the case when the length of the input buffer was not
specified correctly and wxConvAuto::DetectBOM() could read beyond the end of
input. Moreover, the unit test actually relied on this as it didn't pass the
correct length for the literal strings with embedded NULs. This somehow worked
with MSVC but failed with MinGW (see #10713).

Correct the code to handle wxNO_LEN case correctly and fix the unit test to
pass the correct lengths.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@65739 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
2010-10-03 17:15:18 +00:00
Václav Slavík
8d94819c43 Remove wxUSE_WCHAR_T checks.
wxWidgets requires wchar_t for some time now; wx/chartype.h has a check
to fail complation without it. Simplify code by removing now-dead code
for the !wxUSE_WCHAR_T case.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@63991 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
2010-04-16 10:43:18 +00:00
Vadim Zeitlin
4cb0e8d05c Fix wxConvAuto behaviour when it is used by wxTextInputStream.
wxConvAuto implicitly supposed that the chunk of data passed to it for
translation was big enough to allow it to at least detect the BOM from it.
However this isn't necessarily the case and never is with wxTextInputStream
which reads the bytes one by one.

Fix this by waiting until we have enough data to be able to detect the BOM.
This still doesn't fix the problem with streams without BOM and the
corresponding unit test still fails -- it will need to be fixed at the level
of wxTextInputStream itself later but handling correctly the cases when a BOM
is present is already better than before.

See #11570.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@63064 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
2010-01-04 12:22:49 +00:00
Vadim Zeitlin
2730723380 Correct two bugs in wxMBConv::FromWChar() with non NUL-terminated strings.
The variable "lenChunk" was incorrectly used as the length of the wide string
chunk which could result in wrong output.

Worse, the output buffer could be overflown for the final chunk because it
didn't have to have enough space for the trailing NUL(s) in it.

Fix both bugs and added unit tests for them.

Based on patch by Kuang-che Wu.

Closes #11486.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@62793 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
2009-12-06 02:30:05 +00:00
Vadim Zeitlin
9a83f86094 Globally replace _T() with wxT().
Standardize on using a single macro across all wxWidgets sources and solve the name clash with Sun CC standard headers (see #10660).

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@61508 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
2009-07-23 20:30:22 +00:00
Vadim Zeitlin
93a800a95e minor icc warning fixes
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@56845 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
2008-11-19 09:55:27 +00:00
Vadim Zeitlin
097a92e228 blind fix for yet another VC6 compilation error
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@56657 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
2008-11-03 01:11:59 +00:00
Vadim Zeitlin
51725fc0c2 reverted the change of r56246 and keep the old behaviour of MB2WC/WC2MB; document it even more clearly and correct code using these functions incorrectly
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@56394 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
2008-10-17 11:31:22 +00:00
Vadim Zeitlin
8a493b67ac fix off by one bug in the buffer size (fixes #10039)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@56246 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
2008-10-12 14:51:45 +00:00
Vadim Zeitlin
fec42c21ef added wxConvISO8859_1 test
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@54647 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
2008-07-16 00:48:47 +00:00
Vadim Zeitlin
ca8cf4fffb added wxTextOutputStream::Flush(): this is necessary with the stateful encodings, such as UTF-7
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@53890 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
2008-06-01 03:09:25 +00:00
Vadim Zeitlin
04080f208e make test failure in TestStreamDecoder more informative
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@53874 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
2008-05-31 02:46:22 +00:00
Vadim Zeitlin
78648f606d use more informative CPPUNIT_ASSERT_EQUAL instead of CPPUNIT_ASSERT
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@53873 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
2008-05-31 01:57:25 +00:00
Vadim Zeitlin
3af0741ccc compilation fix
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@47687 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
2007-07-23 22:33:44 +00:00
Václav Slavík
81e9dec6f5 use same names for test suites as the ones in ./test -l
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@46992 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
2007-06-28 07:54:15 +00:00
Václav Slavík
8650108199 don't use implicit wxString->char*/wchar_t* conversion, it will not be available in wxUSE_STL build in the future
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@46391 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
2007-06-10 17:42:41 +00:00
Michael Wetherell
1002abaa77 Register the test under the name displayed by "./test -l"
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@45708 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
2007-04-28 15:59:12 +00:00
Václav Slavík
75b16a30bd reverted previous commit and added a comment explaining why CByteArrayFormat should be kept
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@45390 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
2007-04-10 19:32:48 +00:00
Václav Slavík
0cdb0b9666 removed unused CByteArrayFormat function
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@45382 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
2007-04-10 13:37:27 +00:00
Vadim Zeitlin
4a9eae369e corrected signed/unsigned comparison warning
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@45254 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
2007-04-05 14:21:55 +00:00
Vadim Zeitlin
e6a87338f0 name the test just MBConv instead of MBConvTestCase
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@38584 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
2006-04-05 21:03:25 +00:00
Vadim Zeitlin
a29cce78aa tests for wxConvAuto
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@38571 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
2006-04-05 14:38:42 +00:00
Michael Wetherell
6565d564cb Compile fix for VC++ 5
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@35459 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
2005-09-10 21:21:27 +00:00
Michael Wetherell
c1ce4db1de wcslen and wcscmp replacements for systems that lack them, such as djgpp
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@35222 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
2005-08-18 11:40:40 +00:00
Michael Wetherell
8f1158912f wxMBConv test cases, patch 1179989 from Vince Harron
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@35160 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
2005-08-08 22:29:05 +00:00
Michael Wetherell
394579cf6f Replacements for some wcsxxx funcs for systems without them like osx 10.2.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@35159 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
2005-08-08 22:21:20 +00:00
Michael Wetherell
98cfeab393 Check the returned length too in the utf-8 tests
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@33311 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
2005-04-03 21:15:52 +00:00
Michael Wetherell
726c8204cd Tests for UTF-8 and PUA characters and octal escapes
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@33208 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
2005-03-30 23:03:36 +00:00
Ryan Norton
8899b155a1 [ 1068188 ] Precompiled header for the test program [Modified a bit]
Regen bakefiles for unit tests


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@30685 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
2004-11-22 05:00:19 +00:00
Ryan Norton
a9e9946154 Rename some tests to avoid conflicts with project builder GUI debugger
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@30194 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
2004-10-31 04:41:27 +00:00
Václav Slavík
a430a60fd1 compilation fix for gcc-3.4
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@27986 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
2004-06-23 22:18:11 +00:00
Václav Slavík
816b59debf moved wxFontMapper tests to its own file and testcase
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@27893 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
2004-06-19 14:01:44 +00:00
Włodzimierz Skiba
bc55323bc3 Charsets part moved from console sample to test unit.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@27883 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
2004-06-18 15:44:46 +00:00