Commit Graph

1777 Commits

Author SHA1 Message Date
Vadim Zeitlin
25a7c70631 Implement wxVector::reverse_iterator::operator-()
Make wxVector reverse iterators (and const versions of them) more
compatible with the std::vector ones.
2017-11-19 22:08:54 +01:00
Vadim Zeitlin
5669e8dbe9 Add wxVector::operator==() and !=()
Make this class more consistent with std::vector<>.
2017-11-19 22:08:54 +01:00
Vadim Zeitlin
5463402e39 Try to show when do X errors happen while running tests
Install an X11 error handler to try to gather more information about the
GUI tests failures on buildbot.
2017-11-14 02:57:57 +01:00
Vadim Zeitlin
f5703673ad Skip focus event test when running under buildbot
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.
2017-11-14 02:41:58 +01:00
Vadim Zeitlin
f3b5cc32fa Fix recently introduced crash in ClippingBoxTestCase
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.
2017-11-14 00:41:31 +01:00
Vadim Zeitlin
f3995658ff Increase timeout for WindowTestCase::FocusEvent()
The default 100ms doesn't seem to be enough when this test runs under
buildbot.
2017-11-14 00:06:21 +01:00
Vadim Zeitlin
11a5728b32 Replace remaining std::auto_ptr<> with wxScopedPtr in the tests
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.
2017-11-14 00:06:18 +01:00
Vadim Zeitlin
4502e7563b Fix wxTextInputStream for input starting with BOM-like bytes
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.
2017-11-09 23:49:59 +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
VZ
d3db5b30f6
Fix or disable currently failing wxGTK GUI tests
Try to ensure that the GUI test suite passes so that buildbot has a
chance to warn us if/when anything breaks.
2017-11-07 20:56:09 +01:00
Vadim Zeitlin
7ba933c694 Disable wxPaintEvent propagation tests for wxGTK3
They're currently broken and just always fail, it's useless to continue
running them until the issue described in the comment in this commit is
fixed.
2017-11-07 16:37:25 +01:00
Vadim Zeitlin
643071fc77 Add more new lines around GTK errors in the test suite
Try to make things a bit more readable.
2017-11-07 16:21:38 +01:00
Vadim Zeitlin
c13e28ebfb Disable wxTopLevelWindow::IsActive() unit test for wxGTK
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.
2017-11-07 16:16:08 +01:00
Vadim Zeitlin
548d7a0518 Disable keyboard event unit tests for wxGTK
They suffer from the same problem as all the other tests using
wxUIActionSimulator: it is flaky with GTK+ 2 and doesn't work at all
with GTK+ 3.
2017-11-07 16:10:19 +01:00
Vadim Zeitlin
f0a32f0e1f Wait for the focus event to occur in the unit test
The test failed unless we dispatched events with wxGTK (both 2 and 3).
2017-11-07 15:44:18 +01:00
Vadim Zeitlin
66324470f1 Fix wxTextCtrl::GetStyle() with GTK+ 3
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.
2017-11-07 15:40:29 +01:00
Vadim Zeitlin
5fb740fed8 Add a layout hack to PositionToCoords() unit test for wxGTK
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.
2017-11-07 15:03:59 +01:00
Vadim Zeitlin
407d38d9ed Always use wxTE_MULTILINE explicitly in PositionToCoords() test
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.
2017-11-07 14:23:07 +01:00
Vadim Zeitlin
faad429b0f Fix wxTextCtrl::XYToPosition() for last position in wxGTK
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.
2017-11-07 14:12:48 +01:00
Vadim Zeitlin
af9f78852a Fix archivers test suite broken by transition to Catch
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.
2017-11-07 13:50:47 +01:00
Vadim Zeitlin
13163fb315 Send event when clearing wxTextCtrl in wxGTK again
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.
2017-11-07 03:12:10 +01:00
Vadim Zeitlin
e8ceaabb87 Avoid gcc -Wunused-function warnings in wxEvtHandler unit test
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.
2017-11-07 02:54:05 +01:00
Vadim Zeitlin
b4e55a7192 Merge branch 'test-fixes'
Miscellaneous test fixes and disable the UI tests by default under
non-MSW platforms.
2017-11-05 23:44:01 +01:00
Paul Cornett
74282d9aed Fix DrawPoint() test
The result now matches non-GC wxDC, after 5ba7a1d1
2017-11-05 09:35:43 -08:00
Vadim Zeitlin
99378ed0d7 Disable tests using wxUIActionSimulator under non-MSW platforms
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).
2017-11-05 17:51:55 +01:00
Vadim Zeitlin
0858cd52a7 Don't unnecessarily use heap-allocated objects in a test
Just use local stack variables instead.
2017-11-05 17:30:46 +01:00
Vadim Zeitlin
10b80a16f0 Factor out TempFile class and reuse it in other tests
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.
2017-11-05 17:28:24 +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
aaea62a322 Avoid launching interactive programs in unattended tests
This is typically going to fail anyhow, so don't even try to avoid
useless error messages.
2017-11-05 17:16:39 +01:00
Vadim Zeitlin
7e0b6d4d81 Merge branch 'webview-js-retval'
Integrate GSoC 2017 work by Jose Lorenzo on allowing returning values
from JavaScript code via wxWebView::RunScript().
2017-11-04 16:07:51 +01:00
Vadim Zeitlin
266152b459 Merge branch 'mbconv-len-fix'
Return buffers of correct length from wxMBConv::cWC2MB() and cMB2WC().
2017-11-04 14:20:15 +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
9c1964ee1d Fix a unit test in UTF-8 build using UTF-8 strings only
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.
2017-11-03 23:11:32 +01:00
Vadim Zeitlin
e3589af56a Fix wxStringOutputStream position when using external string
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.
2017-11-03 15:25:36 +01:00
Paul Cornett
d76e627341 More use of wxFALLTHROUGH 2017-11-02 08:56:29 -07:00
Paul Cornett
c2513d8a4e Add missing break statement 2017-11-02 08:55:00 -07:00
Vadim Zeitlin
62979a5f6f Remove unused member variables from unit testing class
Thanks clang for the reminder about them with its -Wunused-private-field
warnings.
2017-11-02 01:53:33 +01:00
Vadim Zeitlin
fdad46b10d Suppress some harmless clang warnings in a Catch header
Just avoid harmless but annoying warnings in catch_impl.hpp when using
clang.
2017-11-02 01:53:31 +01:00
Vadim Zeitlin
c363ce8500 Don't use "-t" option when running tests any longer
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.
2017-11-02 01:53:29 +01:00
Vadim Zeitlin
729dd5e693 Work around Catch multi-thread unsafety
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.
2017-11-02 01:53:25 +01:00
Vadim Zeitlin
ebf30adeb6 Avoid calling strftime() with an invalid format string
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.
2017-11-02 01:53:23 +01:00
Vadim Zeitlin
f3f345eec9 Fix harmless signed/unsigned comparison warnings in a test
These warnings appeared after switching to Catch, just use the same type
for all variables to avoid them.
2017-11-02 01:53:21 +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
Vadim Zeitlin
5520d56222 Remove test input file in file stream unit tests only once
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.
2017-11-01 14:45:06 +01:00
Vadim Zeitlin
c54b611093 Replace few uses of CPPUNIT_TEST_FAIL with just CPPUNIT_TEST
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.
2017-10-31 22:04:12 +01:00
Vadim Zeitlin
b8c9cd3528 Use wxScopedPtr<> instead of std::auto_ptr<> in the tests
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.
2017-10-31 21:14:05 +01:00
Vadim Zeitlin
9d0df5707a Include the required standard headers used in archives unit test
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.
2017-10-30 15:29:30 +01:00
Vadim Zeitlin
7b10210763 Move WX_ASSERT_STRARRAY_EQUAL() to the only test using it
It doesn't seem useful to have this macro in the header included by all
tests when it's only used in a single one of them.
2017-10-30 14:44:20 +01:00
Vadim Zeitlin
9f609a8148 Remove WXTEST_WITH_CONDITION macro to simplify the code
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.
2017-10-30 14:16:11 +01:00
Vadim Zeitlin
b5aaede7b1 Add a helper for running fuzz function with a single input
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.
2017-10-28 15:12:14 +02:00