Commit graph

99 commits

Author SHA1 Message Date
Samuel Thibault
62f75c235d Fix DynamicLibrary::Load() test for less common platforms
alpha and ia64 use libc.so.6.1, GNU/kFreeBSD uses libc.so.0.1, and
GNU/Hurd uses libc.so.0.3, so check for these versions too in addition
to 6 and 7 used under x86 Linux.

Closes #23801.
2023-08-24 02:49:31 +02:00
Carlo Bramini
1bc8631b52 Fix DynamicLibrary::Load unit test under Cygwin
While running the test_base on CYGWIN, this message will be printed on the console:

-------------------------------------------------------------------------------
DynamicLibrary::Load
-------------------------------------------------------------------------------
/cygdrive/c/Users/carlo/Documents/GitHub/wxWidgets/tests/misc/dynamiclib.cpp:26
...............................................................................

/cygdrive/c/Users/carlo/Documents/GitHub/wxWidgets/tests/misc/dynamiclib.cpp:80: warning:
  Couldn't find libc.so, skipping DynamicLibrary::Load() test.

/cygdrive/c/Users/carlo/Documents/GitHub/wxWidgets/tests/misc/dynamiclib.cpp:84: warning:
  Possible candidates:
  /lib/libc.a
  /usr/lib/libc.a

CYGWIN uses NEWLIB as C library and it is compiled into cygwin1.dll.
This patch adds the right test case for CYGWIN, for letting the execution of the test.

Closes #23781.
2023-08-24 02:24:16 +02:00
Vadim Zeitlin
72c5691d2f Fix buffer overrun in wxHTMLDataObject under non-MSW platforms
Using strcpy() in GetDataHere() added an extra NUL at the end which
didn't fit into the buffer of the size returned by GetDataSize(). This
could have been also fixed by returning an extra byte from the latter
function, but as the string doesn't need to be NUL-terminated,
apparently, just use memcpy() with the correct number of bytes instead.

Also, because the string is not necessarily NUL-terminated, use the
provided length in wxHTMLDataObject::SetData() instead of relying on the
buffer being NUL-terminated and reading uninitialized memory beyond its
size.

Add a unit test confirming that there are no more ASAN errors when using
this class.

Closes #23660.

Co-Authored-By: mcorino <martin@corino.nl>
2023-06-21 20:38:25 +01:00
Vadim Zeitlin
c7d414bbed Make HTML pasting code more robust and efficient
Use StartFragment and EndFragment headers values in order to extract the
HTML fragment from the entire CF_HTML string, instead of searching for
"<!--StartFragment-->" and "<!--EndFragment-->" comments which could be
wrong (e.g. if a StartFragment comment actually appeared inside the HTML
fragment) and less efficient too.

Also add a simple pseudo-test, disabled by default, allowing to view the
clipboard contents if HTML is available on it.
2023-06-21 20:38:25 +01:00
Vadim Zeitlin
363f0988cf Replace wxScopedPtr with std::unique_ptr in the tests
Just use the standard class instead of the wx one, as they can be used
in exactly the same way.
2023-03-06 23:34:44 +01:00
Vadim Zeitlin
d737d98d27 Consistently include trailing NUL in wxMSW wxTextDataObject size
Fix a long-standing bug in wxMSW wxTextDataObject which returned the
size including the trailing NUL from its GetDataSize() and used the same
convention in GetData(), but didn't account for this NUL being included
into the buffer passed to SetData().

This was partially compensated by also passing the wrong (too small)
buffer size when calling SetData() from wxIDataObject, but still
resulted in problems when using SetData() with the length returned from
GetDataSize(), as done in wxDataViewCtrl code.

Fix this by now always considering NUL part of the buffer (as this is
the platform convention, i.e. all CF_TEXT data on the system clipboard
must include the trailing NUL) and taking it into account when
determining the buffer size in wxIDataObject.

This change is not fully backwards-compatible as it breaks any code
calling SetData() directly, as e.g. wxURLDataObject in wxMSW itself did,
so document it as such, but it's still worth making it as there doesn't
seem to be any other way of fixing the problem described in the linked
issue and direct calls to SetData() should be rare as simpler SetText()
should be used instead.

