Commit Graph

109 Commits

Author SHA1 Message Date
Artur Wieczorek
dc43d15cf7 Add tests of storing HiDPI images in generic wxImageList (wxOSX, wxGTK3) 2021-04-05 12:18:05 +02:00
Artur Wieczorek
2ed7355d5c Add wxImageList tests with negative scenarios (invalid sizes, indices) 2021-04-04 20:53:02 +02:00
Artur Wieczorek
c7667c16f8 Add tests of creating wxGraphicsBitmap from wxImage 2021-02-09 00:14:12 +01:00
Artur Wieczorek
414f211b8a Add tests of wxGraphicsBitmap
Add tests of creating wxGraphicsBitmap from specific to wxMSW and wxOSX
32-bit RGB wxBitmaps (non-alpha).
2021-02-06 21:43:47 +01:00
Artur Wieczorek
e73cb85246 Add tests of wxGraphicsBitmap 2021-02-05 23:52:29 +01:00
Artur Wieczorek
efb96a352d Add more tests of converting wxBitmap to wxImage 2021-01-20 19:29:32 +01:00
Paul Cornett
4a3ff8c180 Fix bitmap tests with GTK2
wxGTK2 does not support drawing bitmaps with both alpha
and a mask, so it doesn't bother to implement having both.
So skip the test for that case.
2021-01-19 01:35:28 -08:00
Artur Wieczorek
72ac21cf18 Fix wxBitmap tests under wxOSX
Under wxOSX wxBitmaps have always 32-bit depth.
2021-01-18 23:01:20 +01:00
Artur Wieczorek
6b572bf694 Add tests of converting wxImage to wxBitmap 2021-01-18 22:14:43 +01:00
Artur Wieczorek
321f38831e Fix sizes of images stored in generic wxImageList
Sizing the images stored in the list should stick to the convention
adopted in the native wxImageList implemented in wxMSW.
Images stored in the list should have the sizes as it is declared for
the list even if provided bitmaps have different sizes.
In case of discrepancies their dimensions should be adjusted accordingly
(cropped or extended).
2021-01-16 23:01:49 +01:00
Artur Wieczorek
bde82aa9fb Fix adding image using bitmap and mask colour to nonmasked wxImageList (wxMSW)
If image using bitmap and mask colour is added to nonmasked wxImageList we
need to convert effective mask to alpha channel values prior to adding the
image to the native list to preserve transparency.
2021-01-16 23:01:48 +01:00
Artur Wieczorek
331840edb3 Fix replacing images in generic wxImageList
Bitmaps stored in the list as a result of replacing existing ones should
conform to the same constraints as bitmaps directly added to the list.
These constraints are applied in the shared GetImageListBitmap() function
called both on adding and replacing the images.
2021-01-13 18:38:57 +01:00
Artur Wieczorek
030664c148 Add tests of wxImageList
This is a basic test set.
2021-01-12 18:22:03 +01:00
Bill Su
47078992c6 Fix handling of mask in wxBitmap::ConvertToImage()
Handling mask when converting wxBitmap to wxImage was accidentally
broken by 7e9afad53a (Add real support for monochrome bitmaps to wxMSW,
2020-10-19). Fix this now and reuse the new wxMonoPixelData to make the
code simpler and more readable.

This commit is best viewed ignoring whitespace-only changes, as it
unindents a large block of code.

Closes https://github.com/wxWidgets/wxWidgets/pull/2125

Closes #18974, #18975.
2020-11-21 18:14:02 +01:00
Bill Su
7e9afad53a Add real support for monochrome bitmaps to wxMSW
In order to be able to use monochrome bitmaps as wxMask, improve support
for them in various ways:

1. Implement loading and saving of monochrome BMP files.
2. Add wxMonoPixelData for direct access to monochrome bitmap pixels.
3. Implement conversion from wxImage to monochrome wxBitmap.

