diff --git a/tests/xml/xrctest.cpp b/tests/xml/xrctest.cpp index 04e1a435ff..196bd1637a 100644 --- a/tests/xml/xrctest.cpp +++ b/tests/xml/xrctest.cpp @@ -21,6 +21,7 @@ #include "wx/fs_inet.h" #include "wx/xml/xml.h" +#include "wx/scopedptr.h" #include "wx/sstream.h" #include "wx/wfstream.h" #include "wx/xrc/xmlres.h" @@ -36,9 +37,19 @@ namespace static const char *TEST_XRC_FILE = "test.xrc"; +void LoadXrcFrom(const wxString& xrcText) +{ + wxStringInputStream sis(xrcText); + wxScopedPtr xmlDoc(new wxXmlDocument(sis, "UTF-8")); + REQUIRE( xmlDoc->IsOk() ); + + // Load the xrc we've just created + REQUIRE( wxXmlResource::Get()->LoadDocument(xmlDoc.release(), TEST_XRC_FILE) ); +} + // I'm hard-wiring the xrc into this function for now // If different xrcs are wanted for future tests, it'll be easy to refactor -void CreateXrc() +void LoadTestXrc() { const char *xrcText = "" @@ -116,13 +127,7 @@ void CreateXrc() "" ; - // afaict there's no elegant way to load xrc direct from a string - // So save it as a file, from which it can be loaded - wxStringInputStream sis(xrcText); - wxFFileOutputStream fos(TEST_XRC_FILE); - REQUIRE(fos.IsOk()); - fos.Write(sis); - REQUIRE(fos.Close()); + LoadXrcFrom(wxString::FromAscii(xrcText)); } } // anon namespace @@ -135,8 +140,7 @@ void CreateXrc() class XrcTestCase { public: - XrcTestCase() { CreateXrc(); } - ~XrcTestCase() { wxRemoveFile(TEST_XRC_FILE); } + XrcTestCase() { } private: wxDECLARE_NO_COPY_CLASS(XrcTestCase); @@ -148,8 +152,7 @@ TEST_CASE_METHOD(XrcTestCase, "XRC::ObjectReferences", "[xrc]") for ( int n = 0; n < 2; ++n ) { - // Load the xrc file we're just created - REQUIRE( wxXmlResource::Get()->Load(TEST_XRC_FILE) ); + LoadTestXrc(); // In xrc there's now a dialog containing two panels, one an object // reference of the other @@ -171,8 +174,7 @@ TEST_CASE_METHOD(XrcTestCase, "XRC::IDRanges", "[xrc]") // Tests ID ranges for ( int n = 0; n < 2; ++n ) { - // Load the xrc file we're just created - REQUIRE( wxXmlResource::Get()->Load(TEST_XRC_FILE) ); + LoadTestXrc(); // foo[start] should == foo[0] CHECK( XRCID("SecondCol[start]") == XRCID("SecondCol[0]") ); @@ -205,6 +207,19 @@ TEST_CASE_METHOD(XrcTestCase, "XRC::IDRanges", "[xrc]") } } +TEST_CASE("XRC::PathWithFragment", "[xrc][uri]") +{ + LoadXrcFrom + ( + "" + "" + " bitmap#1.png" + "" + ); + + CHECK( wxXmlResource::Get()->LoadBitmap("bitmap").IsOk() ); +} + // This test is disabled by default as it requires the environment variable // below to be defined to point to a HTTP URL with the file to load. //