Add support for id ranges to XRC.
Allow to declare ranges of consecutive IDs in XRC by using the "id[n]" syntax. Show this functionality in the xrc sample and test it in the new unit test. Also show and test the "object reference" XRC functionality. Closes #11431. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@66059 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -207,7 +207,8 @@ TEST_GUI_OBJECTS = \
|
||||
test_gui_socket.o \
|
||||
test_gui_boxsizer.o \
|
||||
test_gui_clientsize.o \
|
||||
test_gui_setsize.o
|
||||
test_gui_setsize.o \
|
||||
test_gui_xrctest.o
|
||||
TEST_GUI_ODEP = $(_____pch_testprec_test_gui_testprec_h_gch___depname)
|
||||
|
||||
### Conditionally set variables: ###
|
||||
@@ -843,6 +844,9 @@ test_gui_clientsize.o: $(srcdir)/window/clientsize.cpp $(TEST_GUI_ODEP)
|
||||
test_gui_setsize.o: $(srcdir)/window/setsize.cpp $(TEST_GUI_ODEP)
|
||||
$(CXXC) -c -o $@ $(TEST_GUI_CXXFLAGS) $(srcdir)/window/setsize.cpp
|
||||
|
||||
test_gui_xrctest.o: $(srcdir)/xml/xrctest.cpp $(TEST_GUI_ODEP)
|
||||
$(CXXC) -c -o $@ $(TEST_GUI_CXXFLAGS) $(srcdir)/xml/xrctest.cpp
|
||||
|
||||
|
||||
# notice the ugly hack with using CXXWARNINGS: we can't use CPPFLAGS as
|
||||
# currently the value in the makefile would be ignored if we did, but
|
||||
|
@@ -192,7 +192,8 @@ TEST_GUI_OBJECTS = \
|
||||
$(OBJS)\test_gui_socket.obj \
|
||||
$(OBJS)\test_gui_boxsizer.obj \
|
||||
$(OBJS)\test_gui_clientsize.obj \
|
||||
$(OBJS)\test_gui_setsize.obj
|
||||
$(OBJS)\test_gui_setsize.obj \
|
||||
$(OBJS)\test_gui_xrctest.obj
|
||||
|
||||
### Conditionally set variables: ###
|
||||
|
||||
@@ -889,3 +890,5 @@ $(OBJS)\test_gui_clientsize.obj: .\window\clientsize.cpp
|
||||
$(OBJS)\test_gui_setsize.obj: .\window\setsize.cpp
|
||||
$(CXX) -q -c -P -o$@ $(TEST_GUI_CXXFLAGS) .\window\setsize.cpp
|
||||
|
||||
$(OBJS)\test_gui_xrctest.obj: .\xml\xrctest.cpp
|
||||
$(CXX) -q -c -P -o$@ $(TEST_GUI_CXXFLAGS) .\xml\xrctest.cpp
|
||||
|
@@ -185,7 +185,8 @@ TEST_GUI_OBJECTS = \
|
||||
$(OBJS)\test_gui_socket.o \
|
||||
$(OBJS)\test_gui_boxsizer.o \
|
||||
$(OBJS)\test_gui_clientsize.o \
|
||||
$(OBJS)\test_gui_setsize.o
|
||||
$(OBJS)\test_gui_setsize.o \
|
||||
$(OBJS)\test_gui_xrctest.o
|
||||
|
||||
### Conditionally set variables: ###
|
||||
|
||||
@@ -870,6 +871,9 @@ $(OBJS)\test_gui_clientsize.o: ./window/clientsize.cpp
|
||||
$(OBJS)\test_gui_setsize.o: ./window/setsize.cpp
|
||||
$(CXX) -c -o $@ $(TEST_GUI_CXXFLAGS) $(CPPDEPS) $<
|
||||
|
||||
$(OBJS)\test_gui_xrctest.o: ./xml/xrctest.cpp
|
||||
$(CXX) -c -o $@ $(TEST_GUI_CXXFLAGS) $(CPPDEPS) $<
|
||||
|
||||
.PHONY: all clean data fr
|
||||
|
||||
|
||||
|
@@ -187,7 +187,8 @@ TEST_GUI_OBJECTS = \
|
||||
$(OBJS)\test_gui_socket.obj \
|
||||
$(OBJS)\test_gui_boxsizer.obj \
|
||||
$(OBJS)\test_gui_clientsize.obj \
|
||||
$(OBJS)\test_gui_setsize.obj
|
||||
$(OBJS)\test_gui_setsize.obj \
|
||||
$(OBJS)\test_gui_xrctest.obj
|
||||
TEST_GUI_RESOURCES = \
|
||||
$(OBJS)\test_gui_sample.res
|
||||
|
||||
@@ -1015,3 +1016,5 @@ $(OBJS)\test_gui_clientsize.obj: .\window\clientsize.cpp
|
||||
$(OBJS)\test_gui_setsize.obj: .\window\setsize.cpp
|
||||
$(CXX) /c /nologo /TP /Fo$@ $(TEST_GUI_CXXFLAGS) .\window\setsize.cpp
|
||||
|
||||
$(OBJS)\test_gui_xrctest.obj: .\xml\xrctest.cpp
|
||||
$(CXX) /c /nologo /TP /Fo$@ $(TEST_GUI_CXXFLAGS) .\xml\xrctest.cpp
|
||||
|
@@ -427,7 +427,8 @@ TEST_GUI_OBJECTS = &
|
||||
$(OBJS)\test_gui_socket.obj &
|
||||
$(OBJS)\test_gui_boxsizer.obj &
|
||||
$(OBJS)\test_gui_clientsize.obj &
|
||||
$(OBJS)\test_gui_setsize.obj
|
||||
$(OBJS)\test_gui_setsize.obj &
|
||||
$(OBJS)\test_gui_xrctest.obj
|
||||
|
||||
|
||||
all : $(OBJS)
|
||||
@@ -928,3 +929,5 @@ $(OBJS)\test_gui_clientsize.obj : .AUTODEPEND .\window\clientsize.cpp
|
||||
$(OBJS)\test_gui_setsize.obj : .AUTODEPEND .\window\setsize.cpp
|
||||
$(CXX) -bt=nt -zq -fo=$^@ $(TEST_GUI_CXXFLAGS) $<
|
||||
|
||||
$(OBJS)\test_gui_xrctest.obj : .AUTODEPEND .\xml\xrctest.cpp
|
||||
$(CXX) -bt=nt -zq -fo=$^@ $(TEST_GUI_CXXFLAGS) $<
|
||||
|
@@ -194,6 +194,7 @@
|
||||
sizers/boxsizer.cpp
|
||||
window/clientsize.cpp
|
||||
window/setsize.cpp
|
||||
xml/xrctest.cpp
|
||||
</sources>
|
||||
<wx-lib>richtext</wx-lib>
|
||||
<wx-lib>media</wx-lib>
|
||||
|
@@ -499,6 +499,10 @@ SOURCE=.\controls\treectrltest.cpp
|
||||
|
||||
SOURCE=.\controls\windowtest.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\xml\xrctest.cpp
|
||||
# End Source File
|
||||
# End Group
|
||||
# End Target
|
||||
# End Project
|
||||
|
@@ -808,6 +808,9 @@
|
||||
<File
|
||||
RelativePath=".\controls\windowtest.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\xml\xrctest.cpp">
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Resource Files"
|
||||
|
@@ -1151,6 +1151,10 @@
|
||||
RelativePath=".\controls\windowtest.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\xml\xrctest.cpp"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Resource Files"
|
||||
|
@@ -1123,6 +1123,10 @@
|
||||
RelativePath=".\controls\windowtest.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\xml\xrctest.cpp"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Resource Files"
|
||||
|
229
tests/xml/xrctest.cpp
Normal file
229
tests/xml/xrctest.cpp
Normal file
@@ -0,0 +1,229 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: tests/xml/xrctest.cpp
|
||||
// Purpose: XRC classes unit test
|
||||
// Author: wxWidgets team
|
||||
// Created: 2010-10-30
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) 2010 wxWidgets team
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#include "testprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/wx.h"
|
||||
#endif // WX_PRECOMP
|
||||
|
||||
#include "wx/xml/xml.h"
|
||||
#include "wx/sstream.h"
|
||||
#include "wx/wfstream.h"
|
||||
#include "wx/xrc/xmlres.h"
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// helpers to create/save some xrc
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
static const char *TEST_XRC_FILE = "test.xrc";
|
||||
|
||||
// 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()
|
||||
{
|
||||
const char *xrcText =
|
||||
"<?xml version=\"1.0\" ?>"
|
||||
"<resource>"
|
||||
" <object class=\"wxDialog\" name=\"dialog\">"
|
||||
" <object class=\"wxBoxSizer\">"
|
||||
" <orient>wxVERTICAL</orient>"
|
||||
" <object class=\"sizeritem\">"
|
||||
" <object class=\"wxPanel\" name=\"panel1\">"
|
||||
" <object class=\"wxBoxSizer\">"
|
||||
" <object class=\"sizeritem\">"
|
||||
" <object class=\"wxBoxSizer\">"
|
||||
" <orient>wxVERTICAL</orient>"
|
||||
" <object class=\"sizeritem\">"
|
||||
" <object class=\"wxButton\" name=\"FirstCol[0]\">"
|
||||
" <label>0</label>"
|
||||
" </object>"
|
||||
" </object>"
|
||||
" <object class=\"sizeritem\">"
|
||||
" <object class=\"wxButton\" name=\"FirstCol[1]\">"
|
||||
" <label>1</label>"
|
||||
" </object>"
|
||||
" </object>"
|
||||
" <object class=\"sizeritem\">"
|
||||
" <object class=\"wxButton\" name=\"FirstCol[2]\">"
|
||||
" <label>2</label>"
|
||||
" </object>"
|
||||
" </object>"
|
||||
" <object class=\"sizeritem\">"
|
||||
" <object class=\"wxButton\" name=\"FirstCol[3]\">"
|
||||
" <label>3</label>"
|
||||
" </object>"
|
||||
" </object>"
|
||||
" </object>"
|
||||
" </object>"
|
||||
" <object class=\"sizeritem\">"
|
||||
" <object class=\"wxBoxSizer\">"
|
||||
" <orient>wxVERTICAL</orient>"
|
||||
" <object class=\"sizeritem\">"
|
||||
" <object class=\"wxButton\" name=\"SecondCol[start]\">"
|
||||
" <label>0</label>"
|
||||
" </object>"
|
||||
" </object>"
|
||||
" <object class=\"sizeritem\">"
|
||||
" <object class=\"wxButton\" name=\"SecondCol[1]\">"
|
||||
" <label>1</label>"
|
||||
" </object>"
|
||||
" </object>"
|
||||
" <object class=\"sizeritem\">"
|
||||
" <object class=\"wxButton\" name=\"SecondCol[2]\">"
|
||||
" <label>2</label>"
|
||||
" </object>"
|
||||
" </object>"
|
||||
" <object class=\"sizeritem\">"
|
||||
" <object class=\"wxButton\" name=\"SecondCol[end]\">"
|
||||
" <label>3</label>"
|
||||
" </object>"
|
||||
" </object>"
|
||||
" </object>"
|
||||
" </object>"
|
||||
" <orient>wxHORIZONTAL</orient>"
|
||||
" </object>"
|
||||
" </object>"
|
||||
" </object>"
|
||||
" <object class=\"sizeritem\">"
|
||||
" <object class=\"wxPanel\" name=\"ref_of_panel1\">"
|
||||
" <object_ref ref=\"panel1\"/>"
|
||||
" </object>"
|
||||
" </object>"
|
||||
" </object>"
|
||||
" <title>test</title>"
|
||||
" </object>"
|
||||
" <ids-range name=\"FirstCol\" size=\"2\" start=\"10000\"/>"
|
||||
" <ids-range name=\"SecondCol\" size=\"100\" />"
|
||||
"</resource>"
|
||||
;
|
||||
|
||||
// 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);
|
||||
CPPUNIT_ASSERT(fos.IsOk());
|
||||
fos.Write(sis);
|
||||
CPPUNIT_ASSERT(fos.Close());
|
||||
}
|
||||
|
||||
} // anon namespace
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// test class
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class XrcTestCase : public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
XrcTestCase() {}
|
||||
|
||||
virtual void setUp() { CreateXrc(); }
|
||||
virtual void tearDown() { wxRemoveFile(TEST_XRC_FILE); }
|
||||
|
||||
private:
|
||||
CPPUNIT_TEST_SUITE( XrcTestCase );
|
||||
CPPUNIT_TEST( ObjectReferences );
|
||||
CPPUNIT_TEST( IDRanges );
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
void ObjectReferences();
|
||||
void IDRanges();
|
||||
|
||||
DECLARE_NO_COPY_CLASS(XrcTestCase)
|
||||
};
|
||||
|
||||
// register in the unnamed registry so that these tests are run by default
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION( XrcTestCase );
|
||||
|
||||
// also include in it's own registry so that these tests can be run alone
|
||||
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( XrcTestCase, "XrcTestCase" );
|
||||
|
||||
|
||||
|
||||
void XrcTestCase::ObjectReferences()
|
||||
{
|
||||
wxXmlResource::Get()->InitAllHandlers();
|
||||
|
||||
for ( int n = 0; n < 2; ++n )
|
||||
{
|
||||
// Load the xrc file we're just created
|
||||
CPPUNIT_ASSERT( wxXmlResource::Get()->Load(TEST_XRC_FILE) );
|
||||
|
||||
// In xrc there's now a dialog containing two panels, one an object
|
||||
// reference of the other
|
||||
wxDialog dlg;
|
||||
CPPUNIT_ASSERT( wxXmlResource::Get()->LoadDialog(&dlg, NULL, "dialog") );
|
||||
// Might as well test XRCCTRL too
|
||||
wxPanel* panel1 = XRCCTRL(dlg,"panel1",wxPanel);
|
||||
wxPanel* panel2 = XRCCTRL(dlg,"ref_of_panel1",wxPanel);
|
||||
// Check that the object reference panel is a different object
|
||||
CPPUNIT_ASSERT( panel2 != panel1 );
|
||||
|
||||
// Unload the xrc, so it can be reloaded and the test rerun
|
||||
CPPUNIT_ASSERT( wxXmlResource::Get()->Unload(TEST_XRC_FILE) );
|
||||
}
|
||||
}
|
||||
|
||||
void XrcTestCase::IDRanges()
|
||||
{
|
||||
// Tests ID ranges
|
||||
for ( int n = 0; n < 2; ++n )
|
||||
{
|
||||
// Load the xrc file we're just created
|
||||
CPPUNIT_ASSERT( wxXmlResource::Get()->Load(TEST_XRC_FILE) );
|
||||
|
||||
// foo[start] should == foo[0]
|
||||
CPPUNIT_ASSERT_EQUAL( XRCID("SecondCol[start]"), XRCID("SecondCol[0]") );
|
||||
// foo[start] should be < foo[end]. Usually that means more negative
|
||||
CPPUNIT_ASSERT( XRCID("SecondCol[start]") < XRCID("SecondCol[end]") );
|
||||
// Check it works for the positive values in FirstCol too
|
||||
CPPUNIT_ASSERT( XRCID("FirstCol[start]") < XRCID("FirstCol[end]") );
|
||||
|
||||
// Check that values are adjacent
|
||||
CPPUNIT_ASSERT_EQUAL( XRCID("SecondCol[0]")+1, XRCID("SecondCol[1]") );
|
||||
CPPUNIT_ASSERT_EQUAL( XRCID("SecondCol[1]")+1, XRCID("SecondCol[2]") );
|
||||
// And for the positive range
|
||||
CPPUNIT_ASSERT_EQUAL( XRCID("FirstCol[2]")+1, XRCID("FirstCol[3]") );
|
||||
|
||||
// Check that a large-enough range was created, despite the small
|
||||
// 'size' parameter
|
||||
CPPUNIT_ASSERT_EQUAL
|
||||
(
|
||||
4,
|
||||
XRCID("FirstCol[end]") - XRCID("FirstCol[start]") + 1
|
||||
);
|
||||
|
||||
// Check that the far-too-large size range worked off the scale too
|
||||
CPPUNIT_ASSERT( XRCID("SecondCol[start]") < XRCID("SecondCol[90]") );
|
||||
CPPUNIT_ASSERT( XRCID("SecondCol[90]") < XRCID("SecondCol[end]") );
|
||||
CPPUNIT_ASSERT_EQUAL( XRCID("SecondCol[90]")+1, XRCID("SecondCol[91]") );
|
||||
|
||||
// Check that the positive range-start parameter worked, even after a
|
||||
// reload
|
||||
CPPUNIT_ASSERT_EQUAL( XRCID("FirstCol[start]"), 10000 );
|
||||
|
||||
// Unload the xrc, so it can be reloaded and the tests rerun
|
||||
CPPUNIT_ASSERT( wxXmlResource::Get()->Unload(TEST_XRC_FILE) );
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user