2004-03-03 17:56:16 -05:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: test.cpp
|
|
|
|
// Purpose: Test program for wxWidgets
|
|
|
|
// Author: Mike Wetherell
|
|
|
|
// Copyright: (c) 2004 Mike Wetherell
|
2010-07-13 09:29:13 -04:00
|
|
|
// Licence: wxWindows licence
|
2004-03-03 17:56:16 -05:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2009-06-01 07:30:50 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// headers
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2004-11-22 00:00:19 -05: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 14:15:24 -04:00
|
|
|
// and "catch.hpp"
|
2004-11-22 00:00:19 -05:00
|
|
|
#include "testprec.h"
|
2004-03-03 17:56:16 -05:00
|
|
|
|
|
|
|
#ifdef __BORLANDC__
|
|
|
|
#pragma hdrstop
|
|
|
|
#endif
|
|
|
|
|
2017-11-01 20:36:48 -04: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 14:15:24 -04: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 17:56:16 -05:00
|
|
|
|
2017-11-01 20:36:48 -04: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 14:15:24 -04: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 19:22:37 -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
|
|
|
// Also define our own global variables.
|
|
|
|
namespace wxPrivate
|
|
|
|
{
|
|
|
|
std::string wxTheCurrentTestClass, wxTheCurrentTestMethod;
|
|
|
|
}
|
2009-06-06 19:22:37 -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
|
|
|
// for all others, include the necessary headers
|
|
|
|
#ifndef WX_PRECOMP
|
|
|
|
#include "wx/wx.h"
|
2009-06-06 19:22:37 -04:00
|
|
|
#endif
|
2008-11-05 05:08:19 -05:00
|
|
|
|
2018-01-13 09:56:46 -05:00
|
|
|
#include "wx/apptrait.h"
|
2004-03-03 17:56:16 -05:00
|
|
|
#include "wx/cmdline.h"
|
2010-10-04 06:53:37 -04:00
|
|
|
#include <exception>
|
2004-03-03 17:56:16 -05:00
|
|
|
#include <iostream>
|
|
|
|
|
2012-03-04 15:31:42 -05:00
|
|
|
#ifdef __WINDOWS__
|
2009-03-25 06:42:11 -04:00
|
|
|
#include "wx/msw/msvcrt.h"
|
|
|
|
#endif
|
|
|
|
|
2009-04-14 15:54:01 -04:00
|
|
|
#ifdef __WXOSX__
|
|
|
|
#include "wx/osx/private.h"
|
|
|
|
#endif
|
|
|
|
|
2010-08-22 18:16:05 -04:00
|
|
|
#if wxUSE_GUI
|
|
|
|
#include "testableframe.h"
|
2016-06-29 12:49:47 -04:00
|
|
|
|
|
|
|
#ifdef __WXGTK__
|
|
|
|
#include <glib.h>
|
|
|
|
#endif // __WXGTK__
|
|
|
|
#endif // wxUSE_GUI
|
2010-08-22 18:16:05 -04:00
|
|
|
|
2009-06-01 07:30:50 -04:00
|
|
|
#include "wx/socket.h"
|
2010-08-22 18:16:05 -04:00
|
|
|
#include "wx/evtloop.h"
|
2009-06-01 07:30:50 -04:00
|
|
|
|
2009-03-25 06:42:11 -04:00
|
|
|
using namespace std;
|
|
|
|
|
2009-06-01 07:30:50 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// helper classes
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2009-03-25 06:42:11 -04: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 14:15:24 -04:00
|
|
|
CATCH_TRANSLATE_EXCEPTION(CrtAssertFailure& e)
|
|
|
|
{
|
|
|
|
return "CRT assert failure: " + e.m_msg.ToStdString(wxConvUTF8);
|
|
|
|
}
|
|
|
|
|
2009-03-25 06:42:11 -04:00
|
|
|
#endif // wxUSE_VC_CRTDBG
|
|
|
|
|
2009-09-21 10:45:37 -04:00
|
|
|
#if wxDEBUG_LEVEL
|
|
|
|
|
2012-04-29 19:22:08 -04:00
|
|
|
// Information about the last not yet handled assertion.
|
|
|
|
static wxString s_lastAssertMessage;
|
|
|
|
|
2009-09-21 10:45:37 -04: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 06:53:37 -04: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 19:22:08 -04:00
|
|
|
|
|
|
|
const wxString
|
|
|
|
assertMessage = FormatAssertMessage(file, line, func, cond, msg);
|
|
|
|
|
2009-09-21 10:45:37 -04:00
|
|
|
if ( !wxIsMainThread() )
|
|
|
|
{
|
2010-10-04 06:53:37 -04: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 19:22:08 -04:00
|
|
|
abortReason << assertMessage << "in a worker thread.";
|
2010-10-04 06:53:37 -04: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 19:22:08 -04: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 06:53:37 -04:00
|
|
|
}
|
|
|
|
else // Can "safely" throw from here.
|
|
|
|
{
|
2012-04-29 19:22:08 -04: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 06:53:37 -04:00
|
|
|
throw TestAssertFailure(file, line, func, cond, msg);
|
2009-09-21 10:45:37 -04:00
|
|
|
}
|
|
|
|
|
2012-04-29 19:22:08 -04:00
|
|
|
wxFputs(abortReason, stderr);
|
2010-10-04 06:53:37 -04:00
|
|
|
fflush(stderr);
|
|
|
|
_exit(-1);
|
2009-09-21 10:45:37 -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
|
|
|
CATCH_TRANSLATE_EXCEPTION(TestAssertFailure& e)
|
2009-03-25 06:42:11 -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
|
|
|
return e.m_msg.ToStdString(wxConvUTF8);
|
2009-03-25 06:42:11 -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
|
|
|
#endif // wxDEBUG_LEVEL
|
2016-06-29 12:49:47 -04:00
|
|
|
|
2007-09-25 20:28:31 -04:00
|
|
|
#if wxUSE_GUI
|
|
|
|
typedef wxApp TestAppBase;
|
2018-01-13 09:56:46 -05:00
|
|
|
typedef wxGUIAppTraits TestAppTraitsBase;
|
2007-09-25 20:28:31 -04:00
|
|
|
#else
|
|
|
|
typedef wxAppConsole TestAppBase;
|
2018-01-13 09:56:46 -05:00
|
|
|
typedef wxConsoleAppTraits TestAppTraitsBase;
|
2007-09-25 20:28:31 -04:00
|
|
|
#endif
|
|
|
|
|
2004-03-03 17:56:16 -05:00
|
|
|
// The application class
|
|
|
|
//
|
2007-09-25 20:28:31 -04:00
|
|
|
class TestApp : public TestAppBase
|
2004-03-03 17:56:16 -05:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
TestApp();
|
|
|
|
|
|
|
|
// standard overrides
|
2007-09-25 20:28:31 -04:00
|
|
|
virtual bool OnInit();
|
|
|
|
virtual int OnExit();
|
2004-03-03 17:56:16 -05:00
|
|
|
|
2018-01-13 09:56:46 -05:00
|
|
|
#ifdef __WIN32__
|
|
|
|
virtual wxAppTraits *CreateTraits()
|
|
|
|
{
|
|
|
|
// 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.
|
|
|
|
virtual bool CanUseStderr() { return true; }
|
|
|
|
|
|
|
|
// Overriding CanUseStderr() is not enough, we also need to
|
|
|
|
// override this one to avoid returning false from it.
|
|
|
|
virtual bool WriteToStderr(const wxString& text)
|
|
|
|
{
|
|
|
|
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 12:08:07 -05:00
|
|
|
// Also override this method to avoid showing any dialogs from here -- and
|
|
|
|
// show some details about the exception along the way.
|
|
|
|
virtual bool OnExceptionInMainLoop()
|
|
|
|
{
|
|
|
|
wxFprintf(stderr, "Unhandled exception in the main loop: %s\n",
|
|
|
|
Catch::translateActiveException());
|
|
|
|
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
|
2009-01-16 11:21:50 -05:00
|
|
|
// used by events propagation test
|
|
|
|
virtual int FilterEvent(wxEvent& event);
|
|
|
|
virtual bool ProcessEvent(wxEvent& event);
|
|
|
|
|
|
|
|
void SetFilterEventFunc(FilterEventFunc f) { m_filterEventFunc = f; }
|
|
|
|
void SetProcessEventFunc(ProcessEventFunc f) { m_processEventFunc = f; }
|
|
|
|
|
2013-07-02 20:25:46 -04: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 11:51:30 -04:00
|
|
|
|
2013-07-02 20:25:46 -04:00
|
|
|
virtual int OnRun()
|
|
|
|
{
|
2015-04-12 11:51:30 -04:00
|
|
|
if ( TestAppBase::OnRun() != 0 )
|
|
|
|
m_exitcode = EXIT_FAILURE;
|
|
|
|
|
2013-07-02 20:25:46 -04:00
|
|
|
return m_exitcode;
|
|
|
|
}
|
2015-04-12 12:21:47 -04:00
|
|
|
#else // !wxUSE_GUI
|
|
|
|
virtual int OnRun()
|
|
|
|
{
|
|
|
|
return RunTests();
|
|
|
|
}
|
|
|
|
#endif // wxUSE_GUI/!wxUSE_GUI
|
2013-07-02 20:25:46 -04:00
|
|
|
|
2004-03-03 17:56:16 -05:00
|
|
|
private:
|
2013-07-02 20:25:46 -04:00
|
|
|
int RunTests();
|
|
|
|
|
|
|
|
// flag telling us whether we should run tests from our EVT_IDLE handler
|
|
|
|
bool m_runTests;
|
|
|
|
|
2009-01-16 11:21:50 -05:00
|
|
|
// event handling hooks
|
|
|
|
FilterEventFunc m_filterEventFunc;
|
|
|
|
ProcessEventFunc m_processEventFunc;
|
2013-07-02 20:25:46 -04:00
|
|
|
|
2015-04-12 12:21:47 -04:00
|
|
|
#if wxUSE_GUI
|
2013-07-02 20:25:46 -04:00
|
|
|
// the program exit code
|
|
|
|
int m_exitcode;
|
2015-04-12 12:21:47 -04:00
|
|
|
#endif // wxUSE_GUI
|
2004-03-03 17:56:16 -05:00
|
|
|
};
|
|
|
|
|
2015-04-23 07:49:01 -04:00
|
|
|
wxIMPLEMENT_APP_NO_MAIN(TestApp);
|
2009-03-25 06:42:11 -04:00
|
|
|
|
2009-06-01 07:30:50 -04:00
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// global functions
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2009-03-25 06:42:11 -04: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 14:15:24 -04:00
|
|
|
return wxEntry(argc, argv);
|
2009-03-25 06:42:11 -04:00
|
|
|
}
|
2004-03-03 17:56:16 -05:00
|
|
|
|
2009-06-01 07:30:50 -04:00
|
|
|
extern void SetFilterEventFunc(FilterEventFunc func)
|
|
|
|
{
|
|
|
|
wxGetApp().SetFilterEventFunc(func);
|
|
|
|
}
|
|
|
|
|
|
|
|
extern void SetProcessEventFunc(ProcessEventFunc func)
|
|
|
|
{
|
|
|
|
wxGetApp().SetProcessEventFunc(func);
|
|
|
|
}
|
|
|
|
|
|
|
|
extern bool IsNetworkAvailable()
|
|
|
|
{
|
2016-01-26 17:19:51 -05: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 07:30:50 -04: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 05:09:17 -04:00
|
|
|
|
2009-06-01 07:30:50 -04:00
|
|
|
wxSocketBase::Initialize();
|
2018-07-29 05:09:17 -04:00
|
|
|
|
2009-06-01 07:30:50 -04:00
|
|
|
wxIPV4address addr;
|
|
|
|
if (!addr.Hostname("www.google.com") || !addr.Service("www"))
|
|
|
|
{
|
|
|
|
wxSocketBase::Shutdown();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
wxSocketClient sock;
|
2009-06-01 10:55:22 -04:00
|
|
|
sock.SetTimeout(10); // 10 secs
|
2009-06-01 07:30:50 -04:00
|
|
|
bool online = sock.Connect(addr);
|
2018-07-29 05:09:17 -04:00
|
|
|
|
2009-06-01 07:30:50 -04:00
|
|
|
wxSocketBase::Shutdown();
|
2018-07-29 05:09:17 -04:00
|
|
|
|
2009-06-01 07:30:50 -04:00
|
|
|
return online;
|
|
|
|
}
|
|
|
|
|
2012-06-01 12:21:06 -04: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 15:21:42 -04:00
|
|
|
username.MakeLower();
|
2015-04-12 11:40:10 -04:00
|
|
|
s_isAutomatic = username == "buildbot" ||
|
2013-05-12 15:19:43 -04:00
|
|
|
username.Matches("sandbox*");
|
2017-03-10 21:35:11 -05:00
|
|
|
|
2017-11-22 15:25:19 -05:00
|
|
|
// Also recognize Travis and AppVeyor CI environments.
|
2017-03-10 21:35:11 -05:00
|
|
|
if ( !s_isAutomatic )
|
2017-11-22 15:25:19 -05:00
|
|
|
{
|
|
|
|
s_isAutomatic = wxGetEnv("TRAVIS", NULL) ||
|
|
|
|
wxGetEnv("APPVEYOR", NULL);
|
|
|
|
}
|
2012-06-01 12:21:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return s_isAutomatic == 1;
|
|
|
|
}
|
|
|
|
|
2016-06-29 12:22:05 -04:00
|
|
|
#if wxUSE_GUI
|
|
|
|
|
2017-11-05 11:50:09 -05: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 12:22:05 -04: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 12:49:47 -04:00
|
|
|
#ifdef __WXGTK__
|
|
|
|
|
2017-11-13 20:57:57 -05: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 12:49:47 -04:00
|
|
|
extern "C"
|
|
|
|
void
|
|
|
|
wxTestGLogHandler(const gchar* domain,
|
|
|
|
GLogLevelFlags level,
|
|
|
|
const gchar* message,
|
|
|
|
gpointer data)
|
|
|
|
{
|
2017-11-07 10:21:38 -05: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 14:15:24 -04:00
|
|
|
wxGetCurrentTestName().c_str());
|
2016-06-29 12:49:47 -04:00
|
|
|
|
|
|
|
g_log_default_handler(domain, level, message, data);
|
2017-11-07 10:21:38 -05:00
|
|
|
|
|
|
|
fprintf(stderr, "\n");
|
2016-06-29 12:49:47 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // __WXGTK__
|
|
|
|
|
2016-06-29 12:22:05 -04:00
|
|
|
#endif // wxUSE_GUI
|
2009-06-01 07:30:50 -04:00
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// TestApp
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2004-03-03 17:56:16 -05:00
|
|
|
TestApp::TestApp()
|
|
|
|
{
|
2013-07-02 20:25:46 -04:00
|
|
|
m_runTests = true;
|
|
|
|
|
2009-01-16 11:21:50 -05:00
|
|
|
m_filterEventFunc = NULL;
|
|
|
|
m_processEventFunc = NULL;
|
2009-04-03 11:31:57 -04:00
|
|
|
|
2015-04-12 12:21:47 -04:00
|
|
|
#if wxUSE_GUI
|
2013-07-02 20:25:46 -04:00
|
|
|
m_exitcode = EXIT_SUCCESS;
|
2015-04-12 12:21:47 -04:00
|
|
|
#endif // wxUSE_GUI
|
2004-03-03 17:56:16 -05: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 14:15:24 -04:00
|
|
|
// Hack: don't call TestAppBase::OnInit() to let CATCH handle command line.
|
2007-09-25 20:28:31 -04:00
|
|
|
|
2016-02-13 12:34:47 -05:00
|
|
|
// Output some important information about the test environment.
|
2009-06-01 10:46:44 -04: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 15:21:42 -04:00
|
|
|
<< "build: " << WX_BUILD_OPTIONS_SIGNATURE << "\n"
|
|
|
|
<< "running under " << wxGetOsDescription()
|
2017-11-01 20:39:49 -04:00
|
|
|
<< " as " << wxGetUserId()
|
|
|
|
<< ", locale is " << setlocale(LC_ALL, NULL)
|
|
|
|
<< std::endl;
|
2016-02-13 12:34:47 -05:00
|
|
|
|
2007-09-25 20:28:31 -04:00
|
|
|
#if wxUSE_GUI
|
2016-02-26 19:56:23 -05:00
|
|
|
// create a parent window to be used as parent for the GUI controls
|
|
|
|
new wxTestableFrame();
|
2010-08-22 18:16:05 -04:00
|
|
|
|
2013-07-02 20:25:46 -04:00
|
|
|
Connect(wxEVT_IDLE, wxIdleEventHandler(TestApp::OnIdle));
|
2016-06-29 12:49:47 -04:00
|
|
|
|
2016-07-08 09:15:27 -04:00
|
|
|
#ifdef __WXGTK20__
|
2016-06-29 12:49:47 -04:00
|
|
|
g_log_set_default_handler(wxTestGLogHandler, NULL);
|
|
|
|
#endif // __WXGTK__
|
|
|
|
|
2017-11-13 20:57:57 -05:00
|
|
|
#ifdef GDK_WINDOWING_X11
|
|
|
|
XSetErrorHandler(wxTestX11ErrorHandler);
|
|
|
|
#endif // GDK_WINDOWING_X11
|
|
|
|
|
2007-09-25 20:28:31 -04:00
|
|
|
#endif // wxUSE_GUI
|
|
|
|
|
|
|
|
return true;
|
2008-07-19 11:36:39 -04:00
|
|
|
}
|
2004-03-03 17:56:16 -05:00
|
|
|
|
2009-01-16 11:21:50 -05: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 17:56:16 -05:00
|
|
|
// Run
|
|
|
|
//
|
2013-07-02 20:25:46 -04:00
|
|
|
int TestApp::RunTests()
|
2004-03-03 17:56:16 -05:00
|
|
|
{
|
2009-03-26 11:31:54 -04: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 14:15:24 -04: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 17:56:16 -05:00
|
|
|
}
|
|
|
|
|
2007-09-25 20:28:31 -04:00
|
|
|
int TestApp::OnExit()
|
|
|
|
{
|
|
|
|
#if wxUSE_GUI
|
|
|
|
delete GetTopWindow();
|
|
|
|
#endif // wxUSE_GUI
|
|
|
|
|
2015-04-12 11:51:30 -04:00
|
|
|
return TestAppBase::OnExit();
|
2007-09-25 20:28:31 -04:00
|
|
|
}
|