Also add a unit test for wxTextDataObject and extend the existing test
of wxURLDataObject.

Closes #22928.
2022-12-06 02:25:44 +01:00
Vadim Zeitlin
2a39377ca4 Add wxVersionInfo::AtLeast()
Allow easily checking if the version is at least equal to the given one.
2022-12-04 00:44:09 +01:00
Vadim Zeitlin
84229199c7 Make wxFileTypeInfo ctor a variadic template function
Stop using vararg macros in wxFileTypeInfo and make ctor a template
function instead, this is simpler and more clear.

Add a unit test checking that the ctor still behaves as expected.
2022-11-23 02:44:50 +01:00
Vadim Zeitlin
4f4c5fcfdf Use nullptr instead of NULL in the code and documentation
This is a combination of running clang-tidy with modernize-use-nullptr
check for some ports (GTK, X11, OSX) and manual changes to the ports for
which it couldn't be used easily (MSW, DFB) and also manually updating
the docs.

Also replace NULL with null or nullptr in the comments as this is more
consistent with the use of nullptr in the code and makes it simpler to
grep for the remaining occurrences of NULL itself.

And also use null in the assert messages.

Only a few occurrences of "NULL" are still left in non-C files, mostly
corresponding to unclear comments or string output which it might not be
safe to change.
2022-10-18 01:25:25 +02:00
PB
88d526660f Replace wxOVERRIDE and wxNOEXCEPT with override and noexcept
Don't use deprecated macros in wxWidgets itself.
2022-10-15 18:10:45 +02:00
Vadim Zeitlin
73869d37fd Always use variadic macros and remove wxNO_VARIADIC_MACROS
Variadic macros are always available in C++11, which will be required
very soon, so don't bother testing for them and just always use them.
2022-10-11 00:02:29 +02:00
Vadim Zeitlin
512b8033fe Determine location of libc dynamically in wxDynamicLibrary test
Don't hard code the path to it, even different Linux versions use
different paths, e.g. /lib/x86_64-linux-gnu under Debian and /lib64
under Fedora, so just try all the possibilities until we find something.
2022-08-04 01:07:35 +02:00
PB
8d3812adce Fix wxDynamicLibrary unit test compilation in C++20 mode
Don't use operator<<() with a wide char string, as this overload has
been removed in C++20. This can be done simply by not using wide char
string at all in this test, as it's not really needed.

Co-Authored-By: Vadim Zeitlin <vadim@wxwidgets.org>

Closes #22599.
2022-07-05 01:36:42 +02:00
Vadim Zeitlin
ab204afcab Use correct libc.so location under FreeBSD
This allows wxDynamicLibrary to pass there instead of just warning and
skipping the test.
2022-06-30 16:28:29 +02:00
Vadim Zeitlin
20c8844925 Don't try using /usr/lib/libc.so on unknown Unix systems
This doesn't work under FreeBSD, even if the file exists there.

Show the existing libc candidates on such systems to see if any of them
look plausible.
2022-06-30 14:03:44 +02:00
Vadim Zeitlin
587c1fafe0 Remove unused wx/log.h include from wxDynamicLibrary unit test
No real changes.
2022-06-30 14:03:28 +02:00
Vadim Zeitlin
3fcf4a5f74 Fix Windows wxDynamicLibrary tests build after recent change
Fix a mistake in e32f49bca0 (Do run DynamicLibrary::Load unit test under
Linux, 2022-06-29).
2022-06-29 22:42:10 +02:00
Vadim Zeitlin
e32f49bca0 Do run DynamicLibrary::Load unit test under Linux
Use existing path for libc.so on Linux/x86_64 platforms to prevent the
test from just exiting without doing anything.

Also don't give a compilation error for unknown platforms, just a
run-time warning is sufficient.
2022-06-29 22:25:08 +02:00
Vadim Zeitlin
02434dcc1f Workaround a crash with MSYS2 gcc 9.1 again
The changes of 2144ca38d2 (Get rid of CppUnit boilerplate in
DynamicLibraryTestCase, 2022-04-17) accidentally undid the workaround
from 054cb35b39 (Workaround for a crash with gcc 9.1 from MSYS2 MinGW
32bit, 2019-08-03), so work around the same problem again by avoiding
using CHECK() with function pointers.
2022-04-18 14:36:52 +02:00
Vadim Zeitlin
2144ca38d2 Get rid of CppUnit boilerplate in DynamicLibraryTestCase
Use CATCH macros directly, this is simpler and more clear.

Also use narrow strings instead of wide ones and get rid of wxT() too.

No real changes.

This commit is best viewed ignoring whitespace-only changes.
2022-04-17 18:44:51 +02:00
Vadim Zeitlin
f3b4ee3b5f Skip dynamic library file existence check under Darwin
Under Monterrey (macOS 10.12) we can actually load the file using
wxDynamicLibrary even though it does _not_ exist on the disk, so don't
skip the test just because of this.
2022-04-17 18:38:08 +02:00
Vadim Zeitlin
c6b3b4a39c Make the warning in DynamicLibraryTestCase actually visible
Using wxLogWarning() doesn't work as logs are suppressed by default, but
using CATCH WARN() macro does work.
2022-04-17 18:35:34 +02:00
Vadim Zeitlin
6a48431ca1 Add missing wxLogWarning() argument to wxDynamicLibrary test
The argument corresponding to the "%s" format specifier was missing,
which resulted in a crash if the dynamic library tested didn't actually
exist.
2022-04-17 18:30:42 +02:00
Vadim Zeitlin
b91173f76e Fix comparing wxDataFormat with wxDF_INVALID in wxGTK
Define wxDataFormat::operator==(wxDataFormatId) instead of relying on
the implicit conversion from wxDataFormatId to wxDataFormat, as this
can't be done when the format ID is wxDF_INVALID because creating
wxDataFormat results in an assert failure in this case, while comparing
with wxDF_INVALID is clearly a perfectly valid operation.

Add a unit test checking for this.

Closes #22213.
2022-03-23 13:43:44 +01:00
Vadim Zeitlin
9e5c8eef24 Make wxDumpWindow() public and available in wxMSW too
This function was defined in wxGTK and wxOSX, but not in wxMSW or the
other ports, but it can be useful there too, so make it public and
define it in common code.
2021-10-20 23:35:37 +01:00
Vadim Zeitlin
85503d1dcd Get rid of CppUnit boilerplate in MiscGUIFuncsTestCase
Simplify code by not defining an unnecessary test case class and using
CATCH macros directly.

No real changes.
2021-10-20 23:35:37 +01:00
Vadim Zeitlin
87b394a555 Use wxScopedPtr in MiscGUIFuncsTestCase for automatic cleanup
Replace manual calls to Destroy() to ensure that the objects created in
this test will be destroyed even if a check fails.
2021-10-20 23:35:37 +01:00
Vadim Zeitlin
cc3c836711 Fix tests build with wxDEBUG_LEVEL==0
Define various macros used in the test code (or in the headers included
from it) as nothing when wxDEBUG_LEVEL==0.

Also don't define a helper function used when asserts are enabled in
this build to avoid clang warnings about unused function.
2021-08-21 15:05:13 +02:00
Vadim Zeitlin
7c6f290995 Document wxMulDivInt32() and add a test for it
This function exists since always and is probably already used outside
wx, so make it officially public and add at least a trivial unit test
for it.
2021-07-13 23:05:16 +01:00
Vadim Zeitlin
0585c96a3b Restore wxObject::ms_classInfo public access
This undoes accidental change of ms_classInfo from public to protected
in 95c98a0b5f (Work around -Wuggest-override for event table macros from
gcc 11, 2021-04-25).

