initial commit
Signed-off-by: Peter Siegmund <mars3142@noreply.mars3142.dev>
This commit is contained in:
134
libs/wxWidgets-3.3.1/tests/misc/dynamiclib.cpp
Normal file
134
libs/wxWidgets-3.3.1/tests/misc/dynamiclib.cpp
Normal file
@@ -0,0 +1,134 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: tests/misc/dynamiclib.cpp
|
||||
// Purpose: Test wxDynamicLibrary
|
||||
// Author: Francesco Montorsi (extracted from console sample)
|
||||
// Created: 2010-06-13
|
||||
// Copyright: (c) 2010 wxWidgets team
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#include "testprec.h"
|
||||
|
||||
#include "wx/dynlib.h"
|
||||
|
||||
#ifndef __WINDOWS__
|
||||
#include "wx/dir.h"
|
||||
#include "wx/filename.h"
|
||||
#endif
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// test class
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
TEST_CASE("DynamicLibrary::Load", "[dynlib]")
|
||||
{
|
||||
#if defined(__WINDOWS__)
|
||||
static const char* const LIB_NAME = "kernel32.dll";
|
||||
static const char* const FUNC_NAME = "lstrlenA";
|
||||
#elif defined(__CYGWIN__)
|
||||
static const char* const LIB_NAME = "cygwin1.dll";
|
||||
static const char* const FUNC_NAME = "strlen";
|
||||
#elif defined(__DARWIN__)
|
||||
// Under macOS 12+ we can actually load the libc dylib even though the
|
||||
// corresponding file doesn't exist on disk, so we have to handle it
|
||||
// differently.
|
||||
static const char* const LIB_NAME = "/usr/lib/libc.dylib";
|
||||
static const char* const FUNC_NAME = "strlen";
|
||||
#else // other Unix
|
||||
static const char* const candidateDirs[] =
|
||||
{
|
||||
"/lib/x86_64-linux-gnu",
|
||||
"/lib",
|
||||
"/lib64",
|
||||
"/usr/lib",
|
||||
};
|
||||
|
||||
static const char* const candidateVersions[] = { "6", "7", "6.1", "0.3", "0.1" };
|
||||
|
||||
wxString LIB_NAME;
|
||||
wxArrayString allMatches;
|
||||
for ( size_t n = 0; n < WXSIZEOF(candidateDirs); ++n )
|
||||
{
|
||||
const wxString dir(candidateDirs[n]);
|
||||
|
||||
if ( !wxDir::Exists(dir) )
|
||||
continue;
|
||||
|
||||
for ( size_t m = 0; m < WXSIZEOF(candidateVersions); ++m )
|
||||
{
|
||||
const wxString candidate = wxString::Format
|
||||
(
|
||||
"%s/libc.so.%s",
|
||||
dir, candidateVersions[m]
|
||||
);
|
||||
|
||||
if ( wxFileName::Exists(candidate) )
|
||||
{
|
||||
LIB_NAME = candidate;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ( !LIB_NAME.empty() )
|
||||
break;
|
||||
|
||||
wxDir::GetAllFiles(dir, &allMatches, "libc.*", wxDIR_FILES);
|
||||
}
|
||||
|
||||
if ( LIB_NAME.empty() )
|
||||
{
|
||||
WARN("Couldn't find libc.so, skipping DynamicLibrary::Load() test.");
|
||||
|
||||
if ( !allMatches.empty() )
|
||||
{
|
||||
WARN("Possible candidates:\n" << wxJoin(allMatches, '\n'));
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static const char* const FUNC_NAME = "strlen";
|
||||
#endif // OS
|
||||
|
||||
wxDynamicLibrary lib(LIB_NAME);
|
||||
REQUIRE( lib.IsLoaded() );
|
||||
|
||||
SECTION("strlen")
|
||||
{
|
||||
typedef int (wxSTDCALL *wxStrlenType)(const char *);
|
||||
wxStrlenType pfnStrlen = (wxStrlenType)lib.GetSymbol(FUNC_NAME);
|
||||
|
||||
if ( pfnStrlen )
|
||||
{
|
||||
// Call the function dynamically loaded
|
||||
CHECK( pfnStrlen("foo") == 3 );
|
||||
}
|
||||
else
|
||||
{
|
||||
FAIL(FUNC_NAME << " wasn't found in " << LIB_NAME);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef __WINDOWS__
|
||||
SECTION("A/W")
|
||||
{
|
||||
static const char* const FUNC_NAME_AW = "lstrlen";
|
||||
|
||||
typedef int (wxSTDCALL *wxStrlenTypeAorW)(const wxChar *);
|
||||
wxStrlenTypeAorW
|
||||
pfnStrlenAorW = (wxStrlenTypeAorW)lib.GetSymbolAorW(FUNC_NAME_AW);
|
||||
|
||||
if ( pfnStrlenAorW )
|
||||
{
|
||||
CHECK( pfnStrlenAorW(wxT("foobar")) == 6 );
|
||||
}
|
||||
else
|
||||
{
|
||||
FAIL(FUNC_NAME_AW << " wasn't found in " << LIB_NAME);
|
||||
}
|
||||
}
|
||||
#endif // __WINDOWS__
|
||||
}
|
||||
70
libs/wxWidgets-3.3.1/tests/misc/environ.cpp
Normal file
70
libs/wxWidgets-3.3.1/tests/misc/environ.cpp
Normal file
@@ -0,0 +1,70 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: tests/misc/environ.cpp
|
||||
// Purpose: Test wxGet/SetEnv
|
||||
// Author: Francesco Montorsi (extracted from console sample)
|
||||
// Created: 2010-06-13
|
||||
// Copyright: (c) 2010 wxWidgets team
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#include "testprec.h"
|
||||
|
||||
#include "wx/utils.h"
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// test class
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class EnvTestCase : public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
EnvTestCase() { }
|
||||
|
||||
private:
|
||||
CPPUNIT_TEST_SUITE( EnvTestCase );
|
||||
CPPUNIT_TEST( GetSet );
|
||||
CPPUNIT_TEST( Path );
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
void GetSet();
|
||||
void Path();
|
||||
|
||||
wxDECLARE_NO_COPY_CLASS(EnvTestCase);
|
||||
};
|
||||
|
||||
// register in the unnamed registry so that these tests are run by default
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION( EnvTestCase );
|
||||
|
||||
// also include in its own registry so that these tests can be run alone
|
||||
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( EnvTestCase, "EnvTestCase" );
|
||||
|
||||
void EnvTestCase::GetSet()
|
||||
{
|
||||
const wxChar *var = wxT("wxTestVar");
|
||||
wxString contents;
|
||||
|
||||
CPPUNIT_ASSERT(!wxGetEnv(var, &contents));
|
||||
CPPUNIT_ASSERT(contents.empty());
|
||||
|
||||
wxSetEnv(var, wxT("value for wxTestVar"));
|
||||
CPPUNIT_ASSERT(wxGetEnv(var, &contents));
|
||||
CPPUNIT_ASSERT(contents == wxT("value for wxTestVar"));
|
||||
|
||||
wxSetEnv(var, wxT("another value"));
|
||||
CPPUNIT_ASSERT(wxGetEnv(var, &contents));
|
||||
CPPUNIT_ASSERT(contents == wxT("another value"));
|
||||
|
||||
wxUnsetEnv(var);
|
||||
CPPUNIT_ASSERT(!wxGetEnv(var, &contents));
|
||||
}
|
||||
|
||||
void EnvTestCase::Path()
|
||||
{
|
||||
wxString contents;
|
||||
|
||||
CPPUNIT_ASSERT(wxGetEnv(wxT("PATH"), &contents));
|
||||
CPPUNIT_ASSERT(!contents.empty());
|
||||
}
|
||||
195
libs/wxWidgets-3.3.1/tests/misc/garbage.cpp
Normal file
195
libs/wxWidgets-3.3.1/tests/misc/garbage.cpp
Normal file
@@ -0,0 +1,195 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: tests/misc/garbage.cpp
|
||||
// Purpose: test if loading garbage fails
|
||||
// Author: Francesco Montorsi
|
||||
// Created: 2009-01-10
|
||||
// Copyright: (c) 2009 Francesco Montorsi
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#include "testprec.h"
|
||||
|
||||
|
||||
#include "wx/filename.h"
|
||||
#include "wx/image.h"
|
||||
#include "wx/icon.h"
|
||||
#include "wx/animate.h"
|
||||
#include "wx/mstream.h"
|
||||
#include "wx/dynlib.h"
|
||||
#include "wx/mediactrl.h"
|
||||
#include "wx/html/htmlwin.h"
|
||||
#include "wx/xrc/xmlres.h"
|
||||
|
||||
#define GARBAGE_DATA_SIZE 1000000 // in bytes; ~ 1MB
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// test class
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class GarbageTestCase : public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
GarbageTestCase() { }
|
||||
|
||||
private:
|
||||
CPPUNIT_TEST_SUITE( GarbageTestCase );
|
||||
CPPUNIT_TEST( LoadGarbage );
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
void LoadGarbage();
|
||||
void DoLoadFile(const wxString& fullname);
|
||||
void DoLoadStream(wxInputStream& stream);
|
||||
|
||||
wxDECLARE_NO_COPY_CLASS(GarbageTestCase);
|
||||
};
|
||||
|
||||
// register in the unnamed registry so that these tests are run by default
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION( GarbageTestCase );
|
||||
|
||||
// also include in its own registry so that these tests can be run alone
|
||||
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( GarbageTestCase, "GarbageTestCase" );
|
||||
|
||||
|
||||
void GarbageTestCase::LoadGarbage()
|
||||
{
|
||||
srand(1234);
|
||||
|
||||
wxInitAllImageHandlers();
|
||||
|
||||
for (size_t size = 1; size < GARBAGE_DATA_SIZE; size *= size+1)
|
||||
{
|
||||
// first, generate some garbage data
|
||||
unsigned char *data = new unsigned char[size];
|
||||
for (size_t i = 0; i < size; i++)
|
||||
data[i] = rand();
|
||||
|
||||
// write it to a file
|
||||
wxString garbagename = wxFileName::CreateTempFileName("garbage");
|
||||
CPPUNIT_ASSERT( !garbagename.empty() );
|
||||
|
||||
wxFile garbage(garbagename, wxFile::write);
|
||||
CPPUNIT_ASSERT( garbage.IsOpened() );
|
||||
|
||||
CPPUNIT_ASSERT( garbage.Write(data, size) == size );
|
||||
garbage.Close();
|
||||
|
||||
// try to load it by name
|
||||
DoLoadFile(garbagename);
|
||||
|
||||
// try to load it from a wxInputStream
|
||||
wxMemoryInputStream stream(data, size);
|
||||
DoLoadStream(stream);
|
||||
|
||||
wxDELETEA(data);
|
||||
}
|
||||
}
|
||||
|
||||
// Execute the given macro with the given first and second parameters and
|
||||
// bitmap type as its third parameter for all bitmap types.
|
||||
#define wxFOR_ALL_VALID_BITMAP_TYPES(m, p1, p2) \
|
||||
for ( wxBitmapType type = wxBitmapType(wxBITMAP_TYPE_INVALID + 1); \
|
||||
type < wxBITMAP_TYPE_MAX; \
|
||||
type = (wxBitmapType)(type + 1) ) \
|
||||
m(p1, p2, type)
|
||||
|
||||
// Similar to above but for animation types.
|
||||
#define wxFOR_ALL_VALID_ANIMATION_TYPES(m, p1, p2) \
|
||||
for ( wxAnimationType type = wxAnimationType(wxANIMATION_TYPE_INVALID + 1); \
|
||||
type < wxANIMATION_TYPE_ANY; \
|
||||
type = (wxAnimationType)(type + 1) ) \
|
||||
m(p1, p2, type)
|
||||
|
||||
// This macro is used as an argument to wxFOR_ALL_VALID_BITMAP_TYPES() to
|
||||
// include the information about the type for which the test failed.
|
||||
#define ASSERT_FUNC_FAILS_FOR_TYPE(func, arg, type) \
|
||||
WX_ASSERT_MESSAGE \
|
||||
( \
|
||||
(#func "() unexpectedly succeeded for type %d", type), \
|
||||
!func(arg) \
|
||||
)
|
||||
|
||||
// And this one exists mostly just for consistency with the one above.
|
||||
#define ASSERT_FUNC_FAILS(func, arg) \
|
||||
WX_ASSERT_MESSAGE \
|
||||
( \
|
||||
(#func "() unexpectedly succeeded for default type"), \
|
||||
!func(arg) \
|
||||
)
|
||||
|
||||
void GarbageTestCase::DoLoadFile(const wxString& fullname)
|
||||
{
|
||||
// test wxImage
|
||||
wxImage img;
|
||||
ASSERT_FUNC_FAILS(img.LoadFile, fullname);
|
||||
wxFOR_ALL_VALID_BITMAP_TYPES(ASSERT_FUNC_FAILS_FOR_TYPE, img.LoadFile, fullname);
|
||||
|
||||
// test wxBitmap
|
||||
wxBitmap bmp;
|
||||
ASSERT_FUNC_FAILS(bmp.LoadFile, fullname);
|
||||
wxFOR_ALL_VALID_BITMAP_TYPES(ASSERT_FUNC_FAILS_FOR_TYPE, bmp.LoadFile, fullname);
|
||||
|
||||
// test wxIcon
|
||||
wxIcon icon;
|
||||
ASSERT_FUNC_FAILS(icon.LoadFile, fullname);
|
||||
wxFOR_ALL_VALID_BITMAP_TYPES(ASSERT_FUNC_FAILS_FOR_TYPE, icon.LoadFile, fullname);
|
||||
|
||||
#if wxUSE_ANIMATIONCTRL
|
||||
// test wxAnimation
|
||||
wxAnimation anim;
|
||||
ASSERT_FUNC_FAILS(anim.LoadFile, fullname);
|
||||
wxFOR_ALL_VALID_ANIMATION_TYPES(ASSERT_FUNC_FAILS_FOR_TYPE, anim.LoadFile, fullname);
|
||||
#endif
|
||||
|
||||
// test wxDynamicLibrary
|
||||
wxDynamicLibrary lib;
|
||||
CPPUNIT_ASSERT( lib.Load(fullname) == false );
|
||||
|
||||
/*
|
||||
#if wxUSE_MEDIACTRL
|
||||
// test wxMediaCtrl
|
||||
wxMediaCtrl *media = new wxMediaCtrl(wxTheApp->GetTopWindow());
|
||||
CPPUNIT_ASSERT( media->Load(fullname) == false );
|
||||
#endif
|
||||
|
||||
// test wxHtmlWindow
|
||||
wxHtmlWindow *htmlwin = new wxHtmlWindow(wxTheApp->GetTopWindow());
|
||||
CPPUNIT_ASSERT( htmlwin->LoadFile(fullname) == false );
|
||||
delete htmlwin;
|
||||
*/
|
||||
// test wxXmlResource
|
||||
#if wxUSE_XRC
|
||||
CPPUNIT_ASSERT( wxXmlResource::Get()->Load(fullname) == false );
|
||||
#endif
|
||||
}
|
||||
|
||||
void GarbageTestCase::DoLoadStream(wxInputStream& stream)
|
||||
{
|
||||
// NOTE: not all classes tested by DoLoadFile() supports loading
|
||||
// from an input stream!
|
||||
|
||||
// test wxImage
|
||||
wxImage img;
|
||||
ASSERT_FUNC_FAILS(img.LoadFile, stream);
|
||||
wxFOR_ALL_VALID_BITMAP_TYPES(ASSERT_FUNC_FAILS_FOR_TYPE, img.LoadFile, stream);
|
||||
|
||||
#if wxUSE_ANIMATIONCTRL
|
||||
// test wxAnimation
|
||||
wxAnimation anim;
|
||||
ASSERT_FUNC_FAILS(anim.Load, stream);
|
||||
wxFOR_ALL_VALID_BITMAP_TYPES(ASSERT_FUNC_FAILS_FOR_TYPE, anim.Load, stream);
|
||||
#endif
|
||||
/*
|
||||
// test wxHtmlWindow
|
||||
wxHtmlWindow *htmlwin = new wxHtmlWindow(wxTheApp->GetTopWindow());
|
||||
CPPUNIT_ASSERT( htmlwin->LoadFile(fullname) == false );
|
||||
delete htmlwin;
|
||||
*/
|
||||
}
|
||||
|
||||
#undef ASSERT_FUNC_FAILS
|
||||
#undef ASSERT_FUNC_FAILS_FOR_TYPE
|
||||
#undef wxFOR_ALL_VALID_ANIMATION_TYPES
|
||||
#undef wxFOR_ALL_VALID_BITMAP_TYPES
|
||||
272
libs/wxWidgets-3.3.1/tests/misc/guifuncs.cpp
Normal file
272
libs/wxWidgets-3.3.1/tests/misc/guifuncs.cpp
Normal file
@@ -0,0 +1,272 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: tests/misc/misctests.cpp
|
||||
// Purpose: test miscellaneous GUI functions
|
||||
// Author: Vadim Zeitlin
|
||||
// Created: 2008-09-22
|
||||
// Copyright: (c) 2008 Vadim Zeitlin
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#include "testprec.h"
|
||||
|
||||
|
||||
#include "wx/defs.h"
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/gdicmn.h"
|
||||
#include "wx/filefn.h"
|
||||
#endif // !PCH
|
||||
|
||||
#include "wx/app.h"
|
||||
#include "wx/button.h"
|
||||
#include "wx/clipbrd.h"
|
||||
#include "wx/dataobj.h"
|
||||
#include "wx/panel.h"
|
||||
|
||||
#include "asserthelper.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// the tests
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
TEST_CASE("GUI::DisplaySize", "[guifuncs]")
|
||||
{
|
||||
// test that different (almost) overloads return the same results
|
||||
int w, h;
|
||||
wxDisplaySize(&w, &h);
|
||||
wxSize sz = wxGetDisplaySize();
|
||||
|
||||
CHECK( sz.x == w );
|
||||
CHECK( sz.y == h );
|
||||
|
||||
// test that passing nullptr works as expected, e.g. doesn't crash
|
||||
wxDisplaySize(nullptr, nullptr);
|
||||
wxDisplaySize(&w, nullptr);
|
||||
wxDisplaySize(nullptr, &h);
|
||||
|
||||
CHECK( sz.x == w );
|
||||
CHECK( sz.y == h );
|
||||
|
||||
// test that display PPI is something reasonable
|
||||
sz = wxGetDisplayPPI();
|
||||
CHECK( sz.x < 1000 );
|
||||
CHECK( sz.y < 1000 );
|
||||
}
|
||||
|
||||
#if wxUSE_DATAOBJ
|
||||
TEST_CASE("GUI::TextDataObject", "[guifuncs][clipboard]")
|
||||
{
|
||||
const wxString text("Hello clipboard!");
|
||||
|
||||
wxTextDataObject* const dobj = new wxTextDataObject(text);
|
||||
CHECK( dobj->GetText() == text );
|
||||
|
||||
wxClipboardLocker lockClip;
|
||||
CHECK( wxTheClipboard->SetData(dobj) );
|
||||
wxTheClipboard->Flush();
|
||||
|
||||
wxTextDataObject dobj2;
|
||||
REQUIRE( wxTheClipboard->GetData(dobj2) );
|
||||
CHECK( dobj2.GetText() == text );
|
||||
}
|
||||
|
||||
TEST_CASE("GUI::URLDataObject", "[guifuncs][clipboard]")
|
||||
{
|
||||
// this tests for buffer overflow, see #11102
|
||||
const char * const
|
||||
url = "http://something.long.to.overwrite.plenty.memory.example.com";
|
||||
wxURLDataObject * const dobj = new wxURLDataObject(url);
|
||||
CHECK( dobj->GetURL() == url );
|
||||
|
||||
wxClipboardLocker lockClip;
|
||||
CHECK( wxTheClipboard->SetData(dobj) );
|
||||
wxTheClipboard->Flush();
|
||||
|
||||
wxURLDataObject dobj2;
|
||||
REQUIRE( wxTheClipboard->GetData(dobj2) );
|
||||
CHECK( dobj2.GetURL() == url );
|
||||
}
|
||||
|
||||
TEST_CASE("GUI::HTMLDataObject", "[guifuncs][clipboard]")
|
||||
{
|
||||
const wxString text("<h1>Hello clipboard!</h1>");
|
||||
|
||||
wxHTMLDataObject* const dobj = new wxHTMLDataObject(text);
|
||||
CHECK( dobj->GetHTML() == text );
|
||||
|
||||
wxClipboardLocker lockClip;
|
||||
CHECK( wxTheClipboard->SetData(dobj) );
|
||||
wxTheClipboard->Flush();
|
||||
|
||||
wxHTMLDataObject dobj2;
|
||||
REQUIRE( wxTheClipboard->GetData(dobj2) );
|
||||
CHECK( dobj2.GetHTML() == text );
|
||||
}
|
||||
|
||||
// This disabled by default test allows to check that we retrieve HTML data
|
||||
// from the system clipboard correctly.
|
||||
TEST_CASE("GUI::ShowHTML", "[.]")
|
||||
{
|
||||
wxClipboardLocker lockClip;
|
||||
|
||||
wxHTMLDataObject dobj;
|
||||
REQUIRE( wxTheClipboard->GetData(dobj) );
|
||||
|
||||
WARN("Clipboard contents:\n---start---\n" << dobj.GetHTML() << "\n---end--");
|
||||
}
|
||||
|
||||
TEST_CASE("GUI::DataFormatCompare", "[guifuncs][dataformat]")
|
||||
{
|
||||
const wxDataFormat df(wxDF_TEXT);
|
||||
CHECK( df == wxDF_TEXT );
|
||||
CHECK( df != wxDF_INVALID );
|
||||
}
|
||||
#endif // wxUSE_DATAOBJ
|
||||
|
||||
TEST_CASE("GUI::ParseFileDialogFilter", "[guifuncs]")
|
||||
{
|
||||
wxArrayString descs,
|
||||
filters;
|
||||
|
||||
REQUIRE
|
||||
(
|
||||
wxParseCommonDialogsFilter("Image files|*.jpg;*.png", descs, filters)
|
||||
== 1
|
||||
);
|
||||
|
||||
CHECK( descs[0] == "Image files" );
|
||||
CHECK( filters[0] == "*.jpg;*.png" );
|
||||
|
||||
REQUIRE
|
||||
(
|
||||
wxParseCommonDialogsFilter
|
||||
(
|
||||
"All files (*.*)|*.*|Python source (*.py)|*.py",
|
||||
descs, filters
|
||||
)
|
||||
== 2
|
||||
);
|
||||
|
||||
CHECK( filters[0] == "*.*" );
|
||||
CHECK( filters[1] == "*.py" );
|
||||
|
||||
// Test some invalid ones too.
|
||||
WX_ASSERT_FAILS_WITH_ASSERT
|
||||
(
|
||||
wxParseCommonDialogsFilter
|
||||
(
|
||||
"All files (*.*)|*.*|Python source (*.py)|*.py|",
|
||||
descs, filters
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
TEST_CASE("GUI::ClientToScreen", "[guifuncs]")
|
||||
{
|
||||
wxWindow* const tlw = wxTheApp->GetTopWindow();
|
||||
REQUIRE( tlw );
|
||||
|
||||
std::unique_ptr<wxPanel> const
|
||||
p1(new wxPanel(tlw, wxID_ANY, wxPoint(0, 0), wxSize(100, 50)));
|
||||
std::unique_ptr<wxPanel> const
|
||||
p2(new wxPanel(tlw, wxID_ANY, wxPoint(0, 50), wxSize(100, 50)));
|
||||
wxWindow* const
|
||||
b = new wxWindow(p2.get(), wxID_ANY, wxPoint(10, 10), wxSize(30, 10));
|
||||
|
||||
// We need this to realize the windows created above under wxGTK.
|
||||
wxYield();
|
||||
|
||||
const wxPoint tlwOrig = tlw->ClientToScreen(wxPoint(0, 0));
|
||||
|
||||
CHECK( p2->ClientToScreen(wxPoint(0, 0)) == tlwOrig + wxPoint(0, 50) );
|
||||
|
||||
CHECK( b->ClientToScreen(wxPoint(0, 0)) == tlwOrig + wxPoint(10, 60) );
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
// This class is used as a test window here. We can't use a real wxButton
|
||||
// because we can't create other windows as its children in wxGTK.
|
||||
class TestButton : public wxWindow
|
||||
{
|
||||
public:
|
||||
TestButton(wxWindow* parent, const wxString& label, const wxPoint& pos)
|
||||
: wxWindow(parent, wxID_ANY, pos, wxSize(100, 50))
|
||||
{
|
||||
SetLabel(label);
|
||||
}
|
||||
};
|
||||
|
||||
// Helper function returning the label of the window at the given point or
|
||||
// "NONE" if there is no window there.
|
||||
wxString GetLabelOfWindowAtPoint(wxWindow* parent, int x, int y)
|
||||
{
|
||||
wxWindow* const
|
||||
win = wxFindWindowAtPoint(parent->ClientToScreen(wxPoint(x, y)));
|
||||
return win ? win->GetLabel() : wxString("NONE");
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
TEST_CASE("GUI::FindWindowAtPoint", "[guifuncs]")
|
||||
{
|
||||
wxWindow* const parent = wxTheApp->GetTopWindow();
|
||||
REQUIRE( parent );
|
||||
|
||||
// Set a label to allow distinguishing it from the other windows in the
|
||||
// assertion messages.
|
||||
parent->SetLabel("parent");
|
||||
|
||||
std::unique_ptr<wxWindow> btn1(new TestButton(parent, "1", wxPoint(10, 10)));
|
||||
std::unique_ptr<wxWindow> btn2(new TestButton(parent, "2", wxPoint(10, 90)));
|
||||
|
||||
// No need to use std::unique_ptr<> for this one, it will be deleted by btn2.
|
||||
wxWindow* btn3 = new TestButton(btn2.get(), "3", wxPoint(20, 20));
|
||||
|
||||
// We need this to realize the windows created above under wxGTK.
|
||||
wxYield();
|
||||
|
||||
INFO("No window for a point outside of the window");
|
||||
CHECK( GetLabelOfWindowAtPoint(parent, 900, 900) == "NONE" );
|
||||
|
||||
INFO( "Point over a child control corresponds to it" );
|
||||
CHECK( GetLabelOfWindowAtPoint(parent, 11, 11) == btn1->GetLabel() );
|
||||
|
||||
INFO("Point outside of any child control returns the TLW itself");
|
||||
CHECK( GetLabelOfWindowAtPoint(parent, 5, 5) == parent->GetLabel() );
|
||||
|
||||
btn2->Disable();
|
||||
INFO("Point over a disabled child control still corresponds to it");
|
||||
CHECK( GetLabelOfWindowAtPoint(parent, 11, 91) == btn2->GetLabel() );
|
||||
|
||||
btn2->Hide();
|
||||
INFO("Point over a hidden child control doesn't take it into account");
|
||||
CHECK( GetLabelOfWindowAtPoint(parent, 11, 91) == parent->GetLabel() );
|
||||
|
||||
btn2->Show();
|
||||
INFO("Point over child control corresponds to the child");
|
||||
CHECK( GetLabelOfWindowAtPoint(parent, 31, 111) == btn3->GetLabel() );
|
||||
|
||||
btn3->Disable();
|
||||
INFO("Point over disabled child controls still corresponds to this child");
|
||||
CHECK( GetLabelOfWindowAtPoint(parent, 31, 111) == btn3->GetLabel() );
|
||||
}
|
||||
|
||||
TEST_CASE("wxWindow::Dump", "[window]")
|
||||
{
|
||||
CHECK_NOTHROW( wxDumpWindow(nullptr) );
|
||||
|
||||
std::unique_ptr<wxButton>
|
||||
button(new wxButton(wxTheApp->GetTopWindow(), wxID_ANY, "bloordyblop"));
|
||||
|
||||
const std::string s = wxDumpWindow(button.get()).utf8_string();
|
||||
|
||||
CHECK_THAT( s, Catch::Contains("wxButton") );
|
||||
CHECK_THAT( s, Catch::Contains("bloordyblop") );
|
||||
}
|
||||
94
libs/wxWidgets-3.3.1/tests/misc/metatest.cpp
Normal file
94
libs/wxWidgets-3.3.1/tests/misc/metatest.cpp
Normal file
@@ -0,0 +1,94 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: tests/misc/metatest.cpp
|
||||
// Purpose: Test template meta-programming constructs
|
||||
// Author: Jaakko Salli
|
||||
// Copyright: (c) the wxWidgets team
|
||||
// Licence: wxWindows licence
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "testprec.h"
|
||||
|
||||
#include "wx/object.h"
|
||||
#include "wx/utils.h"
|
||||
#include "wx/meta/pod.h"
|
||||
#include "wx/meta/movable.h"
|
||||
|
||||
#ifndef wxNO_RTTI
|
||||
#include <typeinfo>
|
||||
#endif
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// test class
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class MetaProgrammingTestCase : public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
MetaProgrammingTestCase() { }
|
||||
|
||||
private:
|
||||
CPPUNIT_TEST_SUITE( MetaProgrammingTestCase );
|
||||
CPPUNIT_TEST( IsPod );
|
||||
CPPUNIT_TEST( IsMovable );
|
||||
CPPUNIT_TEST( ImplicitConversion );
|
||||
CPPUNIT_TEST( MinMax );
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
void IsPod();
|
||||
void IsMovable();
|
||||
void ImplicitConversion();
|
||||
void MinMax();
|
||||
|
||||
wxDECLARE_NO_COPY_CLASS(MetaProgrammingTestCase);
|
||||
};
|
||||
|
||||
// register in the unnamed registry so that these tests are run by default
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION( MetaProgrammingTestCase );
|
||||
|
||||
// also include in its own registry so that these tests can be run alone
|
||||
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( MetaProgrammingTestCase,
|
||||
"MetaProgrammingTestCase" );
|
||||
|
||||
|
||||
void MetaProgrammingTestCase::IsPod()
|
||||
{
|
||||
CPPUNIT_ASSERT(wxIsPod<bool>::value);
|
||||
CPPUNIT_ASSERT(wxIsPod<signed int>::value);
|
||||
CPPUNIT_ASSERT(wxIsPod<double>::value);
|
||||
CPPUNIT_ASSERT(wxIsPod<wxObject*>::value);
|
||||
CPPUNIT_ASSERT(!wxIsPod<wxObject>::value);
|
||||
}
|
||||
|
||||
void MetaProgrammingTestCase::IsMovable()
|
||||
{
|
||||
CPPUNIT_ASSERT(wxIsMovable<bool>::value);
|
||||
CPPUNIT_ASSERT(wxIsMovable<signed int>::value);
|
||||
CPPUNIT_ASSERT(wxIsMovable<double>::value);
|
||||
CPPUNIT_ASSERT(wxIsMovable<wxObject*>::value);
|
||||
CPPUNIT_ASSERT(!wxIsMovable<wxObject>::value);
|
||||
}
|
||||
|
||||
void MetaProgrammingTestCase::ImplicitConversion()
|
||||
{
|
||||
#ifndef wxNO_RTTI
|
||||
CPPUNIT_ASSERT(typeid(wxImplicitConversionType<char,int>::value) == typeid(int));
|
||||
CPPUNIT_ASSERT(typeid(wxImplicitConversionType<int,unsigned>::value) == typeid(unsigned));
|
||||
CPPUNIT_ASSERT(typeid(wxImplicitConversionType<wxLongLong_t,float>::value) == typeid(float));
|
||||
#endif // !wxNO_RTTI
|
||||
}
|
||||
|
||||
void MetaProgrammingTestCase::MinMax()
|
||||
{
|
||||
// test that wxMax(1.1,1) returns float, not long int
|
||||
float f = wxMax(1.1f, 1l);
|
||||
CPPUNIT_ASSERT_EQUAL( 1.1f, f);
|
||||
|
||||
// test that comparing signed and unsigned correctly returns unsigned: this
|
||||
// may seem counterintuitive in this case but this is consistent with the
|
||||
// standard C conversions
|
||||
CPPUNIT_ASSERT_EQUAL( 1, wxMin(-1, 1u) );
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL( -1., wxClip(-1.5, -1, 1) );
|
||||
CPPUNIT_ASSERT_EQUAL( 0, wxClip(0, -1, 1) );
|
||||
CPPUNIT_ASSERT_EQUAL( 1, wxClip(2l, -1, 1) );
|
||||
}
|
||||
314
libs/wxWidgets-3.3.1/tests/misc/misctests.cpp
Normal file
314
libs/wxWidgets-3.3.1/tests/misc/misctests.cpp
Normal file
@@ -0,0 +1,314 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: tests/misc/misctests.cpp
|
||||
// Purpose: test miscellaneous stuff
|
||||
// Author: Peter Most, Vadim Zeitlin
|
||||
// Created: 2008-07-10
|
||||
// Copyright: (c) 2008 Peter Most
|
||||
// (c) 2009 Vadim Zeitlin
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#include "testprec.h"
|
||||
|
||||
|
||||
#include "wx/defs.h"
|
||||
|
||||
#include "wx/math.h"
|
||||
#include "wx/mimetype.h"
|
||||
#include "wx/versioninfo.h"
|
||||
#include "wx/utils.h"
|
||||
|
||||
#include "wx/private/wordwrap.h"
|
||||
|
||||
// just some classes using wxRTTI for wxStaticCast() test
|
||||
#include "wx/tarstrm.h"
|
||||
#include "wx/zipstrm.h"
|
||||
|
||||
#ifdef __WINDOWS__
|
||||
// Needed for wxMulDivInt32().
|
||||
#include "wx/msw/wrapwin.h"
|
||||
#endif
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// test class
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class MiscTestCase : public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
MiscTestCase() { }
|
||||
|
||||
private:
|
||||
CPPUNIT_TEST_SUITE( MiscTestCase );
|
||||
CPPUNIT_TEST( Assert );
|
||||
CPPUNIT_TEST( CallForEach );
|
||||
CPPUNIT_TEST( Delete );
|
||||
CPPUNIT_TEST( StaticCast );
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
void Assert();
|
||||
void CallForEach();
|
||||
void Delete();
|
||||
void StaticCast();
|
||||
|
||||
wxDECLARE_NO_COPY_CLASS(MiscTestCase);
|
||||
};
|
||||
|
||||
// register in the unnamed registry so that these tests are run by default
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION( MiscTestCase );
|
||||
|
||||
// also include in its own registry so that these tests can be run alone
|
||||
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( MiscTestCase, "MiscTestCase" );
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
bool AssertIfOdd(int n)
|
||||
{
|
||||
wxCHECK_MSG( !(n % 2), false, "parameter must be even" );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
void MiscTestCase::Assert()
|
||||
{
|
||||
AssertIfOdd(0);
|
||||
WX_ASSERT_FAILS_WITH_ASSERT(AssertIfOdd(1));
|
||||
|
||||
// doesn't fail any more
|
||||
wxAssertHandler_t oldHandler = wxSetAssertHandler(nullptr);
|
||||
AssertIfOdd(17);
|
||||
wxSetAssertHandler(oldHandler);
|
||||
}
|
||||
|
||||
void MiscTestCase::CallForEach()
|
||||
{
|
||||
#define MY_MACRO(pos, str) s += str;
|
||||
|
||||
wxString s;
|
||||
wxCALL_FOR_EACH(MY_MACRO, "foo", "bar", "baz");
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL( "foobarbaz", s );
|
||||
|
||||
#undef MY_MACRO
|
||||
}
|
||||
|
||||
void MiscTestCase::Delete()
|
||||
{
|
||||
// Allocate some arbitrary memory to get a valid pointer:
|
||||
long *pointer = new long;
|
||||
CPPUNIT_ASSERT( pointer != nullptr );
|
||||
|
||||
// Check that wxDELETE sets the pointer to nullptr:
|
||||
wxDELETE( pointer );
|
||||
CPPUNIT_ASSERT( pointer == nullptr );
|
||||
|
||||
// Allocate some arbitrary array to get a valid pointer:
|
||||
long *array = new long[ 3 ];
|
||||
CPPUNIT_ASSERT( array != nullptr );
|
||||
|
||||
// Check that wxDELETEA sets the pointer to nullptr:
|
||||
wxDELETEA( array );
|
||||
CPPUNIT_ASSERT( array == nullptr );
|
||||
|
||||
// this results in compilation error, as it should
|
||||
#if 0
|
||||
struct SomeUnknownStruct *p = nullptr;
|
||||
wxDELETE(p);
|
||||
#endif
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
#ifdef __WXDEBUG__
|
||||
|
||||
// helper function used just to avoid warnings about value computed not being
|
||||
// used in WX_ASSERT_FAILS_WITH_ASSERT() in StaticCast() below
|
||||
bool IsNull(void *p)
|
||||
{
|
||||
return p == nullptr;
|
||||
}
|
||||
|
||||
#endif // __WXDEBUG__
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
void MiscTestCase::StaticCast()
|
||||
{
|
||||
#if wxUSE_TARSTREAM
|
||||
wxTarEntry tarEntry;
|
||||
CPPUNIT_ASSERT( wxStaticCast(&tarEntry, wxArchiveEntry) );
|
||||
|
||||
wxArchiveEntry *entry = &tarEntry;
|
||||
CPPUNIT_ASSERT( wxStaticCast(entry, wxTarEntry) );
|
||||
|
||||
#if wxUSE_ZIPSTREAM
|
||||
wxZipEntry zipEntry;
|
||||
entry = &zipEntry;
|
||||
CPPUNIT_ASSERT( wxStaticCast(entry, wxZipEntry) );
|
||||
WX_ASSERT_FAILS_WITH_ASSERT( IsNull(wxStaticCast(&zipEntry, wxTarEntry)) );
|
||||
#endif // wxUSE_ZIPSTREAM
|
||||
|
||||
WX_ASSERT_FAILS_WITH_ASSERT( IsNull(wxStaticCast(entry, wxTarEntry)) );
|
||||
#endif // wxUSE_TARSTREAM
|
||||
}
|
||||
|
||||
TEST_CASE("RTTI::ClassInfo", "[rtti]")
|
||||
{
|
||||
wxObject obj;
|
||||
CHECK( obj.GetClassInfo()->IsKindOf(wxCLASSINFO(wxObject)) );
|
||||
CHECK( !obj.GetClassInfo()->IsKindOf(wxCLASSINFO(wxArchiveEntry)) );
|
||||
|
||||
#if wxUSE_ZIPSTREAM
|
||||
wxZipEntry zipEntry;
|
||||
CHECK( zipEntry.GetClassInfo()->IsKindOf(wxCLASSINFO(wxArchiveEntry)) );
|
||||
#endif // wxUSE_ZIPSTREAM
|
||||
}
|
||||
|
||||
TEST_CASE("wxObjectDataPtr", "[ptr]")
|
||||
{
|
||||
struct Foo : wxObjectRefData
|
||||
{
|
||||
explicit Foo(int value) : m_value{value} {}
|
||||
int m_value;
|
||||
};
|
||||
|
||||
wxObjectDataPtr<Foo> p1, p2;
|
||||
CHECK( p1 == p2 );
|
||||
|
||||
p1 = new Foo(1);
|
||||
CHECK( p1 != p2 );
|
||||
|
||||
p2 = new Foo(2);
|
||||
CHECK( p1 != p2 );
|
||||
}
|
||||
|
||||
TEST_CASE("wxCTZ", "[math]")
|
||||
{
|
||||
CHECK( wxCTZ(1) == 0 );
|
||||
CHECK( wxCTZ(4) == 2 );
|
||||
CHECK( wxCTZ(17) == 0 );
|
||||
CHECK( wxCTZ(0x80000000) == 31 );
|
||||
|
||||
WX_ASSERT_FAILS_WITH_ASSERT( wxCTZ(0) );
|
||||
}
|
||||
|
||||
TEST_CASE("wxRound", "[math]")
|
||||
{
|
||||
CHECK( wxRound(2.3) == 2 );
|
||||
CHECK( wxRound(3.7) == 4 );
|
||||
CHECK( wxRound(-0.5f) == -1 );
|
||||
|
||||
WX_ASSERT_FAILS_WITH_ASSERT( wxRound(2.0*INT_MAX) );
|
||||
WX_ASSERT_FAILS_WITH_ASSERT( wxRound(1.1*INT_MIN) );
|
||||
|
||||
// For compatibility reasons, we allow using wxRound() with integer types
|
||||
// as well, even if this doesn't really make sense/
|
||||
#if WXWIN_COMPATIBILITY_3_0
|
||||
#ifdef __VISUALC__
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable:4996)
|
||||
#endif
|
||||
wxGCC_WARNING_SUPPRESS(deprecated-declarations)
|
||||
|
||||
CHECK( wxRound(-9) == -9 );
|
||||
CHECK( wxRound((size_t)17) == 17 );
|
||||
CHECK( wxRound((short)289) == 289 );
|
||||
|
||||
wxGCC_WARNING_RESTORE(deprecated-declarations)
|
||||
#ifdef __VISUALC__
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
#endif // WXWIN_COMPATIBILITY_3_0
|
||||
}
|
||||
|
||||
TEST_CASE("wxMulDivInt32", "[math]")
|
||||
{
|
||||
// Check that it rounds correctly.
|
||||
CHECK( wxMulDivInt32(15, 3, 2) == 23 );
|
||||
|
||||
// Check that it doesn't overflow.
|
||||
CHECK( wxMulDivInt32((INT_MAX - 1)/2, 200, 100) == INT_MAX - 1 );
|
||||
}
|
||||
|
||||
#if wxUSE_MIMETYPE
|
||||
TEST_CASE("wxFileTypeInfo", "[mime]")
|
||||
{
|
||||
SECTION("no extensions")
|
||||
{
|
||||
wxFileTypeInfo fti("binary/*", "", wxString{}, L"plain binary");
|
||||
REQUIRE( fti.GetExtensionsCount() == 0 );
|
||||
}
|
||||
|
||||
SECTION("extension without null at the end")
|
||||
{
|
||||
wxFileTypeInfo fti("image/png", "", wxEmptyString, "PNG image", "png");
|
||||
REQUIRE( fti.GetExtensionsCount() == 1 );
|
||||
CHECK( fti.GetExtensions()[0] == "png" );
|
||||
}
|
||||
|
||||
SECTION("two extensions with null at the end")
|
||||
{
|
||||
wxFileTypeInfo fti("image/jpeg", "", "", "JPEG image",
|
||||
"jpg", L"jpeg", nullptr);
|
||||
REQUIRE( fti.GetExtensionsCount() == 2 );
|
||||
CHECK( fti.GetExtensions()[0] == "jpg" );
|
||||
CHECK( fti.GetExtensions()[1] == "jpeg" );
|
||||
}
|
||||
}
|
||||
#endif // wxUSE_MIMETYPE
|
||||
|
||||
TEST_CASE("wxVersionInfo", "[version]")
|
||||
{
|
||||
wxVersionInfo ver120("test", 1, 2);
|
||||
CHECK( ver120.AtLeast(1, 2) );
|
||||
CHECK( ver120.AtLeast(1, 0) );
|
||||
CHECK( ver120.AtLeast(0, 9) );
|
||||
|
||||
CHECK_FALSE( ver120.AtLeast(1, 2, 1) );
|
||||
CHECK_FALSE( ver120.AtLeast(1, 3) );
|
||||
CHECK_FALSE( ver120.AtLeast(2, 0) );
|
||||
}
|
||||
|
||||
TEST_CASE("wxGetLibraryVersionInfo", "[libraryversion]")
|
||||
{
|
||||
// We especially want to ensure that wxGetLibraryVersionInfo()
|
||||
// is available in wxBase, and successfully links, too.
|
||||
wxVersionInfo libver = wxGetLibraryVersionInfo();
|
||||
CHECK( libver.GetNumericVersionString().starts_with("3.") );
|
||||
}
|
||||
|
||||
TEST_CASE("wxWordWrap", "[wordwrap]")
|
||||
{
|
||||
// Use artificially small max width to make the tests shorter and simpler.
|
||||
constexpr int N = 8;
|
||||
|
||||
CHECK( wxWordWrap("", N).empty() );
|
||||
|
||||
CHECK_THAT( wxWordWrap("foo", N),
|
||||
Catch::Equals<wxString>({"foo"}) );
|
||||
CHECK_THAT( wxWordWrap("foo bar", N),
|
||||
Catch::Equals<wxString>({"foo bar"}) );
|
||||
CHECK_THAT( wxWordWrap("foo quux", N),
|
||||
Catch::Equals<wxString>({"foo quux"}) );
|
||||
CHECK_THAT( wxWordWrap("foo bar baz", N),
|
||||
Catch::Equals<wxString>({"foo bar", "baz"}) );
|
||||
CHECK_THAT( wxWordWrap("foo barbaz", N),
|
||||
Catch::Equals<wxString>({"foo", "barbaz"}) );
|
||||
CHECK_THAT( wxWordWrap("foobarbaz", N),
|
||||
Catch::Equals<wxString>({"foobarba", "z"}) );
|
||||
|
||||
CHECK_THAT( wxWordWrap("some more realistic text is wrapped correctly", 15),
|
||||
Catch::Equals<wxString>({
|
||||
"some more",
|
||||
"realistic text",
|
||||
"is wrapped",
|
||||
"correctly"
|
||||
}) );
|
||||
}
|
||||
104
libs/wxWidgets-3.3.1/tests/misc/module.cpp
Normal file
104
libs/wxWidgets-3.3.1/tests/misc/module.cpp
Normal file
@@ -0,0 +1,104 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: tests/misc/module.cpp
|
||||
// Purpose: Test wxModule
|
||||
// Author: Francesco Montorsi (extracted from console sample)
|
||||
// Created: 2010-06-02
|
||||
// Copyright: (c) 2010 wxWidgets team
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#include "testprec.h"
|
||||
|
||||
#include "wx/module.h"
|
||||
#include "wx/wxcrt.h" // for wxStrcat()
|
||||
|
||||
static bool gs_wasInitialized = wxModule::AreInitialized();
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// test classes derived from wxModule
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
wxString g_strLoadOrder;
|
||||
|
||||
class Module : public wxModule
|
||||
{
|
||||
protected:
|
||||
virtual bool OnInit() override { g_strLoadOrder += GetClassInfo()->GetClassName(); return true; }
|
||||
virtual void OnExit() override { }
|
||||
};
|
||||
|
||||
class ModuleA : public Module
|
||||
{
|
||||
public:
|
||||
ModuleA();
|
||||
private:
|
||||
wxDECLARE_DYNAMIC_CLASS(ModuleA);
|
||||
};
|
||||
|
||||
class ModuleB : public Module
|
||||
{
|
||||
public:
|
||||
ModuleB();
|
||||
private:
|
||||
wxDECLARE_DYNAMIC_CLASS(ModuleB);
|
||||
};
|
||||
|
||||
class ModuleC : public Module
|
||||
{
|
||||
public:
|
||||
ModuleC();
|
||||
private:
|
||||
wxDECLARE_DYNAMIC_CLASS(ModuleC);
|
||||
};
|
||||
|
||||
class ModuleD : public Module
|
||||
{
|
||||
public:
|
||||
ModuleD();
|
||||
private:
|
||||
wxDECLARE_DYNAMIC_CLASS(ModuleD);
|
||||
};
|
||||
|
||||
wxIMPLEMENT_DYNAMIC_CLASS(ModuleA, wxModule);
|
||||
ModuleA::ModuleA()
|
||||
{
|
||||
AddDependency(CLASSINFO(ModuleB));
|
||||
AddDependency(CLASSINFO(ModuleD));
|
||||
}
|
||||
|
||||
wxIMPLEMENT_DYNAMIC_CLASS(ModuleB, wxModule);
|
||||
ModuleB::ModuleB()
|
||||
{
|
||||
AddDependency(CLASSINFO(ModuleC));
|
||||
AddDependency(CLASSINFO(ModuleD));
|
||||
}
|
||||
|
||||
wxIMPLEMENT_DYNAMIC_CLASS(ModuleC, wxModule);
|
||||
ModuleC::ModuleC()
|
||||
{
|
||||
AddDependency(CLASSINFO(ModuleD));
|
||||
}
|
||||
|
||||
wxIMPLEMENT_DYNAMIC_CLASS(ModuleD, wxModule);
|
||||
ModuleD::ModuleD()
|
||||
{
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// tests themselves
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
TEST_CASE("wxModule::Initialized", "[module]")
|
||||
{
|
||||
CHECK( !gs_wasInitialized );
|
||||
CHECK( wxModule::AreInitialized() );
|
||||
}
|
||||
|
||||
TEST_CASE("wxModule::LoadOrder", "[module]")
|
||||
{
|
||||
// module D is the only one with no dependencies and so should load as first (and so on):
|
||||
CHECK( g_strLoadOrder == "ModuleDModuleCModuleBModuleA" );
|
||||
}
|
||||
31
libs/wxWidgets-3.3.1/tests/misc/pathlist.cpp
Normal file
31
libs/wxWidgets-3.3.1/tests/misc/pathlist.cpp
Normal file
@@ -0,0 +1,31 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: tests/misc/pathlist.cpp
|
||||
// Purpose: Test wxPathList
|
||||
// Author: Francesco Montorsi (extracted from console sample)
|
||||
// Created: 2010-06-02
|
||||
// Copyright: (c) 2010 wxWidgets team
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#include "testprec.h"
|
||||
|
||||
#include "wx/filefn.h"
|
||||
|
||||
TEST_CASE("wxPathList::FindValidPath", "[file][path]")
|
||||
{
|
||||
#ifdef __UNIX__
|
||||
#define CMD_IN_PATH "ls"
|
||||
#else
|
||||
#define CMD_IN_PATH "cmd.exe"
|
||||
#endif
|
||||
|
||||
wxPathList pathlist;
|
||||
pathlist.AddEnvList(wxT("PATH"));
|
||||
|
||||
wxString path = pathlist.FindValidPath(CMD_IN_PATH);
|
||||
INFO( CMD_IN_PATH " not found in " << wxGetenv("PATH") );
|
||||
CHECK( !path.empty() );
|
||||
}
|
||||
200
libs/wxWidgets-3.3.1/tests/misc/safearrayconverttest.cpp
Normal file
200
libs/wxWidgets-3.3.1/tests/misc/safearrayconverttest.cpp
Normal file
@@ -0,0 +1,200 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: tests/misc/safearrayconverttest.cpp
|
||||
// Purpose: Test conversions between wxVariant and OLE VARIANT using SAFEARRAYs
|
||||
// Author: PB
|
||||
// Copyright: (c) the wxWidgets team
|
||||
// Licence: wxWindows licence
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "testprec.h"
|
||||
|
||||
|
||||
#ifdef __WINDOWS__
|
||||
|
||||
#if wxUSE_OLE && wxUSE_VARIANT
|
||||
|
||||
#include "wx/msw/ole/oleutils.h"
|
||||
#include "wx/msw/ole/safearray.h"
|
||||
|
||||
// need this to be able to use CPPUNIT_ASSERT_EQUAL with wxVariant objects
|
||||
inline std::ostream& operator<<(std::ostream& ostr, const wxVariant& v)
|
||||
{
|
||||
ostr << v.GetString();
|
||||
return ostr;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// test class
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class SafeArrayConvertTestCase : public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
SafeArrayConvertTestCase () { }
|
||||
|
||||
private:
|
||||
CPPUNIT_TEST_SUITE( SafeArrayConvertTestCase );
|
||||
CPPUNIT_TEST( VariantListDefault );
|
||||
CPPUNIT_TEST( VariantStringsDefault );
|
||||
CPPUNIT_TEST( VariantListReturnSafeArray );
|
||||
CPPUNIT_TEST( StringsReturnSafeArray );
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
void VariantListDefault();
|
||||
void VariantStringsDefault();
|
||||
|
||||
void VariantListReturnSafeArray();
|
||||
void StringsReturnSafeArray();
|
||||
|
||||
wxDECLARE_NO_COPY_CLASS(SafeArrayConvertTestCase);
|
||||
};
|
||||
|
||||
// register in the unnamed registry so that these tests are run by default
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION( SafeArrayConvertTestCase );
|
||||
|
||||
// also include in its own registry so that these tests can be run alone
|
||||
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( SafeArrayConvertTestCase, "SafeArrayConvertTestCase" );
|
||||
|
||||
|
||||
|
||||
// test converting a wxVariant with the list type to an OLE VARIANT
|
||||
// and back to wxVariant the list type
|
||||
void SafeArrayConvertTestCase::VariantListDefault()
|
||||
{
|
||||
wxVariant variant;
|
||||
VARIANT oleVariant;
|
||||
|
||||
variant.NullList();
|
||||
variant.Append(true);
|
||||
variant.Append(12.34);
|
||||
variant.Append(42L);
|
||||
variant.Append("ABC");
|
||||
CPPUNIT_ASSERT( wxConvertVariantToOle(variant, oleVariant) );
|
||||
|
||||
wxVariant variantCopy;
|
||||
|
||||
CPPUNIT_ASSERT( wxConvertOleToVariant(oleVariant, variantCopy) );
|
||||
CPPUNIT_ASSERT( variant == variantCopy );
|
||||
}
|
||||
|
||||
// test converting a wxVariant with the arrstring type to an OLE VARIANT
|
||||
// and back to a wxVariant with the arrstring type
|
||||
void SafeArrayConvertTestCase::VariantStringsDefault()
|
||||
{
|
||||
wxVariant variant;
|
||||
wxArrayString as;
|
||||
VARIANT oleVariant;
|
||||
|
||||
as.push_back("abc");
|
||||
as.push_back("def");
|
||||
as.push_back("ghi");
|
||||
variant = as;
|
||||
CPPUNIT_ASSERT( wxConvertVariantToOle(variant, oleVariant) );
|
||||
|
||||
wxVariant variantCopy;
|
||||
|
||||
CPPUNIT_ASSERT( wxConvertOleToVariant(oleVariant, variantCopy) );
|
||||
CPPUNIT_ASSERT( variant == variantCopy );
|
||||
}
|
||||
|
||||
// test converting a wxVariant with the list type to an OLE VARIANT
|
||||
// and then to a wxVariant with the safearray type
|
||||
void SafeArrayConvertTestCase::VariantListReturnSafeArray()
|
||||
{
|
||||
wxVariant variant;
|
||||
VARIANT oleVariant;
|
||||
|
||||
variant.NullList();
|
||||
variant.Append(true);
|
||||
variant.Append(12.34);
|
||||
variant.Append(42L);
|
||||
variant.Append("test");
|
||||
CPPUNIT_ASSERT( wxConvertVariantToOle(variant, oleVariant) );
|
||||
|
||||
wxVariant variantCopy;
|
||||
|
||||
CPPUNIT_ASSERT(
|
||||
wxConvertOleToVariant(oleVariant, variantCopy,
|
||||
wxOleConvertVariant_ReturnSafeArrays)
|
||||
);
|
||||
CPPUNIT_ASSERT( variantCopy.GetType() == wxT("safearray") );
|
||||
|
||||
wxSafeArray<VT_VARIANT> safeArray;
|
||||
wxVariantDataSafeArray*
|
||||
vsa = wxStaticCastVariantData(variantCopy.GetData(),
|
||||
wxVariantDataSafeArray);
|
||||
long bound wxDUMMY_INITIALIZE(0);
|
||||
|
||||
CPPUNIT_ASSERT( vsa );
|
||||
CPPUNIT_ASSERT( safeArray.Attach(vsa->GetValue()) );
|
||||
CPPUNIT_ASSERT_EQUAL( 1, safeArray.GetDim() );
|
||||
CPPUNIT_ASSERT( safeArray.GetLBound(1, bound) );
|
||||
CPPUNIT_ASSERT_EQUAL( 0, bound );
|
||||
CPPUNIT_ASSERT( safeArray.GetUBound(1, bound) );
|
||||
|
||||
const long count = variant.GetCount();
|
||||
|
||||
// bound + 1 because safearray elements are accessed by index ranging from
|
||||
// LBound to UBound inclusive
|
||||
CPPUNIT_ASSERT_EQUAL( bound + 1, count );
|
||||
|
||||
wxVariant variantItem;
|
||||
|
||||
for ( long i = 0; i < count; i++ )
|
||||
{
|
||||
CPPUNIT_ASSERT( safeArray.GetElement(&i, variantItem) );
|
||||
CPPUNIT_ASSERT_EQUAL( variantItem, variant[i] );
|
||||
}
|
||||
}
|
||||
|
||||
// test converting a wxArrayString to an OLE VARIANT
|
||||
// and then to a wxVariant with the safearray type
|
||||
void SafeArrayConvertTestCase::StringsReturnSafeArray()
|
||||
{
|
||||
wxArrayString as;
|
||||
wxSafeArray<VT_BSTR> safeArray;
|
||||
|
||||
as.push_back("abc");
|
||||
as.push_back("def");
|
||||
as.push_back("ghi");
|
||||
CPPUNIT_ASSERT( safeArray.CreateFromArrayString(as) );
|
||||
|
||||
VARIANT oleVariant;
|
||||
wxVariant variant;
|
||||
|
||||
oleVariant.vt = VT_BSTR | VT_ARRAY;
|
||||
oleVariant.parray = safeArray.Detach();
|
||||
CPPUNIT_ASSERT( oleVariant.parray );
|
||||
CPPUNIT_ASSERT(
|
||||
wxConvertOleToVariant(oleVariant, variant,
|
||||
wxOleConvertVariant_ReturnSafeArrays)
|
||||
);
|
||||
CPPUNIT_ASSERT( variant.GetType() == wxT("safearray") );
|
||||
|
||||
wxVariantDataSafeArray*
|
||||
vsa = wxStaticCastVariantData(variant.GetData(),
|
||||
wxVariantDataSafeArray);
|
||||
long bound wxDUMMY_INITIALIZE(0);
|
||||
|
||||
CPPUNIT_ASSERT( vsa );
|
||||
CPPUNIT_ASSERT( safeArray.Attach(vsa->GetValue()) );
|
||||
CPPUNIT_ASSERT_EQUAL( 1, safeArray.GetDim() );
|
||||
CPPUNIT_ASSERT( safeArray.GetLBound(1, bound) );
|
||||
CPPUNIT_ASSERT_EQUAL( 0, bound );
|
||||
CPPUNIT_ASSERT( safeArray.GetUBound(1, bound) );
|
||||
|
||||
const long count = as.size();
|
||||
CPPUNIT_ASSERT_EQUAL( bound + 1, count );
|
||||
|
||||
wxString str;
|
||||
|
||||
for ( long i = 0; i < count; i++ )
|
||||
{
|
||||
CPPUNIT_ASSERT( safeArray.GetElement(&i, str) );
|
||||
CPPUNIT_ASSERT( str == as[i] );
|
||||
}
|
||||
}
|
||||
|
||||
#endif // __WINDOWS__
|
||||
|
||||
#endif // wxUSE_OLE && wxUSE_VARIANT
|
||||
168
libs/wxWidgets-3.3.1/tests/misc/selstoretest.cpp
Normal file
168
libs/wxWidgets-3.3.1/tests/misc/selstoretest.cpp
Normal file
@@ -0,0 +1,168 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: tests/misc/selstoretest.cpp
|
||||
// Purpose: wxSelectionStore unit test
|
||||
// Author: Vadim Zeitlin
|
||||
// Created: 2008-03-31
|
||||
// Copyright: (c) 2008 Vadim Zeitlin
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#include "testprec.h"
|
||||
|
||||
|
||||
#include "wx/selstore.h"
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// test class
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class SelStoreTest
|
||||
{
|
||||
public:
|
||||
SelStoreTest()
|
||||
{
|
||||
m_store.SetItemCount(NUM_ITEMS);
|
||||
}
|
||||
|
||||
// NB: must be even
|
||||
static const unsigned NUM_ITEMS;
|
||||
|
||||
wxSelectionStore m_store;
|
||||
|
||||
wxDECLARE_NO_COPY_CLASS(SelStoreTest);
|
||||
};
|
||||
|
||||
const unsigned SelStoreTest::NUM_ITEMS = 10; // NB: must be even
|
||||
|
||||
TEST_CASE_METHOD(SelStoreTest, "wxSelectionStore::SelectItem", "[selstore]")
|
||||
{
|
||||
m_store.SelectItem(0);
|
||||
CHECK( m_store.GetSelectedCount() == 1 );
|
||||
CHECK( m_store.IsSelected(0) );
|
||||
|
||||
m_store.SelectItem(NUM_ITEMS - 1);
|
||||
CHECK( m_store.GetSelectedCount() == 2 );
|
||||
CHECK( m_store.IsSelected(NUM_ITEMS - 1) );
|
||||
|
||||
m_store.SelectItem(0, false);
|
||||
CHECK( m_store.GetSelectedCount() == 1 );
|
||||
CHECK( !m_store.IsSelected(0) );
|
||||
}
|
||||
|
||||
TEST_CASE_METHOD(SelStoreTest, "wxSelectionStore::SelectRange", "[selstore]")
|
||||
{
|
||||
m_store.SelectRange(0, NUM_ITEMS/2);
|
||||
CHECK( m_store.GetSelectedCount() == NUM_ITEMS/2 + 1 );
|
||||
CHECK( m_store.IsSelected(0) );
|
||||
CHECK( !m_store.IsSelected(NUM_ITEMS - 1) );
|
||||
|
||||
m_store.SelectRange(NUM_ITEMS/2, NUM_ITEMS - 1);
|
||||
CHECK( m_store.GetSelectedCount() == NUM_ITEMS );
|
||||
CHECK( m_store.IsSelected(0) );
|
||||
CHECK( m_store.IsSelected(NUM_ITEMS - 1) );
|
||||
|
||||
m_store.SelectRange(1, NUM_ITEMS - 2, false);
|
||||
CHECK( m_store.GetSelectedCount() == 2 );
|
||||
CHECK( m_store.IsSelected(0) );
|
||||
CHECK( !m_store.IsSelected(NUM_ITEMS/2) );
|
||||
CHECK( m_store.IsSelected(NUM_ITEMS - 1) );
|
||||
}
|
||||
|
||||
TEST_CASE_METHOD(SelStoreTest, "wxSelectionStore::SetItemCount", "[selstore]")
|
||||
{
|
||||
m_store.SelectRange(1, NUM_ITEMS - 2);
|
||||
CHECK( m_store.GetSelectedCount() == NUM_ITEMS - 2 );
|
||||
|
||||
m_store.SetItemCount(NUM_ITEMS/2);
|
||||
CHECK( m_store.GetSelectedCount() == NUM_ITEMS/2 - 1 );
|
||||
|
||||
|
||||
m_store.Clear();
|
||||
m_store.SetItemCount(NUM_ITEMS);
|
||||
|
||||
|
||||
m_store.SelectItem(NUM_ITEMS/2 - 1);
|
||||
m_store.SelectItem(NUM_ITEMS/2 + 1);
|
||||
m_store.SetItemCount(NUM_ITEMS/2);
|
||||
CHECK( m_store.GetSelectedCount() == 1 );
|
||||
}
|
||||
|
||||
TEST_CASE_METHOD(SelStoreTest, "wxSelectionStore::Clear", "[selstore]")
|
||||
{
|
||||
CHECK(m_store.IsEmpty());
|
||||
CHECK( m_store.GetSelectedCount() == 0 );
|
||||
|
||||
m_store.SelectItem(0);
|
||||
|
||||
CHECK(!m_store.IsEmpty());
|
||||
|
||||
m_store.Clear();
|
||||
|
||||
CHECK(m_store.IsEmpty());
|
||||
CHECK( m_store.GetSelectedCount() == 0 );
|
||||
}
|
||||
|
||||
TEST_CASE_METHOD(SelStoreTest, "wxSelectionStore::Iterate", "[selstore]")
|
||||
{
|
||||
m_store.SelectRange(NUM_ITEMS/2 - 1, NUM_ITEMS/2 + 1);
|
||||
|
||||
wxSelectionStore::IterationState cookie;
|
||||
CHECK(NUM_ITEMS/2 - 1 == m_store.GetFirstSelectedItem(cookie));
|
||||
CHECK(NUM_ITEMS/2 == m_store.GetNextSelectedItem(cookie));
|
||||
CHECK(NUM_ITEMS/2 + 1 == m_store.GetNextSelectedItem(cookie));
|
||||
|
||||
CHECK(wxSelectionStore::NO_SELECTION == m_store.GetNextSelectedItem(cookie));
|
||||
|
||||
|
||||
m_store.SelectRange(0, NUM_ITEMS - 1);
|
||||
m_store.SelectItem(0, false);
|
||||
CHECK(1 == m_store.GetFirstSelectedItem(cookie));
|
||||
}
|
||||
|
||||
TEST_CASE_METHOD(SelStoreTest, "wxSelectionStore::ItemsAddDelete", "[selstore]")
|
||||
{
|
||||
m_store.SelectItem(0);
|
||||
m_store.SelectItem(NUM_ITEMS/2);
|
||||
m_store.SelectItem(NUM_ITEMS - 1);
|
||||
|
||||
m_store.OnItemsInserted(NUM_ITEMS/2 + 1, 1);
|
||||
CHECK(m_store.IsSelected(0));
|
||||
CHECK(m_store.IsSelected(NUM_ITEMS/2));
|
||||
CHECK(m_store.IsSelected(NUM_ITEMS));
|
||||
CHECK(m_store.GetSelectedCount() == 3);
|
||||
|
||||
CHECK(m_store.OnItemsDeleted(NUM_ITEMS/2 - 1, 2));
|
||||
CHECK(m_store.IsSelected(0));
|
||||
CHECK(m_store.IsSelected(NUM_ITEMS - 2));
|
||||
CHECK(m_store.GetSelectedCount() == 2);
|
||||
|
||||
m_store.OnItemsInserted(0, 2);
|
||||
CHECK(m_store.IsSelected(2));
|
||||
CHECK(m_store.IsSelected(NUM_ITEMS));
|
||||
CHECK(m_store.GetSelectedCount() == 2);
|
||||
|
||||
m_store.OnItemDelete(0);
|
||||
|
||||
m_store.SelectRange(0, NUM_ITEMS - 1);
|
||||
CHECK(m_store.OnItemsDeleted(0, NUM_ITEMS/2));
|
||||
CHECK(m_store.GetSelectedCount() == NUM_ITEMS/2);
|
||||
CHECK(m_store.IsSelected(0));
|
||||
CHECK(m_store.IsSelected(NUM_ITEMS/2));
|
||||
}
|
||||
|
||||
TEST_CASE_METHOD(SelStoreTest, "wxSelectionStore::InsertInSelected", "[selstore]")
|
||||
{
|
||||
m_store.SelectRange(0, NUM_ITEMS - 1);
|
||||
CHECK( m_store.GetSelectedCount() == NUM_ITEMS );
|
||||
|
||||
// Newly inserted items shouldn't be selected, even if all the existing
|
||||
// ones are.
|
||||
m_store.OnItemsInserted(1, 3);
|
||||
CHECK( !m_store.IsSelected(1) );
|
||||
CHECK( !m_store.IsSelected(2) );
|
||||
CHECK( !m_store.IsSelected(3) );
|
||||
CHECK( m_store.GetSelectedCount() == NUM_ITEMS );
|
||||
}
|
||||
167
libs/wxWidgets-3.3.1/tests/misc/settings.cpp
Normal file
167
libs/wxWidgets-3.3.1/tests/misc/settings.cpp
Normal file
@@ -0,0 +1,167 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: tests/misc/settings.cpp
|
||||
// Purpose: test wxSettings
|
||||
// Author: Francesco Montorsi
|
||||
// Created: 2009-03-24
|
||||
// Copyright: (c) 2009 Francesco Montorsi
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#include "testprec.h"
|
||||
|
||||
|
||||
#include "wx/settings.h"
|
||||
#include "wx/fontenum.h"
|
||||
#include "wx/brush.h"
|
||||
#include "wx/pen.h"
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// test class
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class SettingsTestCase : public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
SettingsTestCase() { }
|
||||
|
||||
private:
|
||||
CPPUNIT_TEST_SUITE( SettingsTestCase );
|
||||
CPPUNIT_TEST( GetColour );
|
||||
CPPUNIT_TEST( GetFont );
|
||||
CPPUNIT_TEST( GlobalColours );
|
||||
CPPUNIT_TEST( GlobalFonts );
|
||||
CPPUNIT_TEST( GlobalBrushes );
|
||||
CPPUNIT_TEST( GlobalPens );
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
void GetColour();
|
||||
void GetFont();
|
||||
|
||||
// not really wxSystemSettings stuff but still nice to test:
|
||||
void GlobalColours();
|
||||
void GlobalFonts();
|
||||
void GlobalBrushes();
|
||||
void GlobalPens();
|
||||
|
||||
wxDECLARE_NO_COPY_CLASS(SettingsTestCase);
|
||||
};
|
||||
|
||||
// register in the unnamed registry so that these tests are run by default
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION( SettingsTestCase );
|
||||
|
||||
// also include in its own registry so that these tests can be run alone
|
||||
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( SettingsTestCase, "SettingsTestCase" );
|
||||
|
||||
|
||||
void SettingsTestCase::GetColour()
|
||||
{
|
||||
for (unsigned int i=wxSYS_COLOUR_SCROLLBAR; i < wxSYS_COLOUR_MAX; i++)
|
||||
CPPUNIT_ASSERT( wxSystemSettings::GetColour((wxSystemColour)i).IsOk() );
|
||||
}
|
||||
|
||||
void SettingsTestCase::GetFont()
|
||||
{
|
||||
const wxSystemFont ids[] =
|
||||
{
|
||||
wxSYS_OEM_FIXED_FONT,
|
||||
wxSYS_ANSI_FIXED_FONT,
|
||||
wxSYS_ANSI_VAR_FONT,
|
||||
wxSYS_SYSTEM_FONT,
|
||||
wxSYS_DEVICE_DEFAULT_FONT,
|
||||
wxSYS_SYSTEM_FIXED_FONT,
|
||||
wxSYS_DEFAULT_GUI_FONT
|
||||
};
|
||||
|
||||
for (unsigned int i=0; i < WXSIZEOF(ids); i++)
|
||||
{
|
||||
const wxFont& font = wxSystemSettings::GetFont(ids[i]);
|
||||
CPPUNIT_ASSERT( font.IsOk() );
|
||||
CPPUNIT_ASSERT( wxFontEnumerator::IsValidFacename(font.GetFaceName()) );
|
||||
}
|
||||
}
|
||||
|
||||
void SettingsTestCase::GlobalColours()
|
||||
{
|
||||
wxColour col[] =
|
||||
{
|
||||
*wxBLACK,
|
||||
*wxBLUE,
|
||||
*wxCYAN,
|
||||
*wxGREEN,
|
||||
*wxLIGHT_GREY,
|
||||
*wxRED,
|
||||
*wxWHITE
|
||||
};
|
||||
|
||||
for (unsigned int i=0; i < WXSIZEOF(col); i++)
|
||||
CPPUNIT_ASSERT( col[i].IsOk() );
|
||||
}
|
||||
|
||||
void SettingsTestCase::GlobalFonts()
|
||||
{
|
||||
const wxFont font[] =
|
||||
{
|
||||
*wxNORMAL_FONT,
|
||||
*wxSMALL_FONT,
|
||||
*wxITALIC_FONT,
|
||||
*wxSWISS_FONT
|
||||
};
|
||||
|
||||
for (unsigned int i=0; i < WXSIZEOF(font); i++)
|
||||
{
|
||||
CPPUNIT_ASSERT( font[i].IsOk() );
|
||||
|
||||
const wxString facename = font[i].GetFaceName();
|
||||
if ( !facename.empty() )
|
||||
{
|
||||
WX_ASSERT_MESSAGE(
|
||||
("font #%u: facename \"%s\" is invalid", i, facename),
|
||||
wxFontEnumerator::IsValidFacename(facename)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SettingsTestCase::GlobalBrushes()
|
||||
{
|
||||
wxBrush brush[] =
|
||||
{
|
||||
*wxBLACK_BRUSH,
|
||||
*wxBLUE_BRUSH,
|
||||
*wxCYAN_BRUSH,
|
||||
*wxGREEN_BRUSH,
|
||||
*wxGREY_BRUSH,
|
||||
*wxLIGHT_GREY_BRUSH,
|
||||
*wxMEDIUM_GREY_BRUSH,
|
||||
*wxRED_BRUSH,
|
||||
*wxTRANSPARENT_BRUSH,
|
||||
*wxWHITE_BRUSH
|
||||
};
|
||||
|
||||
for (unsigned int i=0; i < WXSIZEOF(brush); i++)
|
||||
CPPUNIT_ASSERT( brush[i].IsOk() );
|
||||
}
|
||||
|
||||
void SettingsTestCase::GlobalPens()
|
||||
{
|
||||
wxPen pen[] =
|
||||
{
|
||||
*wxBLACK_DASHED_PEN,
|
||||
*wxBLACK_PEN,
|
||||
*wxBLUE_PEN,
|
||||
*wxCYAN_PEN,
|
||||
*wxGREEN_PEN,
|
||||
*wxGREY_PEN,
|
||||
*wxLIGHT_GREY_PEN,
|
||||
*wxMEDIUM_GREY_PEN,
|
||||
*wxRED_PEN,
|
||||
*wxTRANSPARENT_PEN,
|
||||
*wxWHITE_PEN
|
||||
};
|
||||
|
||||
for (unsigned int i=0; i < WXSIZEOF(pen); i++)
|
||||
CPPUNIT_ASSERT( pen[i].IsOk() );
|
||||
}
|
||||
169
libs/wxWidgets-3.3.1/tests/misc/textwrap.cpp
Normal file
169
libs/wxWidgets-3.3.1/tests/misc/textwrap.cpp
Normal file
@@ -0,0 +1,169 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: tests/misc/textwrap.cpp
|
||||
// Purpose: wxTextWrapper unit test
|
||||
// Author: Vadim Zeitlin
|
||||
// Created: 2025-01-19
|
||||
// Copyright: (c) 2025 Vadim Zeitlin
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#include "testprec.h"
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/app.h"
|
||||
#endif // !PCH
|
||||
|
||||
#include "wx/textwrapper.h"
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wrapper implementation for testing
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
class HardBreakWrapper : public wxTextWrapper
|
||||
{
|
||||
public:
|
||||
HardBreakWrapper() = default;
|
||||
|
||||
// Return the window used for wrapping: for now, use the main frame because
|
||||
// it doesn't really matter which one we use.
|
||||
wxWindow* GetWindow() const
|
||||
{
|
||||
return wxTheApp->GetTopWindow();
|
||||
}
|
||||
|
||||
// Helper function returning the width of the given text.
|
||||
int GetExtent(const wxString& text) const
|
||||
{
|
||||
return GetWindow()->GetTextExtent(text).x;
|
||||
}
|
||||
|
||||
// Wrap and return the number of lines in the wrapped text.
|
||||
size_t Do(const wxString& text, int width)
|
||||
{
|
||||
Wrap(GetWindow(), text, width);
|
||||
|
||||
return m_lines.size();
|
||||
}
|
||||
|
||||
const wxString& GetLine(size_t n) const
|
||||
{
|
||||
REQUIRE( n < m_lines.size() );
|
||||
|
||||
return m_lines[n];
|
||||
}
|
||||
|
||||
wxString GetResult() const { return wxJoin(m_lines, '\n'); }
|
||||
|
||||
protected:
|
||||
void OnOutputLine(const wxString& line) override { m_lines.push_back(line); }
|
||||
|
||||
private:
|
||||
wxArrayString m_lines;
|
||||
};
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// the tests
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
TEST_CASE("wxTextWrapper::Wrap", "[text]")
|
||||
{
|
||||
// Note that this text shouldn't contain line breaks.
|
||||
const wxString text =
|
||||
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, "
|
||||
"sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
|
||||
;
|
||||
|
||||
HardBreakWrapper w;
|
||||
|
||||
// Check that not wrapping the text works.
|
||||
SECTION("None")
|
||||
{
|
||||
REQUIRE( w.Do(text, -1) == 1 );
|
||||
CHECK( w.GetLine(0) == text );
|
||||
}
|
||||
|
||||
SECTION("Wide")
|
||||
{
|
||||
REQUIRE( w.Do(text, 200*w.GetExtent("x")) == 1 );
|
||||
CHECK( w.GetLine(0) == text );
|
||||
}
|
||||
|
||||
// Check that wrapping the text using reasonable width works.
|
||||
SECTION("Normal")
|
||||
{
|
||||
const auto n = w.Do(text, 40*w.GetExtent("x"));
|
||||
INFO("Wrapped text:\n" << w.GetResult() << "\n");
|
||||
CHECK( n >= 3 );
|
||||
}
|
||||
|
||||
SECTION("Narrow")
|
||||
{
|
||||
const auto n = w.Do(text, w.GetExtent("Lorum ipsum dolor"));
|
||||
INFO("Wrapped text:\n" << w.GetResult() << "\n");
|
||||
CHECK( n >= 8 );
|
||||
CHECK( w.GetLine(0) == "Lorem ipsum dolor" );
|
||||
}
|
||||
|
||||
// Make the window too narrow to fit the word "consectetur" and check that
|
||||
// the text is still wrapped reasonableness well.
|
||||
SECTION("Thin")
|
||||
{
|
||||
const auto n = w.Do(text, w.GetExtent("Lorum"));
|
||||
INFO("Wrapped text:\n" << w.GetResult() << "\n");
|
||||
CHECK( n > 10 );
|
||||
CHECK( w.GetLine(0) == "Lorem" );
|
||||
|
||||
// There should be just one line with the word "consectetur", longer
|
||||
// than the wrap width.
|
||||
bool found = false;
|
||||
for ( size_t i = 1; i < n; ++i )
|
||||
{
|
||||
if ( w.GetLine(i) == "consectetur" )
|
||||
{
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
CHECK( found );
|
||||
}
|
||||
|
||||
// Make the window too narrow to fit even a single character so that
|
||||
// wrapped text has one word per line.
|
||||
SECTION("Narrowest")
|
||||
{
|
||||
const auto n = w.Do(text, 1);
|
||||
INFO("Wrapped text:\n" << w.GetResult() << "\n");
|
||||
REQUIRE( n == static_cast<size_t>(text.Freq(' ')) + 1 );
|
||||
CHECK( w.GetLine(0) == "Lorem" );
|
||||
CHECK( w.GetLine(5) == "consectetur" );
|
||||
}
|
||||
}
|
||||
|
||||
// This pseudo test is disabled by default as it requires the environment
|
||||
// variables WX_TEST_TEXT_WRAP WX_TEST_TEXT_WIDTH to be defined to test how the
|
||||
// given text is wrapped.
|
||||
TEST_CASE("wxTextWrapper::Manual", "[.]")
|
||||
{
|
||||
wxString text;
|
||||
REQUIRE( wxGetEnv("WX_TEST_TEXT_WRAP", &text) );
|
||||
|
||||
wxString widthStr;
|
||||
REQUIRE( wxGetEnv("WX_TEST_TEXT_WIDTH", &widthStr) );
|
||||
|
||||
int width;
|
||||
REQUIRE( widthStr.ToInt(&width) );
|
||||
|
||||
HardBreakWrapper w;
|
||||
const size_t n = w.Do(text, width);
|
||||
WARN("Text wrapped at " << width << " takes " << n << " lines:\n\n"
|
||||
<< w.GetResult() << "\n");
|
||||
}
|
||||
87
libs/wxWidgets-3.3.1/tests/misc/typeinfotest.cpp
Normal file
87
libs/wxWidgets-3.3.1/tests/misc/typeinfotest.cpp
Normal file
@@ -0,0 +1,87 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: tests/misc/typeinfotest.cpp
|
||||
// Purpose: Test typeinfo.h
|
||||
// Author: Jaakko Salli
|
||||
// Copyright: (c) the wxWidgets team
|
||||
// Licence: wxWindows licence
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "testprec.h"
|
||||
|
||||
#include "wx/typeinfo.h"
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// test class
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class TypeInfoTestCase : public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
TypeInfoTestCase() { }
|
||||
|
||||
private:
|
||||
CPPUNIT_TEST_SUITE( TypeInfoTestCase );
|
||||
CPPUNIT_TEST( Test );
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
void Test();
|
||||
|
||||
wxDECLARE_NO_COPY_CLASS(TypeInfoTestCase);
|
||||
};
|
||||
|
||||
// register in the unnamed registry so that these tests are run by default
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION( TypeInfoTestCase );
|
||||
|
||||
// also include in its own registry so that these tests can be run alone
|
||||
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( TypeInfoTestCase, "TypeInfoTestCase" );
|
||||
|
||||
|
||||
namespace UserNameSpace {
|
||||
class UserType1
|
||||
{
|
||||
WX_DECLARE_TYPEINFO_INLINE(UserType1)
|
||||
public:
|
||||
virtual ~UserType1() { }
|
||||
};
|
||||
}
|
||||
|
||||
class UserType1
|
||||
{
|
||||
WX_DECLARE_TYPEINFO_INLINE(UserType1)
|
||||
public:
|
||||
virtual ~UserType1() { }
|
||||
};
|
||||
|
||||
class UserType2
|
||||
{
|
||||
WX_DECLARE_TYPEINFO(UserType2)
|
||||
public:
|
||||
virtual ~UserType2() { }
|
||||
};
|
||||
|
||||
WX_DEFINE_TYPEINFO(UserType2)
|
||||
|
||||
void TypeInfoTestCase::Test()
|
||||
{
|
||||
UserNameSpace::UserType1 uns_ut1;
|
||||
UserNameSpace::UserType1* uns_ut1_p = new UserNameSpace::UserType1();
|
||||
UserType1 ut1;
|
||||
UserType1* ut1_p = new UserType1();
|
||||
UserType2 ut2;
|
||||
UserType2* ut2_p = new UserType2();
|
||||
|
||||
// These type comparison should match
|
||||
CPPUNIT_ASSERT(wxTypeId(uns_ut1) == wxTypeId(*uns_ut1_p));
|
||||
CPPUNIT_ASSERT(wxTypeId(ut1) == wxTypeId(*ut1_p));
|
||||
CPPUNIT_ASSERT(wxTypeId(ut2) == wxTypeId(*ut2_p));
|
||||
|
||||
// These type comparison should not match
|
||||
CPPUNIT_ASSERT(wxTypeId(uns_ut1) != wxTypeId(ut1));
|
||||
CPPUNIT_ASSERT(wxTypeId(uns_ut1) != wxTypeId(ut2));
|
||||
CPPUNIT_ASSERT(wxTypeId(ut1) != wxTypeId(ut2));
|
||||
|
||||
delete uns_ut1_p;
|
||||
delete ut1_p;
|
||||
delete ut2_p;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user