2011-04-26 18:57:16 -04:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: tests/testimage.h
|
|
|
|
// Purpose: Unit test helpers for dealing with wxImage.
|
|
|
|
// Author: Vadim Zeitlin
|
|
|
|
// Copyright: (c) 2011 Vadim Zeitlin <vadim@wxwidgets.org>
|
|
|
|
// Licence: wxWindows licence
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#ifndef _WX_TESTS_TESTIMAGE_H_
|
|
|
|
#define _WX_TESTS_TESTIMAGE_H_
|
|
|
|
|
|
|
|
#include "wx/image.h"
|
|
|
|
|
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-01 14:15:24 -04:00
|
|
|
namespace Catch
|
|
|
|
{
|
|
|
|
template <>
|
|
|
|
struct StringMaker<wxImage>
|
|
|
|
{
|
|
|
|
static std::string convert(const wxImage& image)
|
|
|
|
{
|
|
|
|
return wxString::Format("image of size %d*%d with%s alpha",
|
|
|
|
image.GetWidth(),
|
|
|
|
image.GetHeight(),
|
|
|
|
image.HasAlpha() ? "" : "out")
|
|
|
|
.ToStdString();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2011-04-26 18:57:16 -04:00
|
|
|
|
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-01 14:15:24 -04:00
|
|
|
class ImageRGBMatcher : public Catch::MatcherBase<wxImage>
|
2011-04-26 18:57:16 -04:00
|
|
|
{
|
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-01 14:15:24 -04:00
|
|
|
public:
|
2021-02-05 17:04:55 -05:00
|
|
|
ImageRGBMatcher(const wxImage& image, int tolerance, bool checkAlpha = false)
|
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-01 14:15:24 -04:00
|
|
|
: m_image(image)
|
2020-09-23 05:56:58 -04:00
|
|
|
, m_tolerance(tolerance)
|
2021-02-05 17:04:55 -05:00
|
|
|
, m_checkAlpha(checkAlpha)
|
2011-04-26 18:57:16 -04:00
|
|
|
{
|
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-01 14:15:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool match(const wxImage& other) const wxOVERRIDE
|
|
|
|
{
|
|
|
|
if ( other.GetWidth() != m_image.GetWidth() )
|
2011-04-26 18:57:16 -04:00
|
|
|
return false;
|
|
|
|
|
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-01 14:15:24 -04:00
|
|
|
if ( other.GetHeight() != m_image.GetHeight() )
|
2011-04-26 18:57:16 -04:00
|
|
|
return false;
|
|
|
|
|
2019-07-15 07:44:17 -04:00
|
|
|
if ( memcmp(other.GetData(), m_image.GetData(),
|
|
|
|
other.GetWidth()*other.GetHeight()*3) == 0 )
|
2021-02-05 17:04:55 -05:00
|
|
|
{
|
|
|
|
if ( m_checkAlpha )
|
|
|
|
{
|
|
|
|
if ( !other.HasAlpha() && !m_image.HasAlpha() )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if ( other.HasAlpha() && m_image.HasAlpha() &&
|
|
|
|
memcmp(other.GetAlpha(), m_image.GetAlpha(), other.GetWidth() * other.GetHeight()) == 0 )
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2019-07-15 07:44:17 -04:00
|
|
|
|
2022-01-02 11:56:44 -05:00
|
|
|
const wxString dispAlphaValNull("--");
|
2019-07-15 07:44:17 -04:00
|
|
|
const unsigned char* d1 = m_image.GetData();
|
|
|
|
const unsigned char* d2 = other.GetData();
|
2021-02-05 17:04:55 -05:00
|
|
|
const unsigned char* a1 = m_image.GetAlpha();
|
|
|
|
const unsigned char* a2 = other.GetAlpha();
|
|
|
|
bool dispAlphaVal = a1 || a2;
|
2021-02-05 17:03:59 -05:00
|
|
|
for ( int y = 0; y < m_image.GetHeight(); ++y )
|
2019-07-15 07:44:17 -04:00
|
|
|
{
|
2021-02-05 17:03:59 -05:00
|
|
|
for ( int x = 0; x < m_image.GetWidth(); ++x )
|
2019-07-15 07:44:17 -04:00
|
|
|
{
|
2022-01-02 11:56:44 -05:00
|
|
|
wxString a1txt = dispAlphaVal ? (a1 != NULL ? wxString::Format("%02x", *a1) : dispAlphaValNull) : wxString();
|
|
|
|
wxString a2txt = dispAlphaVal ? (a2 != NULL ? wxString::Format("%02x", *a2) : dispAlphaValNull) : wxString();
|
2021-02-05 17:04:55 -05:00
|
|
|
|
2021-02-05 17:03:59 -05:00
|
|
|
for ( int i = 0; i < 3; i++ )
|
2019-07-15 07:44:17 -04:00
|
|
|
{
|
2021-02-05 17:03:59 -05:00
|
|
|
const unsigned char diff = d1[i] > d2[i] ? d1[i] - d2[i] : d2[i] - d1[i];
|
|
|
|
if ( diff > m_tolerance )
|
|
|
|
{
|
|
|
|
m_diffDesc.Printf
|
|
|
|
(
|
|
|
|
"first mismatch is at (%d, %d) which "
|
2021-02-05 17:04:55 -05:00
|
|
|
"has value 0x%02x%02x%02x%s instead of the "
|
|
|
|
"expected 0x%02x%02x%02x%s",
|
|
|
|
x, y, d2[0], d2[1], d2[2], a2txt, d1[0], d1[1], d1[2], a1txt
|
|
|
|
);
|
|
|
|
|
|
|
|
// Don't show all mismatches, there may be too many of them.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( m_checkAlpha )
|
|
|
|
{
|
|
|
|
if ( a1 && a2 )
|
|
|
|
{
|
|
|
|
const unsigned char diff = *a1 > *a2 ? *a1 - *a2 : *a2 - *a1;
|
|
|
|
if ( diff > m_tolerance )
|
|
|
|
{
|
|
|
|
m_diffDesc.Printf
|
|
|
|
(
|
|
|
|
"first mismatch is at (%d, %d) which "
|
|
|
|
"has value 0x%02x%02x%02x%02x instead of the "
|
|
|
|
"expected 0x%02x%02x%02x%02x",
|
|
|
|
x, y, d2[0], d2[1], d2[2], *a2, d1[0], d1[1], d1[2], *a1
|
|
|
|
);
|
|
|
|
|
|
|
|
// Don't show all mismatches, there may be too many of them.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ( a1txt != a2txt )
|
|
|
|
{
|
|
|
|
m_diffDesc.Printf
|
|
|
|
(
|
|
|
|
"first mismatch is at (%d, %d) which "
|
|
|
|
"has value 0x%02x%02x%02x%s instead of the "
|
|
|
|
"expected 0x%02x%02x%02x%s",
|
|
|
|
x, y, d2[0], d2[1], d2[2], a2txt, d1[0], d1[1], d1[2], a1txt
|
2021-02-05 17:03:59 -05:00
|
|
|
);
|
2020-08-15 10:16:45 -04:00
|
|
|
|
2021-02-05 17:03:59 -05:00
|
|
|
// Don't show all mismatches, there may be too many of them.
|
|
|
|
return false;
|
|
|
|
}
|
2019-07-15 07:44:17 -04:00
|
|
|
}
|
|
|
|
|
2021-02-05 17:03:59 -05:00
|
|
|
d1 += 3;
|
|
|
|
d2 += 3;
|
2021-02-05 17:04:55 -05:00
|
|
|
if ( a1 ) a1++;
|
|
|
|
if ( a2 ) a2++;
|
2019-07-15 07:44:17 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-23 05:56:58 -04:00
|
|
|
// We can only get here when the images are different AND we've not exited the
|
|
|
|
// method from the loop. That implies the tolerance must have caused this.
|
|
|
|
wxASSERT_MSG(m_tolerance > 0, "Unreachable without tolerance");
|
2020-08-15 10:16:45 -04:00
|
|
|
|
2020-09-23 05:56:58 -04:00
|
|
|
return true;
|
2011-04-26 18:57:16 -04:00
|
|
|
}
|
|
|
|
|
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-01 14:15:24 -04:00
|
|
|
std::string describe() const wxOVERRIDE
|
2011-04-26 18:57:16 -04:00
|
|
|
{
|
2019-07-15 07:44:17 -04:00
|
|
|
std::string desc = "doesn't have the same RGB data as " +
|
|
|
|
Catch::toString(m_image);
|
|
|
|
|
|
|
|
if ( !m_diffDesc.empty() )
|
|
|
|
desc += + ": " + m_diffDesc.ToStdString(wxConvUTF8);
|
|
|
|
|
|
|
|
return desc;
|
2011-04-26 18:57:16 -04:00
|
|
|
}
|
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-01 14:15:24 -04:00
|
|
|
|
|
|
|
private:
|
|
|
|
const wxImage m_image;
|
2020-09-23 05:56:58 -04:00
|
|
|
const int m_tolerance;
|
2021-02-05 17:04:55 -05:00
|
|
|
const bool m_checkAlpha;
|
2019-07-15 07:44:17 -04:00
|
|
|
mutable wxString m_diffDesc;
|
2011-04-26 18:57:16 -04:00
|
|
|
};
|
|
|
|
|
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-01 14:15:24 -04:00
|
|
|
inline ImageRGBMatcher RGBSameAs(const wxImage& image)
|
|
|
|
{
|
2021-02-05 17:04:55 -05:00
|
|
|
return ImageRGBMatcher(image, 0, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline ImageRGBMatcher RGBASameAs(const wxImage& image)
|
|
|
|
{
|
|
|
|
return ImageRGBMatcher(image, 0, true);
|
2020-09-23 05:56:58 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Allows small differences (within given tolerance) for r, g, and b values.
|
|
|
|
inline ImageRGBMatcher RGBSimilarTo(const wxImage& image, int tolerance)
|
|
|
|
{
|
2021-02-05 17:04:55 -05:00
|
|
|
return ImageRGBMatcher(image, tolerance, false);
|
2020-09-23 05:56:58 -04:00
|
|
|
}
|
|
|
|
|
2021-04-10 09:26:10 -04:00
|
|
|
inline ImageRGBMatcher RGBASimilarTo(const wxImage& image, int tolerance)
|
|
|
|
{
|
|
|
|
return ImageRGBMatcher(image, tolerance, true);
|
|
|
|
}
|
|
|
|
|
2020-09-23 05:56:58 -04:00
|
|
|
class ImageAlphaMatcher : public Catch::MatcherBase<wxImage>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ImageAlphaMatcher(unsigned char alpha)
|
|
|
|
: m_alpha(alpha)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool match(const wxImage& other) const wxOVERRIDE
|
|
|
|
{
|
|
|
|
if (!other.HasAlpha())
|
|
|
|
{
|
|
|
|
m_diffDesc = "no alpha data";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned char center_alpha =
|
|
|
|
*(other.GetAlpha() + (other.GetWidth() / 2) + (other.GetHeight() / 2 * other.GetWidth()));
|
|
|
|
|
|
|
|
if (m_alpha != center_alpha)
|
|
|
|
{
|
|
|
|
m_diffDesc.Printf("got alpha %u", center_alpha);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string describe() const wxOVERRIDE
|
|
|
|
{
|
|
|
|
std::string desc;
|
|
|
|
|
|
|
|
if (!m_diffDesc.empty())
|
|
|
|
desc = m_diffDesc.ToStdString(wxConvUTF8);
|
|
|
|
|
|
|
|
return desc;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
const unsigned char m_alpha;
|
|
|
|
mutable wxString m_diffDesc;
|
|
|
|
};
|
|
|
|
|
|
|
|
inline ImageAlphaMatcher CenterAlphaPixelEquals(unsigned char alpha)
|
|
|
|
{
|
|
|
|
return ImageAlphaMatcher(alpha);
|
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-01 14:15:24 -04:00
|
|
|
}
|
2011-04-26 18:57:16 -04:00
|
|
|
|
|
|
|
#endif // _WX_TESTS_TESTIMAGE_H_
|