Also add a unit test checking that using wxCLASSINFO(wxObject) compiles
and works as expected.
2021-05-04 23:14:41 +02:00
Vadim Zeitlin
5ddf57c150 Add wxModule::AreInitialized()
This internal function will be useful to check if the modules are
already initialized, i.e. if the library is in the "steady state"
between the end of the initialization and the beginning of the cleanup
phases.
2021-03-07 20:39:09 +01:00
Vadim Zeitlin
fbd23270e3 Remove CppUnit boilerplate from wxModule unit test
Also use wxString instead of fixed size char array and wxStrcat().
2021-03-07 20:39:09 +01:00
Vadim Zeitlin
86f9778ea9 Add a unit test exercising the bug fix in the parent commit
This test used to fail, but passes now.
2021-01-23 16:40:30 +01:00
Vadim Zeitlin
6b3ff511ee Get rid of all CppUnit boilerplate in wxSelectionStore test
This simplifies the code and allows running the test cases individually
from the command line.
2021-01-23 16:40:30 +01:00
Vadim Zeitlin
a1cca242a4 Use CHECK() instead of CPPUNIT_ASSERT in wxSelectionStore test
No real changes, just simplify the code. Notably we don't need explicit
"u" suffix on the literal constants any longer as CATCH is smart enough
to compare signed and unsigned integers correctly without it.
2021-01-23 16:40:30 +01:00
Vadim Zeitlin
8e5836908c Use wxSelectionStore object instead of a pointer in the test
Just simplify the code, there is no need to allocate and free a pointer
when we can just use an object.

No real changes.
2021-01-22 22:32:20 +01:00
Vadim Zeitlin
a1d43c9363 Make wxRound() compile for all integer types again
Replace the overloads added in c2e5f3520a (Add a wxRound() overload for
int, 2020-11-05) and 1cf7c47934 (Add more wxRound() compatibility
overloads and improve docs, 2020-11-05) with a template function that
should work for all integer types.

This fixes compilation of existing code using wxRound() with size_t
values: while this doesn't make any sense, it doesn't make much less
sense than using it with int, so let people avoid having to change their
code when upgrading to wx 3.2.

Also add at least some minimal tests for this function.

Closes https://github.com/wxWidgets/wxWidgets/pull/2119
2020-11-19 15:45:22 +01:00
PB
f57f214122 Remove BCC-specific hdrstop pragma from everywhere 2020-10-12 21:58:37 +02:00
Stefan Csomor
da48b9e45d
adding an iOS build to travis (#1847)
* fixing compilation of tests that cannot build

bracket code with the corresponding wxUSE… macros

* adding directive for iOS

* adding a switch for skipping the run - not the build of tests

right now I don’t know yet, how to run the test binary in the iOS simulator, but building it is still a good test in itself

* adding skipping of tests

* increasing minimum deployment to get proper c++17 support

* using --disable-sys-libs, restoring other targets

even when the zlib in -isysroot is used, due to deployment on lower iOS versions inflateValidate may not be available and crash. The guards are evaluated using macros from the zlib from the SDK, not from the lowest version supported.
2020-05-08 08:01:56 +02:00
Maarten Bent
054cb35b39 Workaround for a crash with gcc 9.1 from MSYS2 MinGW 32bit 2019-08-03 21:08:10 +02:00
Maarten Bent
3bab07edcf Fix some build warnings
private field 'm_dwCookie' is not used
'return' will never be executed
result of comparison of unsigned enum expression < 0 is always false
'FlushDC' overrides a member function but is not marked 'override'
potentially uninitialized local variable 'bound' used
2018-11-25 21:29:38 +01:00
Vadim Zeitlin
ef92b92691 Add unit test for wxCTZ
Check that the new function works reasonably correctly.
2018-11-05 19:27:53 +01:00
Maarten Bent
7c1ab06ea5 Add more wxOVERRIDE 2018-09-22 14:44:07 +02:00
Maarten Bent
a914478f60 Add guards around test cases 2018-09-19 22:01:17 +02:00
Maarten Bent
57180d68c8 Add wxOVERRIDE to test files
And cleanup some tailing spaces and tabs.
2018-07-29 12:08:53 +02:00
Vadim Zeitlin
62f9438ad3 Rewrite wxPathList unit test without CppUnit-compatible API
Simplify the test by using a single function instead of all the
machinery inherited from CppUnit.

Also provide more information in case of test failure.
2017-11-25 16:08:01 +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
Paul Cornett
7816ca6538 Fix building tests with wxUSE_XRC==0 2017-10-01 09:46:03 -07:00
Vadim Zeitlin
893102b926 Fix mismatched new[]/delete in a test case.
Use wxDELETEA() as the comment said we did -- except that we didn't.
2015-06-19 16:32:14 +02: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