add wxURL::GetInputStream test unit; add a global IsNetworkAvailable() utility to the test units
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@60851 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
105
tests/test.cpp
105
tests/test.cpp
@@ -7,6 +7,10 @@
|
||||
// Licence: wxWidgets licence
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// For compilers that support precompilation, includes "wx/wx.h"
|
||||
// and "wx/cppunit.h"
|
||||
#include "testprec.h"
|
||||
@@ -45,12 +49,19 @@
|
||||
#include "wx/osx/private.h"
|
||||
#endif
|
||||
|
||||
#include "wx/socket.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
using CppUnit::Test;
|
||||
using CppUnit::TestSuite;
|
||||
using CppUnit::TestFactoryRegistry;
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// helper classes
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// exception class for MSVC debug CRT assertion failures
|
||||
#ifdef wxUSE_VC_CRTDBG
|
||||
|
||||
@@ -79,7 +90,7 @@ static string GetExceptionMessage()
|
||||
{
|
||||
msg << "wxWidgets assert: " << e.m_cond << " failed "
|
||||
"at " << e.m_file << ":" << e.m_line << " in " << e.m_func
|
||||
<< " with message " << e.m_msg;
|
||||
<< " with message '" << e.m_msg << "'";
|
||||
}
|
||||
#endif // wxDEBUG_LEVEL
|
||||
#ifdef wxUSE_VC_CRTDBG
|
||||
@@ -244,6 +255,11 @@ private:
|
||||
|
||||
IMPLEMENT_APP_NO_MAIN(TestApp)
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// global functions
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#ifdef wxUSE_VC_CRTDBG
|
||||
|
||||
static int TestCrtReportHook(int reportType, char *message, int *)
|
||||
@@ -295,6 +311,63 @@ int main(int argc, char **argv)
|
||||
return -1;
|
||||
}
|
||||
|
||||
extern void SetFilterEventFunc(FilterEventFunc func)
|
||||
{
|
||||
wxGetApp().SetFilterEventFunc(func);
|
||||
}
|
||||
|
||||
extern void SetProcessEventFunc(ProcessEventFunc func)
|
||||
{
|
||||
wxGetApp().SetProcessEventFunc(func);
|
||||
}
|
||||
|
||||
extern bool IsNetworkAvailable()
|
||||
{
|
||||
// NOTE: we could use wxDialUpManager here if it was in wxNet; since it's in
|
||||
// wxCore we use a simple rough test:
|
||||
|
||||
wxSocketBase::Initialize();
|
||||
|
||||
wxIPV4address addr;
|
||||
if (!addr.Hostname("www.google.com") || !addr.Service("www"))
|
||||
{
|
||||
wxSocketBase::Shutdown();
|
||||
return false;
|
||||
}
|
||||
|
||||
wxSocketClient sock;
|
||||
bool online = sock.Connect(addr);
|
||||
|
||||
wxSocketBase::Shutdown();
|
||||
|
||||
return online;
|
||||
}
|
||||
|
||||
// helper of OnRun(): gets the test with the given name, returning NULL (and
|
||||
// not an empty test suite) if there is no such test
|
||||
static Test *GetTestByName(const wxString& name)
|
||||
{
|
||||
Test *
|
||||
test = TestFactoryRegistry::getRegistry(string(name.mb_str())).makeTest();
|
||||
if ( test )
|
||||
{
|
||||
TestSuite * const suite = dynamic_cast<TestSuite *>(test);
|
||||
if ( !suite || !suite->countTestCases() )
|
||||
{
|
||||
// it's a bogus test, don't use it
|
||||
delete test;
|
||||
test = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return test;
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// TestApp
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
TestApp::TestApp()
|
||||
: m_list(false),
|
||||
m_longlist(false)
|
||||
@@ -406,36 +479,6 @@ bool TestApp::ProcessEvent(wxEvent& event)
|
||||
return TestAppBase::ProcessEvent(event);
|
||||
}
|
||||
|
||||
extern void SetFilterEventFunc(FilterEventFunc func)
|
||||
{
|
||||
wxGetApp().SetFilterEventFunc(func);
|
||||
}
|
||||
|
||||
extern void SetProcessEventFunc(ProcessEventFunc func)
|
||||
{
|
||||
wxGetApp().SetProcessEventFunc(func);
|
||||
}
|
||||
|
||||
// helper of OnRun(): gets the test with the given name, returning NULL (and
|
||||
// not an empty test suite) if there is no such test
|
||||
static Test *GetTestByName(const wxString& name)
|
||||
{
|
||||
Test *
|
||||
test = TestFactoryRegistry::getRegistry(string(name.mb_str())).makeTest();
|
||||
if ( test )
|
||||
{
|
||||
TestSuite * const suite = dynamic_cast<TestSuite *>(test);
|
||||
if ( !suite || !suite->countTestCases() )
|
||||
{
|
||||
// it's a bogus test, don't use it
|
||||
delete test;
|
||||
test = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return test;
|
||||
}
|
||||
|
||||
// Run
|
||||
//
|
||||
int TestApp::OnRun()
|
||||
|
Reference in New Issue
Block a user