2004-03-03 22:56:16 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: test.cpp
|
|
|
|
// Purpose: Test program for wxWidgets
|
|
|
|
// Author: Mike Wetherell
|
|
|
|
// Copyright: (c) 2004 Mike Wetherell
|
2010-07-13 13:29:13 +00:00
|
|
|
// Licence: wxWindows licence
|
2004-03-03 22:56:16 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2009-06-01 11:30:50 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// headers
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2004-11-22 05:00:19 +00:00
|
|
|
// For compilers that support precompilation, includes "wx/wx.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 18:15:24 +00:00
|
|
|
// and "catch.hpp"
|
2004-11-22 05:00:19 +00:00
|
|
|
#include "testprec.h"
|
2004-03-03 22:56:16 +00:00
|
|
|
|
|
|
|
#ifdef __BORLANDC__
|
|
|
|
#pragma hdrstop
|
|
|
|
#endif
|
|
|
|
|
2017-11-02 00:36:48 +00:00
|
|
|
// Suppress some warnings in catch_impl.hpp.
|
|
|
|
wxCLANG_WARNING_SUPPRESS(missing-braces)
|
|
|
|
wxCLANG_WARNING_SUPPRESS(logical-op-parentheses)
|
|
|
|
|
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 18:15:24 +00:00
|
|
|
// This file needs to get the CATCH definitions in addition to the usual
|
|
|
|
// assertion macros declarations from catch.hpp included by testprec.h.
|
|
|
|
// Including an internal file like this is ugly, but there doesn't seem to be
|
|
|
|
// any better way, see https://github.com/philsquared/Catch/issues/1061
|
|
|
|
#include "internal/catch_impl.hpp"
|
2004-03-03 22:56:16 +00:00
|
|
|
|
2017-11-02 00:36:48 +00:00
|
|
|
wxCLANG_WARNING_RESTORE(missing-braces)
|
|
|
|
wxCLANG_WARNING_RESTORE(logical-op-parentheses)
|
|
|
|
|
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 18:15:24 +00:00
|
|
|
// This probably could be done by predefining CLARA_CONFIG_MAIN, but at the
|
|
|
|
// point where we are, just define this global variable manually.
|
|
|
|
namespace Catch { namespace Clara { UnpositionalTag _; } }
|
2009-06-06 23:22:37 +00: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 18:15:24 +00:00
|
|
|
// Also define our own global variables.
|
|
|
|
namespace wxPrivate
|
|
|
|
{
|
|
|
|
std::string wxTheCurrentTestClass, wxTheCurrentTestMethod;
|
|
|
|
}
|
2009-06-06 23:22:37 +00: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 18:15:24 +00:00
|
|
|
// for all others, include the necessary headers
|
|
|
|
#ifndef WX_PRECOMP
|
|
|
|
#include "wx/wx.h"
|
2009-06-06 23:22:37 +00:00
|
|
|
#endif
|
2008-11-05 10:08:19 +00:00
|
|
|
|
2018-01-13 14:56:46 +00:00
|
|
|
#include "wx/apptrait.h"
|
2004-03-03 22:56:16 +00:00
|
|
|
#include "wx/cmdline.h"
|
2010-10-04 10:53:37 +00:00
|
|
|
#include <exception>
|
2004-03-03 22:56:16 +00:00
|
|
|
#include <iostream>
|
|
|
|
|
2012-03-04 20:31:42 +00:00
|
|
|
#ifdef __WINDOWS__
|
2009-03-25 10:42:11 +00:00
|
|
|
#include "wx/msw/msvcrt.h"
|
|
|
|
#endif
|
|
|
|
|
2009-04-14 19:54:01 +00:00
|
|
|
#ifdef __WXOSX__
|
|
|
|
#include "wx/osx/private.h"
|
|
|
|
#endif
|
|
|
|
|
2010-08-22 22:16:05 +00:00
|
|
|
#if wxUSE_GUI
|
|
|
|
#include "testableframe.h"
|
2016-06-29 16:49:47 +00:00
|
|
|
|
|
|
|
#ifdef __WXGTK__
|
|
|
|
#include <glib.h>
|
|
|
|
#endif // __WXGTK__
|
|
|
|
#endif // wxUSE_GUI
|
2010-08-22 22:16:05 +00:00
|
|
|
|
2009-06-01 11:30:50 +00:00
|
|
|
#include "wx/socket.h"
|
2010-08-22 22:16:05 +00:00
|
|
|
#include "wx/evtloop.h"
|
2009-06-01 11:30:50 +00:00
|
|
|
|
2009-03-25 10:42:11 +00:00
|
|
|
using namespace std;
|
|
|
|
|
2009-06-01 11:30:50 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// helper classes
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2009-03-25 10:42:11 +00:00
|
|
|
// exception class for MSVC debug CRT assertion failures
|
|
|
|
#ifdef wxUSE_VC_CRTDBG
|
|
|
|
|
|
|
|
struct CrtAssertFailure
|
|
|
|
{
|
|
|
|
CrtAssertFailure(const char *message) : m_msg(message) { }
|
|
|
|
|
|
|
|
const wxString m_msg;
|
|
|
|
|
|
|
|
wxDECLARE_NO_ASSIGN_CLASS(CrtAssertFailure);
|
|
|
|
};
|
|
|
|
|
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 18:15:24 +00:00
|
|
|
CATCH_TRANSLATE_EXCEPTION(CrtAssertFailure& e)
|
|
|
|
{
|
|
|
|
return "CRT assert failure: " + e.m_msg.ToStdString(wxConvUTF8);
|
|
|
|
}
|
|
|
|
|
2009-03-25 10:42:11 +00:00
|
|
|
#endif // wxUSE_VC_CRTDBG
|
|
|
|
|
2009-09-21 14:45:37 +00:00
|
|
|
#if wxDEBUG_LEVEL
|
|
|
|
|
2012-04-29 23:22:08 +00:00
|
|
|
// Information about the last not yet handled assertion.
|
|
|
|
static wxString s_lastAssertMessage;
|
|
|
|
|
2009-09-21 14:45:37 +00:00
|
|
|
static wxString FormatAssertMessage(const wxString& file,
|
|
|
|
int line,
|
|
|
|
const wxString& func,
|
|
|
|
const wxString& cond,
|
|
|
|
const wxString& msg)
|
|
|
|
{
|
|
|
|
wxString str;
|
|
|
|
str << "wxWidgets assert: " << cond << " failed "
|
|
|
|
"at " << file << ":" << line << " in " << func
|
|
|
|
<< " with message '" << msg << "'";
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void TestAssertHandler(const wxString& file,
|
|
|
|
int line,
|
|
|
|
const wxString& func,
|
|
|
|
const wxString& cond,
|
|
|
|
const wxString& msg)
|
|
|
|
{
|
2010-10-04 10:53:37 +00:00
|
|
|
// Determine whether we can safely throw an exception to just make the test
|
|
|
|
// fail or whether we need to abort (in this case "msg" will contain the
|
|
|
|
// explanation why did we decide to do it).
|
|
|
|
wxString abortReason;
|
2012-04-29 23:22:08 +00:00
|
|
|
|
|
|
|
const wxString
|
|
|
|
assertMessage = FormatAssertMessage(file, line, func, cond, msg);
|
|
|
|
|
2009-09-21 14:45:37 +00:00
|
|
|
if ( !wxIsMainThread() )
|
|
|
|
{
|
2010-10-04 10:53:37 +00:00
|
|
|
// Exceptions thrown from worker threads are not caught currently and
|
|
|
|
// so we'd just die without any useful information -- abort instead.
|
2012-04-29 23:22:08 +00:00
|
|
|
abortReason << assertMessage << "in a worker thread.";
|
2010-10-04 10:53:37 +00:00
|
|
|
}
|
|
|
|
else if ( uncaught_exception() )
|
|
|
|
{
|
|
|
|
// Throwing while already handling an exception would result in
|
|
|
|
// terminate() being called and we wouldn't get any useful information
|
|
|
|
// about why the test failed then.
|
2012-04-29 23:22:08 +00:00
|
|
|
if ( s_lastAssertMessage.empty() )
|
|
|
|
{
|
|
|
|
abortReason << assertMessage << "while handling an exception";
|
|
|
|
}
|
|
|
|
else // In this case the exception is due to a previous assert.
|
|
|
|
{
|
|
|
|
abortReason << s_lastAssertMessage << "\n and another "
|
|
|
|
<< assertMessage << " while handling it.";
|
|
|
|
}
|
2010-10-04 10:53:37 +00:00
|
|
|
}
|
|
|
|
else // Can "safely" throw from here.
|
|
|
|
{
|
2012-04-29 23:22:08 +00:00
|
|
|
// Remember this in case another assert happens while handling this
|
|
|
|
// exception: we want to show the original assert as it's usually more
|
|
|
|
// useful to determine the real root of the problem.
|
|
|
|
s_lastAssertMessage = assertMessage;
|
|
|
|
|
2010-10-04 10:53:37 +00:00
|
|
|
throw TestAssertFailure(file, line, func, cond, msg);
|
2009-09-21 14:45:37 +00:00
|
|
|
}
|
|
|
|
|
2012-04-29 23:22:08 +00:00
|
|
|
wxFputs(abortReason, stderr);
|
2010-10-04 10:53:37 +00:00
|
|
|
fflush(stderr);
|
|
|
|
_exit(-1);
|
2009-09-21 14:45:37 +00: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 18:15:24 +00:00
|
|
|
CATCH_TRANSLATE_EXCEPTION(TestAssertFailure& e)
|
2009-03-25 10:42:11 +00: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 18:15:24 +00:00
|
|
|
return e.m_msg.ToStdString(wxConvUTF8);
|
2009-03-25 10:42:11 +00: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 18:15:24 +00:00
|
|
|
#endif // wxDEBUG_LEVEL
|
2016-06-29 16:49:47 +00:00
|
|
|
|
2007-09-26 00:28:31 +00:00
|
|
|
#if wxUSE_GUI
|
|
|
|
typedef wxApp TestAppBase;
|
2018-01-13 14:56:46 +00:00
|
|
|
typedef wxGUIAppTraits TestAppTraitsBase;
|
2007-09-26 00:28:31 +00:00
|
|
|
#else
|
|
|
|
typedef wxAppConsole TestAppBase;
|
2018-01-13 14:56:46 +00:00
|
|
|
typedef wxConsoleAppTraits TestAppTraitsBase;
|
2007-09-26 00:28:31 +00:00
|
|
|
#endif
|
|
|
|
|
2004-03-03 22:56:16 +00:00
|
|
|
// The application class
|
|
|
|
//
|
2007-09-26 00:28:31 +00:00
|
|
|
class TestApp : public TestAppBase
|
2004-03-03 22:56:16 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
TestApp();
|
|
|
|
|
|
|
|
// standard overrides
|
2018-09-21 17:46:49 +00:00
|
|
|
virtual bool OnInit() wxOVERRIDE;
|
|
|
|
virtual int OnExit() wxOVERRIDE;
|
2004-03-03 22:56:16 +00:00
|
|
|
|
2018-01-13 14:56:46 +00:00
|
|
|
#ifdef __WIN32__
|
2018-09-21 17:46:49 +00:00
|
|
|
virtual wxAppTraits *CreateTraits() wxOVERRIDE
|
2018-01-13 14:56:46 +00:00
|
|
|
{
|
|
|
|
// Define a new class just to customize CanUseStderr() behaviour.
|
|
|
|
class TestAppTraits : public TestAppTraitsBase
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// We want to always use stderr, tests are also run unattended and
|
|
|
|
// in this case we really don't want to show any message boxes, as
|
|
|
|
// wxMessageOutputBest, used e.g. from the default implementation
|
|
|
|
// of wxApp::OnUnhandledException(), would do by default.
|
2018-09-21 17:46:49 +00:00
|
|
|
virtual bool CanUseStderr() wxOVERRIDE { return true; }
|
2018-01-13 14:56:46 +00:00
|
|
|
|
|
|
|
// Overriding CanUseStderr() is not enough, we also need to
|
|
|
|
// override this one to avoid returning false from it.
|
2018-09-21 17:46:49 +00:00
|
|
|
virtual bool WriteToStderr(const wxString& text) wxOVERRIDE
|
2018-01-13 14:56:46 +00:00
|
|
|
{
|
|
|
|
wxFputs(text, stderr);
|
|
|
|
fflush(stderr);
|
|
|
|
|
|
|
|
// Intentionally ignore any errors, we really don't want to
|
|
|
|
// show any message boxes in any case.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
return new TestAppTraits;
|
|
|
|
}
|
|
|
|
#endif // __WIN32__
|
|
|
|
|
2018-01-13 17:08:07 +00:00
|
|
|
// Also override this method to avoid showing any dialogs from here -- and
|
|
|
|
// show some details about the exception along the way.
|
2018-09-21 17:46:49 +00:00
|
|
|
virtual bool OnExceptionInMainLoop() wxOVERRIDE
|
2018-01-13 17:08:07 +00:00
|
|
|
{
|
|
|
|
wxFprintf(stderr, "Unhandled exception in the main loop: %s\n",
|
|
|
|
Catch::translateActiveException());
|
|
|
|
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
|
2009-01-16 16:21:50 +00:00
|
|
|
// used by events propagation test
|
2018-09-21 17:46:49 +00:00
|
|
|
virtual int FilterEvent(wxEvent& event) wxOVERRIDE;
|
|
|
|
virtual bool ProcessEvent(wxEvent& event) wxOVERRIDE;
|
2009-01-16 16:21:50 +00:00
|
|
|
|
|
|
|
void SetFilterEventFunc(FilterEventFunc f) { m_filterEventFunc = f; }
|
|
|
|
void SetProcessEventFunc(ProcessEventFunc f) { m_processEventFunc = f; }
|
|
|
|
|
2013-07-03 00:25:46 +00:00
|
|
|
// In console applications we run the tests directly from the overridden
|
|
|
|
// OnRun(), but in the GUI ones we run them when we get the first call to
|
|
|
|
// our EVT_IDLE handler to ensure that we do everything from inside the
|
|
|
|
// main event loop. This is especially important under wxOSX/Cocoa where
|
|
|
|
// the main event loop is different from the others but it's also safer to
|
|
|
|
// do it like this in the other ports as we test the GUI code in the same
|
|
|
|
// context as it's used usually, in normal programs, and it might behave
|
|
|
|
// differently without the event loop.
|
|
|
|
#if wxUSE_GUI
|
|
|
|
void OnIdle(wxIdleEvent& event)
|
|
|
|
{
|
|
|
|
if ( m_runTests )
|
|
|
|
{
|
|
|
|
m_runTests = false;
|
|
|
|
|
|
|
|
#ifdef __WXOSX__
|
|
|
|
// we need to wait until the window is activated and fully ready
|
|
|
|
// otherwise no events can be posted
|
|
|
|
wxEventLoopBase* const loop = wxEventLoop::GetActive();
|
|
|
|
if ( loop )
|
|
|
|
{
|
|
|
|
loop->DispatchTimeout(1000);
|
|
|
|
loop->Yield();
|
|
|
|
}
|
|
|
|
#endif // __WXOSX__
|
|
|
|
|
|
|
|
m_exitcode = RunTests();
|
|
|
|
ExitMainLoop();
|
|
|
|
}
|
|
|
|
|
|
|
|
event.Skip();
|
|
|
|
}
|
2015-04-12 15:51:30 +00:00
|
|
|
|
2018-09-21 17:46:49 +00:00
|
|
|
virtual int OnRun() wxOVERRIDE
|
2013-07-03 00:25:46 +00:00
|
|
|
{
|
2015-04-12 15:51:30 +00:00
|
|
|
if ( TestAppBase::OnRun() != 0 )
|
|
|
|
m_exitcode = EXIT_FAILURE;
|
|
|
|
|
2013-07-03 00:25:46 +00:00
|
|
|
return m_exitcode;
|
|
|
|
}
|
2015-04-12 16:21:47 +00:00
|
|
|
#else // !wxUSE_GUI
|
2018-09-21 17:46:49 +00:00
|
|
|
virtual int OnRun() wxOVERRIDE
|
2015-04-12 16:21:47 +00:00
|
|
|
{
|
|
|
|
return RunTests();
|
|
|
|
}
|
|
|
|
#endif // wxUSE_GUI/!wxUSE_GUI
|
2013-07-03 00:25:46 +00:00
|
|
|
|
2004-03-03 22:56:16 +00:00
|
|
|
private:
|
2013-07-03 00:25:46 +00:00
|
|
|
int RunTests();
|
|
|
|
|
|
|
|
// flag telling us whether we should run tests from our EVT_IDLE handler
|
|
|
|
bool m_runTests;
|
|
|
|
|
2009-01-16 16:21:50 +00:00
|
|
|
// event handling hooks
|
|
|
|
FilterEventFunc m_filterEventFunc;
|
|
|
|
ProcessEventFunc m_processEventFunc;
|
2013-07-03 00:25:46 +00:00
|
|
|
|
2015-04-12 16:21:47 +00:00
|
|
|
#if wxUSE_GUI
|
2013-07-03 00:25:46 +00:00
|
|
|
// the program exit code
|
|
|
|
int m_exitcode;
|
2015-04-12 16:21:47 +00:00
|
|
|
#endif // wxUSE_GUI
|
2004-03-03 22:56:16 +00:00
|
|
|
};
|
|
|
|
|
2015-04-23 11:49:01 +00:00
|
|
|
wxIMPLEMENT_APP_NO_MAIN(TestApp);
|
2009-03-25 10:42:11 +00:00
|
|
|
|
2009-06-01 11:30:50 +00:00
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// global functions
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2009-03-25 10:42:11 +00:00
|
|
|
#ifdef wxUSE_VC_CRTDBG
|
|
|
|
|
|
|
|
static int TestCrtReportHook(int reportType, char *message, int *)
|
|
|
|
{
|
|
|
|
if ( reportType != _CRT_ASSERT )
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
throw CrtAssertFailure(message);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // wxUSE_VC_CRTDBG
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
// tests can be ran non-interactively so make sure we don't show any assert
|
|
|
|
// dialog boxes -- neither our own nor from MSVC debug CRT -- which would
|
|
|
|
// prevent them from completing
|
|
|
|
|
|
|
|
#if wxDEBUG_LEVEL
|
|
|
|
wxSetAssertHandler(TestAssertHandler);
|
|
|
|
#endif // wxDEBUG_LEVEL
|
|
|
|
|
|
|
|
#ifdef wxUSE_VC_CRTDBG
|
|
|
|
_CrtSetReportHook(TestCrtReportHook);
|
|
|
|
#endif // wxUSE_VC_CRTDBG
|
|
|
|
|
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 18:15:24 +00:00
|
|
|
return wxEntry(argc, argv);
|
2009-03-25 10:42:11 +00:00
|
|
|
}
|
2004-03-03 22:56:16 +00:00
|
|
|
|
2009-06-01 11:30:50 +00:00
|
|
|
extern void SetFilterEventFunc(FilterEventFunc func)
|
|
|
|
{
|
|
|
|
wxGetApp().SetFilterEventFunc(func);
|
|
|
|
}
|
|
|
|
|
|
|
|
extern void SetProcessEventFunc(ProcessEventFunc func)
|
|
|
|
{
|
|
|
|
wxGetApp().SetProcessEventFunc(func);
|
|
|
|
}
|
|
|
|
|
|
|
|
extern bool IsNetworkAvailable()
|
|
|
|
{
|
2016-01-26 22:19:51 +00:00
|
|
|
// Somehow even though network is available on Travis CI build machines,
|
|
|
|
// attempts to open remote URIs sporadically fail, so don't run these tests
|
|
|
|
// under Travis to avoid false positives.
|
|
|
|
static int s_isTravis = -1;
|
|
|
|
if ( s_isTravis == -1 )
|
|
|
|
s_isTravis = wxGetEnv("TRAVIS", NULL);
|
|
|
|
|
|
|
|
if ( s_isTravis )
|
|
|
|
return false;
|
|
|
|
|
2009-06-01 11:30:50 +00:00
|
|
|
// NOTE: we could use wxDialUpManager here if it was in wxNet; since it's in
|
|
|
|
// wxCore we use a simple rough test:
|
2018-07-29 09:09:17 +00:00
|
|
|
|
2009-06-01 11:30:50 +00:00
|
|
|
wxSocketBase::Initialize();
|
2018-07-29 09:09:17 +00:00
|
|
|
|
2009-06-01 11:30:50 +00:00
|
|
|
wxIPV4address addr;
|
|
|
|
if (!addr.Hostname("www.google.com") || !addr.Service("www"))
|
|
|
|
{
|
|
|
|
wxSocketBase::Shutdown();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
wxSocketClient sock;
|
2009-06-01 14:55:22 +00:00
|
|
|
sock.SetTimeout(10); // 10 secs
|
2009-06-01 11:30:50 +00:00
|
|
|
bool online = sock.Connect(addr);
|
2018-07-29 09:09:17 +00:00
|
|
|
|
2009-06-01 11:30:50 +00:00
|
|
|
wxSocketBase::Shutdown();
|
2018-07-29 09:09:17 +00:00
|
|
|
|
2009-06-01 11:30:50 +00:00
|
|
|
return online;
|
|
|
|
}
|
|
|
|
|
2012-06-01 16:21:06 +00:00
|
|
|
extern bool IsAutomaticTest()
|
|
|
|
{
|
|
|
|
static int s_isAutomatic = -1;
|
|
|
|
if ( s_isAutomatic == -1 )
|
|
|
|
{
|
|
|
|
// Allow setting an environment variable to emulate buildslave user for
|
|
|
|
// testing.
|
|
|
|
wxString username;
|
|
|
|
if ( !wxGetEnv("WX_TEST_USER", &username) )
|
|
|
|
username = wxGetUserId();
|
|
|
|
|
2013-05-10 19:21:42 +00:00
|
|
|
username.MakeLower();
|
2015-04-12 15:40:10 +00:00
|
|
|
s_isAutomatic = username == "buildbot" ||
|
2013-05-12 19:19:43 +00:00
|
|
|
username.Matches("sandbox*");
|
2017-03-11 02:35:11 +00:00
|
|
|
|
2017-11-22 20:25:19 +00:00
|
|
|
// Also recognize Travis and AppVeyor CI environments.
|
2017-03-11 02:35:11 +00:00
|
|
|
if ( !s_isAutomatic )
|
2017-11-22 20:25:19 +00:00
|
|
|
{
|
|
|
|
s_isAutomatic = wxGetEnv("TRAVIS", NULL) ||
|
|
|
|
wxGetEnv("APPVEYOR", NULL);
|
|
|
|
}
|
2012-06-01 16:21:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return s_isAutomatic == 1;
|
|
|
|
}
|
|
|
|
|
2016-06-29 16:22:05 +00:00
|
|
|
#if wxUSE_GUI
|
|
|
|
|
2017-11-05 16:50:09 +00:00
|
|
|
bool EnableUITests()
|
|
|
|
{
|
|
|
|
static int s_enabled = -1;
|
|
|
|
if ( s_enabled == -1 )
|
|
|
|
{
|
|
|
|
// Allow explicitly configuring this via an environment variable under
|
|
|
|
// all platforms.
|
|
|
|
wxString enabled;
|
|
|
|
if ( wxGetEnv("WX_UI_TESTS", &enabled) )
|
|
|
|
{
|
|
|
|
if ( enabled == "1" )
|
|
|
|
s_enabled = 1;
|
|
|
|
else if ( enabled == "0" )
|
|
|
|
s_enabled = 0;
|
|
|
|
else
|
|
|
|
wxFprintf(stderr, "Unknown \"WX_UI_TESTS\" value \"%s\" ignored.\n", enabled);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( s_enabled == -1 )
|
|
|
|
{
|
|
|
|
#ifdef __WXMSW__
|
|
|
|
s_enabled = 1;
|
|
|
|
#else // !__WXMSW__
|
|
|
|
s_enabled = 0;
|
|
|
|
#endif // __WXMSW__/!__WXMSW__
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return s_enabled == 1;
|
|
|
|
}
|
|
|
|
|
2016-06-29 16:22:05 +00:00
|
|
|
void DeleteTestWindow(wxWindow* win)
|
|
|
|
{
|
|
|
|
if ( !win )
|
|
|
|
return;
|
|
|
|
|
|
|
|
wxWindow* const capture = wxWindow::GetCapture();
|
|
|
|
if ( capture )
|
|
|
|
{
|
|
|
|
if ( capture == win ||
|
|
|
|
capture->GetMainWindowOfCompositeControl() == win )
|
|
|
|
capture->ReleaseMouse();
|
|
|
|
}
|
|
|
|
|
|
|
|
delete win;
|
|
|
|
}
|
|
|
|
|
2016-06-29 16:49:47 +00:00
|
|
|
#ifdef __WXGTK__
|
|
|
|
|
2017-11-14 01:57:57 +00:00
|
|
|
#ifdef GDK_WINDOWING_X11
|
|
|
|
|
|
|
|
#include "X11/Xlib.h"
|
|
|
|
|
|
|
|
extern "C"
|
|
|
|
int wxTestX11ErrorHandler(Display*, XErrorEvent*)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "\n*** X11 error while running %s(): ",
|
|
|
|
wxGetCurrentTestName().c_str());
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // GDK_WINDOWING_X11
|
|
|
|
|
2016-06-29 16:49:47 +00:00
|
|
|
extern "C"
|
|
|
|
void
|
|
|
|
wxTestGLogHandler(const gchar* domain,
|
|
|
|
GLogLevelFlags level,
|
|
|
|
const gchar* message,
|
|
|
|
gpointer data)
|
|
|
|
{
|
2017-11-07 15:21:38 +00:00
|
|
|
fprintf(stderr, "\n*** GTK log message while running %s(): ",
|
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 18:15:24 +00:00
|
|
|
wxGetCurrentTestName().c_str());
|
2016-06-29 16:49:47 +00:00
|
|
|
|
|
|
|
g_log_default_handler(domain, level, message, data);
|
2017-11-07 15:21:38 +00:00
|
|
|
|
|
|
|
fprintf(stderr, "\n");
|
2016-06-29 16:49:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // __WXGTK__
|
|
|
|
|
2016-06-29 16:22:05 +00:00
|
|
|
#endif // wxUSE_GUI
|
2009-06-01 11:30:50 +00:00
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// TestApp
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2004-03-03 22:56:16 +00:00
|
|
|
TestApp::TestApp()
|
|
|
|
{
|
2013-07-03 00:25:46 +00:00
|
|
|
m_runTests = true;
|
|
|
|
|
2009-01-16 16:21:50 +00:00
|
|
|
m_filterEventFunc = NULL;
|
|
|
|
m_processEventFunc = NULL;
|
2009-04-03 15:31:57 +00:00
|
|
|
|
2015-04-12 16:21:47 +00:00
|
|
|
#if wxUSE_GUI
|
2013-07-03 00:25:46 +00:00
|
|
|
m_exitcode = EXIT_SUCCESS;
|
2015-04-12 16:21:47 +00:00
|
|
|
#endif // wxUSE_GUI
|
2004-03-03 22:56:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Init
|
|
|
|
//
|
|
|
|
bool TestApp::OnInit()
|
|
|
|
{
|
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 18:15:24 +00:00
|
|
|
// Hack: don't call TestAppBase::OnInit() to let CATCH handle command line.
|
2007-09-26 00:28:31 +00:00
|
|
|
|
2016-02-13 17:34:47 +00:00
|
|
|
// Output some important information about the test environment.
|
2009-06-01 14:46:44 +00:00
|
|
|
#if wxUSE_GUI
|
|
|
|
cout << "Test program for wxWidgets GUI features\n"
|
|
|
|
#else
|
|
|
|
cout << "Test program for wxWidgets non-GUI features\n"
|
|
|
|
#endif
|
2013-05-10 19:21:42 +00:00
|
|
|
<< "build: " << WX_BUILD_OPTIONS_SIGNATURE << "\n"
|
|
|
|
<< "running under " << wxGetOsDescription()
|
2017-11-02 00:39:49 +00:00
|
|
|
<< " as " << wxGetUserId()
|
|
|
|
<< ", locale is " << setlocale(LC_ALL, NULL)
|
|
|
|
<< std::endl;
|
2016-02-13 17:34:47 +00:00
|
|
|
|
2007-09-26 00:28:31 +00:00
|
|
|
#if wxUSE_GUI
|
2016-02-27 00:56:23 +00:00
|
|
|
// create a parent window to be used as parent for the GUI controls
|
|
|
|
new wxTestableFrame();
|
2010-08-22 22:16:05 +00:00
|
|
|
|
2013-07-03 00:25:46 +00:00
|
|
|
Connect(wxEVT_IDLE, wxIdleEventHandler(TestApp::OnIdle));
|
2016-06-29 16:49:47 +00:00
|
|
|
|
2016-07-08 13:15:27 +00:00
|
|
|
#ifdef __WXGTK20__
|
2016-06-29 16:49:47 +00:00
|
|
|
g_log_set_default_handler(wxTestGLogHandler, NULL);
|
|
|
|
#endif // __WXGTK__
|
|
|
|
|
2017-11-14 01:57:57 +00:00
|
|
|
#ifdef GDK_WINDOWING_X11
|
|
|
|
XSetErrorHandler(wxTestX11ErrorHandler);
|
|
|
|
#endif // GDK_WINDOWING_X11
|
|
|
|
|
2007-09-26 00:28:31 +00:00
|
|
|
#endif // wxUSE_GUI
|
|
|
|
|
|
|
|
return true;
|
2008-07-19 15:36:39 +00:00
|
|
|
}
|
2004-03-03 22:56:16 +00:00
|
|
|
|
2009-01-16 16:21:50 +00:00
|
|
|
// Event handling
|
|
|
|
int TestApp::FilterEvent(wxEvent& event)
|
|
|
|
{
|
|
|
|
if ( m_filterEventFunc )
|
|
|
|
return (*m_filterEventFunc)(event);
|
|
|
|
|
|
|
|
return TestAppBase::FilterEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TestApp::ProcessEvent(wxEvent& event)
|
|
|
|
{
|
|
|
|
if ( m_processEventFunc )
|
|
|
|
return (*m_processEventFunc)(event);
|
|
|
|
|
|
|
|
return TestAppBase::ProcessEvent(event);
|
|
|
|
}
|
|
|
|
|
2004-03-03 22:56:16 +00:00
|
|
|
// Run
|
|
|
|
//
|
2013-07-03 00:25:46 +00:00
|
|
|
int TestApp::RunTests()
|
2004-03-03 22:56:16 +00:00
|
|
|
{
|
2009-03-26 15:31:54 +00:00
|
|
|
#if wxUSE_LOG
|
|
|
|
// Switch off logging unless --verbose
|
|
|
|
bool verbose = wxLog::GetVerbose();
|
|
|
|
wxLog::EnableLogging(verbose);
|
|
|
|
#else
|
|
|
|
bool verbose = false;
|
|
|
|
#endif
|
|
|
|
|
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 18:15:24 +00:00
|
|
|
// Cast is needed under MSW where Catch also provides an overload taking
|
|
|
|
// wchar_t, but as it simply converts arguments to char internally anyhow,
|
|
|
|
// we can just as well always use the char version.
|
|
|
|
return Catch::Session().run(argc, static_cast<char**>(argv));
|
2004-03-03 22:56:16 +00:00
|
|
|
}
|
|
|
|
|
2007-09-26 00:28:31 +00:00
|
|
|
int TestApp::OnExit()
|
|
|
|
{
|
|
|
|
#if wxUSE_GUI
|
|
|
|
delete GetTopWindow();
|
|
|
|
#endif // wxUSE_GUI
|
|
|
|
|
2015-04-12 15:51:30 +00:00
|
|
|
return TestAppBase::OnExit();
|
2007-09-26 00:28:31 +00:00
|
|
|
}
|