Closes https://github.com/wxWidgets/wxWidgets/pull/2032
2020-10-20 15:52:55 +02:00
PB
f57f214122 Remove BCC-specific hdrstop pragma from everywhere 2020-10-12 21:58:37 +02:00
Artur Wieczorek
d00ca6a172 Add more unit tests of coordinates conversion functions 2020-09-27 13:38:41 +02:00
Artur Wieczorek
6fac6c0b35 Add unit tests of coordinates conversion functions 2020-09-26 01:43:20 +02:00
Vadim Zeitlin
d57c688d89 Return non-zero height from GetMultiLineTextExtent("") in wxMSW
This restores the previous behaviour inadvertently changed by bfeae1922d
(Minor optimizations in GetMultiLineTextExtent(), 2020-06-10) and makes
it official by documenting it and adding tests checking for it.

It wasn't completely obviously if this was intentional or accidental
before, but at least wxStaticText itself relied on the old behaviour,
and chances are that so did some code outside the library, so make this
part of the API now.

See #18825.
2020-07-15 02:10:49 +02:00
Vadim Zeitlin
46d6866c9f Make wxGCDC::GetTextExtent("") return (0, 0)
This seems more logical and is compatible with wxDC in wxMSW and wxGTK2,
as well as other kinds of DC, e.g. wxPostScriptDC.

It also looks like the current behaviour was unintentional as it
happened only because wxGCDCImpl::DoGetTextExtent() always passed all
non-null parameters to wxGraphicsContext::GetTextExtent(), even if it
didn't need the values for all of them, and thus bypassed the special
case for the empty string which was already present in the latter
function.

Fix this, making DoGetTextExtent() more efficient as a side effect (we
now avoid unnecessary calls to pango_layout_iter_get_baseline() in the
most common case), and also add another test for empty string to
wxGraphicsContext itself, for non-GTK case.

Also document this behaviour and add a test checking for it.
2020-07-15 02:10:34 +02:00
Vadim Zeitlin
db556fc388 Remove CppUnit boilerplate from wxDC::GetTextExtent() unit tests
Drop the test case class and use CATCH macros.
2020-07-14 23:36:23 +02:00
Vadim Zeitlin
9890cf6bac Return empty string from wxColour::GetAsString() if it's invalid
This is consistent with wxToString(wxColour) and seems more useful than
either returning black string representation (as wxMSW used to do) or
asserting (as wxGTK did).

Document this behaviour and add a test checking for it.

Closes #18623.
2020-07-11 14:31:54 +02:00
Vadim Zeitlin
5d14346325 Replace CppUnit assertion macros with Catch ones
Also define wxColour-specific matchers to allow comparing RGB(A)
channels to the expected values, replacing the old ASSERT_EQUAL_RGB(A)
macros.

No real changes.
2020-07-11 14:24:06 +02:00
Vadim Zeitlin
de6bc5f062 Remove useless CppUnit test case class from wxColour unit test
No real changes, just get rid of the unnecessary legacy boilerplate.
2020-07-10 19:31:33 +02:00
Maarten Bent
977e9df630 Add test case for wxGraphicsContext DrawBitmap
Test if the bitmap is scaled correctly.
2020-03-11 20:00:09 +01:00
Maarten Bent
38008cd8d5 Add macro to compare colours in bitmap test suite 2020-03-10 21:04:15 +01:00
Vadim Zeitlin
aa1891e524 Remove unnecessary and unused EllipsizationTestCase class
No real changes, just don't use a text fixture which does nothing, this
is useless and confusing.
2019-11-13 18:25:42 +01:00
iwbnwif
7155e82255 Show the used font in case of failure in Ellipsization unit test 2019-11-13 18:04:53 +01:00
Vadim Zeitlin
cf07dea50d Add unit tests for wxDC::Clear()
Verify that it behaves as documented, i.e. uses white if the background
brush is not explicitly set.
2019-10-02 02:45:28 +02:00
Artur Wieczorek
96cb3b6714 Add tests of retrieving sub-bitmaps 2019-09-29 16:16:55 +02:00
Artur Wieczorek
7f65e654ee Add tests of drawing wxBitmap 2019-09-19 00:38:30 +02:00
Artur Wieczorek
5aac5ae562 Migrate wxBitmap tests to Catch 2019-09-19 00:37:48 +02:00
Maarten Bent
533d82655f Remove CppUnit boilerplate and macros from ellipsization tests 2019-08-14 21:03:48 +02:00
Maarten Bent
b245e4a571 Use dynamic widths in ellipsization tests so they will work for any font size 2019-08-14 21:02:33 +02:00
Vadim Zeitlin
30726437c0 Fix the result width check in the ellipsization unit test
When processing mnemonics, the resulting string should still contain
them and they need to be stripped before measuring its width, but the
code didn't do it.

