Merge branch 'wxwidgets.org-tests'
Don't fail CI if wxwidgets.org is not available or behind Cloudflare proxy. See #22350.
This commit is contained in:
commit
5f469f481a
3 changed files with 123 additions and 116 deletions
|
|
@ -31,6 +31,7 @@
|
|||
#include "wx/wfstream.h"
|
||||
#include "wx/clipbrd.h"
|
||||
#include "wx/dataobj.h"
|
||||
#include "wx/scopedptr.h"
|
||||
|
||||
#include "testimage.h"
|
||||
|
||||
|
|
@ -158,62 +159,54 @@ void ImageTestCase::LoadFromFile()
|
|||
{
|
||||
wxImage img;
|
||||
for (unsigned int i=0; i<WXSIZEOF(g_testfiles); i++)
|
||||
CPPUNIT_ASSERT(img.LoadFile(g_testfiles[i].file));
|
||||
CHECK(img.LoadFile(g_testfiles[i].file));
|
||||
}
|
||||
|
||||
void ImageTestCase::LoadFromSocketStream()
|
||||
{
|
||||
if (!IsNetworkAvailable()) // implemented in test.cpp
|
||||
{
|
||||
wxLogWarning("No network connectivity; skipping the "
|
||||
WARN("No network connectivity; skipping the "
|
||||
"ImageTestCase::LoadFromSocketStream test unit.");
|
||||
return;
|
||||
}
|
||||
|
||||
// These URLs use the real IP address of www.wxwidgets.org.
|
||||
struct {
|
||||
const char* url;
|
||||
wxBitmapType type;
|
||||
} testData[] =
|
||||
{
|
||||
{ "http://www.wxwidgets.org/assets/img/header-logo.png", wxBITMAP_TYPE_PNG },
|
||||
{ "http://www.wxwidgets.org/assets/ico/favicon-1.ico", wxBITMAP_TYPE_ICO }
|
||||
{ "http://173.254.92.22/assets/img/header-logo.png", wxBITMAP_TYPE_PNG },
|
||||
{ "http://173.254.92.22/assets/ico/favicon-1.ico", wxBITMAP_TYPE_ICO }
|
||||
};
|
||||
|
||||
for (unsigned int i=0; i<WXSIZEOF(testData); i++)
|
||||
{
|
||||
SECTION(std::string("Testing URL ") + testData[i].url)
|
||||
{
|
||||
wxURL url(testData[i].url);
|
||||
WX_ASSERT_EQUAL_MESSAGE
|
||||
(
|
||||
("Constructing URL \"%s\" failed.", testData[i].url),
|
||||
wxURL_NOERR,
|
||||
url.GetError()
|
||||
);
|
||||
REQUIRE( url.GetError() == wxURL_NOERR );
|
||||
|
||||
wxInputStream *in_stream = url.GetInputStream();
|
||||
WX_ASSERT_MESSAGE
|
||||
(
|
||||
("Opening URL \"%s\" failed.", testData[i].url),
|
||||
in_stream && in_stream->IsOk()
|
||||
);
|
||||
wxScopedPtr<wxInputStream> in_stream(url.GetInputStream());
|
||||
REQUIRE( in_stream );
|
||||
REQUIRE( in_stream->IsOk() );
|
||||
|
||||
wxImage img;
|
||||
|
||||
// NOTE: it's important to inform wxImage about the type of the image being
|
||||
// loaded otherwise it will try to autodetect the format, but that
|
||||
// requires a seekable stream!
|
||||
WX_ASSERT_MESSAGE
|
||||
(
|
||||
("Loading image from \"%s\" failed.", testData[i].url),
|
||||
img.LoadFile(*in_stream, testData[i].type)
|
||||
);
|
||||
|
||||
delete in_stream;
|
||||
CHECK( img.LoadFile(*in_stream, testData[i].type) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ImageTestCase::LoadFromZipStream()
|
||||
{
|
||||
for (unsigned int i=0; i<WXSIZEOF(g_testfiles); i++)
|
||||
{
|
||||
SECTION(std::string("Testing file ") + g_testfiles[i].file)
|
||||
{
|
||||
switch (g_testfiles[i].type)
|
||||
{
|
||||
|
|
@ -233,29 +226,29 @@ void ImageTestCase::LoadFromZipStream()
|
|||
wxMemoryOutputStream memOut;
|
||||
{
|
||||
wxFileInputStream file(g_testfiles[i].file);
|
||||
CPPUNIT_ASSERT(file.IsOk());
|
||||
REQUIRE(file.IsOk());
|
||||
|
||||
wxZlibOutputStream compressFilter(memOut, 5, wxZLIB_GZIP);
|
||||
CPPUNIT_ASSERT(compressFilter.IsOk());
|
||||
REQUIRE(compressFilter.IsOk());
|
||||
|
||||
file.Read(compressFilter);
|
||||
CPPUNIT_ASSERT(file.GetLastError() == wxSTREAM_EOF);
|
||||
REQUIRE(file.GetLastError() == wxSTREAM_EOF);
|
||||
}
|
||||
|
||||
// now fetch the compressed memory to wxImage, decompressing it on the fly; this
|
||||
// allows us to test loading images from non-seekable streams other than socket streams
|
||||
wxMemoryInputStream memIn(memOut);
|
||||
CPPUNIT_ASSERT(memIn.IsOk());
|
||||
REQUIRE(memIn.IsOk());
|
||||
wxZlibInputStream decompressFilter(memIn, wxZLIB_GZIP);
|
||||
CPPUNIT_ASSERT(decompressFilter.IsOk());
|
||||
REQUIRE(decompressFilter.IsOk());
|
||||
|
||||
wxImage img;
|
||||
|
||||
// NOTE: it's important to inform wxImage about the type of the image being
|
||||
// loaded otherwise it will try to autodetect the format, but that
|
||||
// requires a seekable stream!
|
||||
WX_ASSERT_MESSAGE(("Could not load file type '%d' after it was zipped", g_testfiles[i].type),
|
||||
img.LoadFile(decompressFilter, g_testfiles[i].type));
|
||||
CHECK( img.LoadFile(decompressFilter, g_testfiles[i].type) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -872,10 +865,10 @@ void ImageTestCase::SizeImage()
|
|||
void ImageTestCase::CompareLoadedImage()
|
||||
{
|
||||
wxImage expected8("horse.xpm");
|
||||
CPPUNIT_ASSERT( expected8.IsOk() );
|
||||
REQUIRE( expected8.IsOk() );
|
||||
|
||||
wxImage expected24("horse.png");
|
||||
CPPUNIT_ASSERT( expected24.IsOk() );
|
||||
REQUIRE( expected24.IsOk() );
|
||||
|
||||
for (size_t i=0; i<WXSIZEOF(g_testfiles); i++)
|
||||
{
|
||||
|
|
@ -951,10 +944,10 @@ void CompareImage(const wxImageHandler& handler, const wxImage& image,
|
|||
}
|
||||
|
||||
wxMemoryInputStream memIn(memOut);
|
||||
CPPUNIT_ASSERT(memIn.IsOk());
|
||||
REQUIRE(memIn.IsOk());
|
||||
|
||||
wxImage actual(memIn);
|
||||
CPPUNIT_ASSERT(actual.IsOk());
|
||||
REQUIRE(actual.IsOk());
|
||||
|
||||
const wxImage *expected = compareTo ? compareTo : ℑ
|
||||
|
||||
|
|
@ -964,11 +957,11 @@ void CompareImage(const wxImageHandler& handler, const wxImage& image,
|
|||
CHECK_THAT(actual, RGBSameAs(*expected));
|
||||
|
||||
#if wxUSE_PALETTE
|
||||
CPPUNIT_ASSERT(actual.HasPalette()
|
||||
REQUIRE(actual.HasPalette()
|
||||
== (testPalette || type == wxBITMAP_TYPE_XPM));
|
||||
#endif
|
||||
|
||||
CPPUNIT_ASSERT( actual.HasAlpha() == testAlpha);
|
||||
REQUIRE( actual.HasAlpha() == testAlpha);
|
||||
|
||||
if (!testAlpha)
|
||||
{
|
||||
|
|
@ -998,8 +991,8 @@ static void SetAlpha(wxImage *image)
|
|||
void ImageTestCase::CompareSavedImage()
|
||||
{
|
||||
wxImage expected24("horse.png");
|
||||
CPPUNIT_ASSERT( expected24.IsOk() );
|
||||
CPPUNIT_ASSERT( !expected24.HasAlpha() );
|
||||
REQUIRE( expected24.IsOk() );
|
||||
REQUIRE( !expected24.HasAlpha() );
|
||||
|
||||
wxImage expected8 = expected24.ConvertToGreyscale();
|
||||
|
||||
|
|
@ -1037,9 +1030,9 @@ void ImageTestCase::CompareSavedImage()
|
|||
void ImageTestCase::SavePNG()
|
||||
{
|
||||
wxImage expected24("horse.png");
|
||||
CPPUNIT_ASSERT( expected24.IsOk() );
|
||||
REQUIRE( expected24.IsOk() );
|
||||
#if wxUSE_PALETTE
|
||||
CPPUNIT_ASSERT( !expected24.HasPalette() );
|
||||
REQUIRE( !expected24.HasPalette() );
|
||||
#endif // #if wxUSE_PALETTE
|
||||
|
||||
wxImage expected8 = expected24.ConvertToGreyscale();
|
||||
|
|
@ -1058,9 +1051,9 @@ void ImageTestCase::SavePNG()
|
|||
expected8, wxIMAGE_HAVE_PALETTE);
|
||||
|
||||
|
||||
CPPUNIT_ASSERT( expected8.LoadFile("horse.gif") );
|
||||
REQUIRE( expected8.LoadFile("horse.gif") );
|
||||
#if wxUSE_PALETTE
|
||||
CPPUNIT_ASSERT( expected8.HasPalette() );
|
||||
REQUIRE( expected8.HasPalette() );
|
||||
#endif // #if wxUSE_PALETTE
|
||||
|
||||
CompareImage(*wxImage::FindHandler(wxBITMAP_TYPE_PNG),
|
||||
|
|
@ -1119,18 +1112,18 @@ static void TestTIFFImage(const wxString& option, int value,
|
|||
{
|
||||
(void) image.LoadFile("horse.png");
|
||||
}
|
||||
CPPUNIT_ASSERT( image.IsOk() );
|
||||
REQUIRE( image.IsOk() );
|
||||
|
||||
wxMemoryOutputStream memOut;
|
||||
image.SetOption(option, value);
|
||||
|
||||
CPPUNIT_ASSERT(image.SaveFile(memOut, wxBITMAP_TYPE_TIFF));
|
||||
REQUIRE(image.SaveFile(memOut, wxBITMAP_TYPE_TIFF));
|
||||
|
||||
wxMemoryInputStream memIn(memOut);
|
||||
CPPUNIT_ASSERT(memIn.IsOk());
|
||||
REQUIRE(memIn.IsOk());
|
||||
|
||||
wxImage savedImage(memIn);
|
||||
CPPUNIT_ASSERT(savedImage.IsOk());
|
||||
REQUIRE(savedImage.IsOk());
|
||||
|
||||
WX_ASSERT_EQUAL_MESSAGE(("While checking for option %s", option),
|
||||
true, savedImage.HasOption(option));
|
||||
|
|
@ -1149,7 +1142,7 @@ void ImageTestCase::SaveTIFF()
|
|||
TestTIFFImage(wxIMAGE_OPTION_TIFF_PHOTOMETRIC, 1/*PHOTOMETRIC_MINISBLACK*/);
|
||||
|
||||
wxImage alphaImage("horse.png");
|
||||
CPPUNIT_ASSERT( alphaImage.IsOk() );
|
||||
REQUIRE( alphaImage.IsOk() );
|
||||
SetAlpha(&alphaImage);
|
||||
|
||||
// RGB with alpha
|
||||
|
|
@ -1186,10 +1179,10 @@ void ImageTestCase::ReadCorruptedTGA()
|
|||
};
|
||||
|
||||
wxMemoryInputStream memIn(corruptTGA, WXSIZEOF(corruptTGA));
|
||||
CPPUNIT_ASSERT(memIn.IsOk());
|
||||
REQUIRE(memIn.IsOk());
|
||||
|
||||
wxImage tgaImage;
|
||||
CPPUNIT_ASSERT( !tgaImage.LoadFile(memIn) );
|
||||
REQUIRE( !tgaImage.LoadFile(memIn) );
|
||||
|
||||
|
||||
/*
|
||||
|
|
@ -1197,7 +1190,7 @@ void ImageTestCase::ReadCorruptedTGA()
|
|||
follow 127+1 uncompressed pixels (while we only should have 1 in total).
|
||||
*/
|
||||
corruptTGA[18] = 0x7f;
|
||||
CPPUNIT_ASSERT( !tgaImage.LoadFile(memIn) );
|
||||
REQUIRE( !tgaImage.LoadFile(memIn) );
|
||||
}
|
||||
|
||||
#if wxUSE_GIF
|
||||
|
|
@ -1206,7 +1199,7 @@ void ImageTestCase::SaveAnimatedGIF()
|
|||
{
|
||||
#if wxUSE_PALETTE
|
||||
wxImage image("horse.gif");
|
||||
CPPUNIT_ASSERT( image.IsOk() );
|
||||
REQUIRE( image.IsOk() );
|
||||
|
||||
wxImageArray images;
|
||||
images.Add(image);
|
||||
|
|
@ -1218,18 +1211,18 @@ void ImageTestCase::SaveAnimatedGIF()
|
|||
}
|
||||
|
||||
wxMemoryOutputStream memOut;
|
||||
CPPUNIT_ASSERT( wxGIFHandler().SaveAnimation(images, &memOut) );
|
||||
REQUIRE( wxGIFHandler().SaveAnimation(images, &memOut) );
|
||||
|
||||
wxGIFHandler handler;
|
||||
wxMemoryInputStream memIn(memOut);
|
||||
CPPUNIT_ASSERT(memIn.IsOk());
|
||||
REQUIRE(memIn.IsOk());
|
||||
const int imageCount = handler.GetImageCount(memIn);
|
||||
CPPUNIT_ASSERT_EQUAL(4, imageCount);
|
||||
CHECK( imageCount == 4 );
|
||||
|
||||
for (int i = 0; i < imageCount; ++i)
|
||||
{
|
||||
wxFileOffset pos = memIn.TellI();
|
||||
CPPUNIT_ASSERT( handler.LoadFile(&image, memIn, true, i) );
|
||||
REQUIRE( handler.LoadFile(&image, memIn, true, i) );
|
||||
memIn.SeekI(pos);
|
||||
|
||||
wxINFO_FMT("Compare test for GIF frame number %d failed", i);
|
||||
|
|
@ -1244,21 +1237,20 @@ static void TestGIFComment(const wxString& comment)
|
|||
|
||||
image.SetOption(wxIMAGE_OPTION_GIF_COMMENT, comment);
|
||||
wxMemoryOutputStream memOut;
|
||||
CPPUNIT_ASSERT(image.SaveFile(memOut, wxBITMAP_TYPE_GIF));
|
||||
REQUIRE(image.SaveFile(memOut, wxBITMAP_TYPE_GIF));
|
||||
|
||||
wxMemoryInputStream memIn(memOut);
|
||||
CPPUNIT_ASSERT( image.LoadFile(memIn) );
|
||||
REQUIRE( image.LoadFile(memIn) );
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL(comment,
|
||||
image.GetOption(wxIMAGE_OPTION_GIF_COMMENT));
|
||||
CHECK( image.GetOption(wxIMAGE_OPTION_GIF_COMMENT) == comment );
|
||||
}
|
||||
|
||||
void ImageTestCase::GIFComment()
|
||||
{
|
||||
// Test reading a comment.
|
||||
wxImage image("horse.gif");
|
||||
CPPUNIT_ASSERT_EQUAL(" Imported from GRADATION image: gray",
|
||||
image.GetOption(wxIMAGE_OPTION_GIF_COMMENT));
|
||||
CHECK( image.GetOption(wxIMAGE_OPTION_GIF_COMMENT) ==
|
||||
" Imported from GRADATION image: gray" );
|
||||
|
||||
|
||||
// Test writing a comment and reading it back.
|
||||
|
|
@ -1272,7 +1264,7 @@ void ImageTestCase::GIFComment()
|
|||
|
||||
|
||||
// Test writing comments in an animated GIF and reading them back.
|
||||
CPPUNIT_ASSERT( image.LoadFile("horse.gif") );
|
||||
REQUIRE( image.LoadFile("horse.gif") );
|
||||
|
||||
#if wxUSE_PALETTE
|
||||
wxImageArray images;
|
||||
|
|
@ -1296,20 +1288,19 @@ void ImageTestCase::GIFComment()
|
|||
|
||||
|
||||
wxMemoryOutputStream memOut;
|
||||
CPPUNIT_ASSERT( wxGIFHandler().SaveAnimation(images, &memOut) );
|
||||
REQUIRE( wxGIFHandler().SaveAnimation(images, &memOut) );
|
||||
|
||||
wxGIFHandler handler;
|
||||
wxMemoryInputStream memIn(memOut);
|
||||
CPPUNIT_ASSERT(memIn.IsOk());
|
||||
REQUIRE(memIn.IsOk());
|
||||
const int imageCount = handler.GetImageCount(memIn);
|
||||
for (i = 0; i < imageCount; ++i)
|
||||
{
|
||||
wxFileOffset pos = memIn.TellI();
|
||||
CPPUNIT_ASSERT( handler.LoadFile(&image, memIn, true /*verbose?*/, i) );
|
||||
REQUIRE( handler.LoadFile(&image, memIn, true /*verbose?*/, i) );
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL(
|
||||
wxString::Format("GIF comment for frame #%d", i+1),
|
||||
image.GetOption(wxIMAGE_OPTION_GIF_COMMENT));
|
||||
CHECK( image.GetOption(wxIMAGE_OPTION_GIF_COMMENT) ==
|
||||
wxString::Format("GIF comment for frame #%d", i+1) );
|
||||
memIn.SeekI(pos);
|
||||
}
|
||||
#endif //wxUSE_PALETTE
|
||||
|
|
@ -1326,21 +1317,21 @@ void ImageTestCase::DibPadding()
|
|||
an ICO). Test for it here.
|
||||
*/
|
||||
wxImage image("horse.gif");
|
||||
CPPUNIT_ASSERT( image.IsOk() );
|
||||
REQUIRE( image.IsOk() );
|
||||
|
||||
image = image.Scale(99, 99);
|
||||
|
||||
wxMemoryOutputStream memOut;
|
||||
CPPUNIT_ASSERT( image.SaveFile(memOut, wxBITMAP_TYPE_ICO) );
|
||||
REQUIRE( image.SaveFile(memOut, wxBITMAP_TYPE_ICO) );
|
||||
}
|
||||
|
||||
static void CompareBMPImage(const wxString& file1, const wxString& file2)
|
||||
{
|
||||
wxImage image1(file1);
|
||||
CPPUNIT_ASSERT( image1.IsOk() );
|
||||
REQUIRE( image1.IsOk() );
|
||||
|
||||
wxImage image2(file2);
|
||||
CPPUNIT_ASSERT( image2.IsOk() );
|
||||
REQUIRE( image2.IsOk() );
|
||||
|
||||
CompareImage(*wxImage::FindHandler(wxBITMAP_TYPE_BMP), image1, 0, &image2);
|
||||
}
|
||||
|
|
@ -1394,7 +1385,8 @@ FindMaxChannelDiff(const wxImage& i1, const wxImage& i2)
|
|||
#define ASSERT_IMAGE_EQUAL_TO_FILE(image, file) \
|
||||
if ( 0 ) \
|
||||
{ \
|
||||
CPPUNIT_ASSERT_MESSAGE( "Failed to save " file, image.SaveFile(file) ); \
|
||||
INFO("Failed to save \"" << file << "\""); \
|
||||
CHECK( image.SaveFile(file) ); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
|
|
@ -1413,7 +1405,7 @@ FindMaxChannelDiff(const wxImage& i1, const wxImage& i2)
|
|||
void ImageTestCase::ScaleCompare()
|
||||
{
|
||||
wxImage original;
|
||||
CPPUNIT_ASSERT(original.LoadFile("horse.bmp"));
|
||||
REQUIRE(original.LoadFile("horse.bmp"));
|
||||
|
||||
ASSERT_IMAGE_EQUAL_TO_FILE(original.Scale( 50, 50, wxIMAGE_QUALITY_BICUBIC),
|
||||
"image/horse_bicubic_50x50.png");
|
||||
|
|
|
|||
|
|
@ -428,7 +428,7 @@ extern void SetProcessEventFunc(ProcessEventFunc func)
|
|||
wxGetApp().SetProcessEventFunc(func);
|
||||
}
|
||||
|
||||
extern bool IsNetworkAvailable()
|
||||
static bool DoCheckConnection()
|
||||
{
|
||||
// NOTE: we could use wxDialUpManager here if it was in wxNet; since it's in
|
||||
// wxCore we use a simple rough test:
|
||||
|
|
@ -436,21 +436,35 @@ extern bool IsNetworkAvailable()
|
|||
wxSocketBase::Initialize();
|
||||
|
||||
wxIPV4address addr;
|
||||
if (!addr.Hostname(wxASCII_STR("www.google.com")) || !addr.Service(wxASCII_STR("www")))
|
||||
if (!addr.Hostname(0xadfe5c16) || !addr.Service(wxASCII_STR("www")))
|
||||
{
|
||||
wxSocketBase::Shutdown();
|
||||
return false;
|
||||
}
|
||||
|
||||
const char* const
|
||||
HTTP_GET = "GET / HTTP /1.1\r\nHost: www.wxwidgets.org\r\n\r\n";
|
||||
|
||||
wxSocketClient sock;
|
||||
sock.SetTimeout(10); // 10 secs
|
||||
bool online = sock.Connect(addr);
|
||||
bool online = sock.Connect(addr) &&
|
||||
(sock.Write(HTTP_GET, strlen(HTTP_GET)), sock.WaitForRead(1));
|
||||
|
||||
wxSocketBase::Shutdown();
|
||||
|
||||
return online;
|
||||
}
|
||||
|
||||
extern bool IsNetworkAvailable()
|
||||
{
|
||||
static int s_isNetworkAvailable = -1;
|
||||
|
||||
if ( s_isNetworkAvailable == -1 )
|
||||
s_isNetworkAvailable = DoCheckConnection();
|
||||
|
||||
return s_isNetworkAvailable == 1;
|
||||
}
|
||||
|
||||
extern bool IsAutomaticTest()
|
||||
{
|
||||
static int s_isAutomatic = -1;
|
||||
|
|
|
|||
|
|
@ -65,11 +65,12 @@ void URLTestCase::GetInputStream()
|
|||
{
|
||||
if (!IsNetworkAvailable()) // implemented in test.cpp
|
||||
{
|
||||
wxLogWarning("No network connectivity; skipping the URLTestCase::GetInputStream test unit.");
|
||||
WARN("No network connectivity; skipping the URLTestCase::GetInputStream test unit.");
|
||||
return;
|
||||
}
|
||||
|
||||
wxURL url("http://www.wxwidgets.org/assets/img/header-logo.png");
|
||||
// This is the IP address of the real www.wxwidgets.org server.
|
||||
wxURL url("http://173.254.92.22/assets/img/header-logo.png");
|
||||
CPPUNIT_ASSERT_EQUAL(wxURL_NOERR, url.GetError());
|
||||
|
||||
wxScopedPtr<wxInputStream> in_stream(url.GetInputStream());
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue