This test seems to consistently fail, but the failure can't be
reproduced locally nor debugged on buildbot, so, lacking any other
solution, just disable it.
Commit fc7f20c419 did fix a memory leak in
this test case, but at the price of introducing a crash due to deleting
the same pointer twice.
The real fix would be to change the code here to avoid returning a
pointer which sometimes needs to be deleted and sometimes must not, but
for now just add a crude check to avoid crashing.
This should have been done in b8c9cd3528
to avoid all warnings about std::auto_ptr<> being deprecated when using
g++ 6 or later which compiles in C++14 mode by default.
Contrary to what a comment in wxTextInputStream::GetChar() said, it is
actually possible to get more than one wide character from a call to
wxMBConv::ToWChar(len+1) even if a previous call to ToWChar(len) failed
to decode anything at all. This happens with wxConvAuto because it keeps
returning an error while it doesn't have enough data to determine if the
input contains a BOM or not, but then returns all the characters
examined so far at once if it turns out that there was no BOM, after
all.
The simplest case in which this created problems was just input starting
with a NUL byte as it as this could be a start of UTF-32BE BOM.
The fix consists in keeping all the bytes read but not yet decoded in
the m_lastBytes buffer and retrying to decode them during the next
GetChar() call. This implies keeping track of how much valid data is
there in m_lastBytes exactly, as we can't discard the already decoded
data immediately, but need to keep it in the buffer too, in order to
allow implementing UngetLast(). Incidentally, UngetLast() was totally
broken for UTF-16/32 input (containing NUL bytes in the middle of the
characters) before and this change fixes this as a side effect.
Also add test cases for previously failing inputs.
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.
It just doesn't work in the test, so live without it for now.
Also use CHECK() instead of CPPUNIT_ASSERT(), which expands into
REQUIRE(), for independent tests to let later tests to still be done
even if an earlier one fails.
The text and background colours are now stored in the rgba array instead
of fg_color and bg_color as with GTK+ 2 (the latter ones seem to have
been repurposed for the underline and strike-through colours!).
Also make the unit test for this method more robust.
The text control needs a few event loop iterations in order to layout
itself correctly, so give it up to 1 second to do it in order to avoid
spurious test failures that occurred if just a single call to wxYield()
were done (or, worse, none at all as it was the case before).
Also log the value returned by PositionToCoords() in case of test
failures.
While it is added implicitly when running all tests in the order, this
style wasn't used if just this test was ran using "-c PositionToCoords"
option.
Specify wxTE_MULTILINE in it explicitly to allow this to work too.
Change this method to consider the coordinates corresponding to the last
position (i.e. the one beyond the last text character) as valid, for
consistency with wxMSW and to conform to the documented behaviour.
Also give more information about the failures in the corresponding unit
test to make debugging problems with this function simpler.
The code of ziptest and tartest classes still compiled, but actually
didn't do anything during the run-time because makeSuite() method was
never called.
Replace this unused method with DoRunTest() and override runTest() in
the test suite classes to actually run the tests.
This was broken by 1c946a469a and resulted
in test failures in OwnerDrawnComboBoxTestCase::TextChangeEvents() unit
test because wxOwnerDrawnComboBox::Clear() used SetValue("") and didn't
generate any events any more.
Fix this regression by explicitly sending an event if we're returning
early and add a unit test explicitly checking that SetValue("") does
generate an event.
The warnings are justified as the functions defined by the event table
macros are indeed not used here because we only write them to test that
they compile, but not useful, so suppress them.
wxUIActionSimulator is just too unreliable to be used there, so while
fixing it should really be a priority, for now at least prevent these
spurious failures from masking any other ones, which indicate real
problems that need to be fixed.
Notice that these tests can still be enabled by setting the environment
variable WX_UI_TESTS to 1 (or disabled by setting it to 0 under MSW).
Ensure we don't leave "mytext.dat" and "test.txt" lying around in any
directory the tests are run from by ensuring that these files are
destroyed by the test code using them.
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.
Avoid the optimized mb_str() available in this build returning directly
a "char*" as it doesn't preserve the length of the string if it contains
NULs. Use mb_str(wxMBConv) overload instead which always returns the
buffer of the correct length.
Arguably, this is a problem of wxString API and maybe this optimized
mb_str() overload shouldn't be provided at all. OTOH the main reason for
wxUSE_UTF8_LOCALE_ONLY existence is optimization, so it seems a pity to
deliberately make the code less efficient when using it.
Initialize m_pos correctly when using an existing, and hence possibly
not empty, string (and not the internal one which is always empty
initially). The old code was totally wrong as it divided the string
length by the size of wxChar instead of multiplying by it, but doing
this could have been wrong too with UTF-16 and surrogates, so use the
conversion object to compute the real length of the string
representation in the corresponding encoding.
Add a simple unit test checking that this works as intended.
Closes#17985.
This option now lists the available tags instead of showing the timing
information.
We could use Catch "--durations yes" option, but it results in too much
output, so for now just run the tests with default verbosity.
Don't use Catch asserts in threads other than main, this doesn't work
reliably.
Switch to using simple wxASSERT() which doesn't give as much information
as Catch asserts when the test fails, but at least allows the tests to
pass when the asserts don't fail.
This results in an assertion from MSVC CRT implementation which was
somehow consumed by CppUnit but with the switch to Catch resulted in a
test failure.
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.
Don't remove the files in the test cases classes dtors, this was
inconsistent with how they were created: we either need to create the
file in the ctor and destroy it in the dtor or do both only once
globally.
Implement the second solution using the helper AutoRemoveFile instead of
a simple static bool in GetInFileName() implementations.
Use positive tests really checking for whatever we want to check (that
the stream is not seekable in this particular case) instead of just
checking that the test fails, for whatever reason -- which might not be
at all the reason for which we expect it to fail.
It is better to use wholly non-standard wxWidgets smart pointer class
rather than using standard, but deprecated in C++17, std::auto_ptr<> as
this results in warnings from recent compilers.
These files are currently implicitly included from other headers, but we
shouldn't rely on this and include them explicitly as we use std::map<>
and std::auto_ptr<> in this header.
No real changes.
It was only used as part of WXTEST_WITH_GZIP_CONDITION which was
necessary only to support running the tests on systems using zlib < 1.2
which is not a concern since many years any more, so simplify the code
by using the simple non-conditional CPPUNIT_TEST instead and drop the
helper macros which were required only for this.
This is useful when not using libFuzzer (e.g. because the compiler is
gcc or MSVC and not clang) as it allows to debug the problems found by
libFuzzer with the reproducers generated by it.