This didn't prevent the tests from passing, but only due to another bug
in ellipsization code itself, which lost the mnemonics completely. As
this bug is about to be fixed, the test needs to take mnemonics into
account properly now.
2019-06-20 01:46:28 +02:00
Vadim Zeitlin
d662a2223e Add wxColour::GetLuminance()
This method can be used to return the perceived brightness of the
colour.

Closes https://github.com/wxWidgets/wxWidgets/pull/1300
2019-04-21 02:09:42 +02:00
Graham Dawes
db15e99884 Fix wxBitmap::GetRawData() in wxQt
This method used to return a dangling pointer to a temporary buffer,
which resulted in a crash when using it, e.g. in the unit test.

Fix this by keeping a QImage as a member in wxBitmapRefData, so that the
pointer to its data remain valid until UngetRawData() is called.

Also check that GetRawData() returns a non-null pointer in the test.

Closes https://github.com/wxWidgets/wxWidgets/pull/1067
2018-12-13 15:24:54 +01: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
Maarten Bent
7bf952165f Test success in BitmapTestCase::Mask() 2018-09-19 22:01:17 +02:00
Maarten Bent
a914478f60 Add guards around test cases 2018-09-19 22:01:17 +02:00
Maarten Bent
da9b4bc0a0 Remove unused variable in graphpath test 2018-07-29 16:29:36 +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
Artur Wieczorek
e732da462f Add tests for the bounds of wxGraphicsPath
Check if bounding box of wxGraphicsPath is properly determined.
2018-07-28 11:36:44 +02:00
Artur Wieczorek
fc53007ab4 Add unit test for current point of wxGraphicsPath
Verify that last point is properly positioned after the operations
on wxGraphicsPath.

See #18111.
2018-07-02 20:08:30 +02:00
Vadim Zeitlin
070336470f Make wxSVGFileDC::GetClippingBox() actually work
wxSVGFileDCImpl class uses the default, i.e. inherited from wxDCImpl,
implementation of this method, but for it to work, the clipping box
coordinates stored in wxDCImpl need to be updated when the clipping
region changes or is destroyed and this wasn't done before.

Fix this now and add a unit test verifying that this indeed works.
2018-06-18 17:11:16 +02:00
Vadim Zeitlin
e13904308f Add convenient tags for clipping box unit tests
No real changes, just replace the old CppUnit test registration macros
with wxREGISTER_UNIT_TEST_WITH_TAGS() which allows to specify the tags
explicitly and use "clip" as the tag for all the tests here to allow
running all of them (and just them) by specifying "[clip]" on the test
program command line.
2018-06-18 10:54:26 +02: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
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
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
aa4c270d73 Fix warning about local variable shadowing in clipping unit test
Use "col" for the "wxColour" variable to avoid clash with "c" one used
for the corner index.

Also just construct the colour directly from the RGB values instead of
default-initializing it and then using Set(), which also allows to make
it "const".
2017-10-22 23:39:47 +02:00