From: Vadim Zeitlin Date: Thu, 18 Mar 2010 15:07:10 +0000 (+0000) Subject: Add (a very simple for now) wxBoxSizer unit test. X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/869c7a944b2be1a0e35cf2a0df631693a217f9f0 Add (a very simple for now) wxBoxSizer unit test. Only check that layout for a single sizer item works correctly for now. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@63703 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/tests/Makefile.in b/tests/Makefile.in index e951631108..21d0ac5c2b 100644 --- a/tests/Makefile.in +++ b/tests/Makefile.in @@ -156,6 +156,7 @@ TEST_GUI_OBJECTS = \ test_gui_garbage.o \ test_gui_settings.o \ test_gui_socket.o \ + test_gui_boxsizer.o \ test_gui_clientsize.o \ test_gui_setsize.o TEST_GUI_ODEP = $(_____pch_testprec_test_gui_testprec_h_gch___depname) @@ -634,6 +635,9 @@ test_gui_settings.o: $(srcdir)/misc/settings.cpp $(TEST_GUI_ODEP) test_gui_socket.o: $(srcdir)/net/socket.cpp $(TEST_GUI_ODEP) $(CXXC) -c -o $@ $(TEST_GUI_CXXFLAGS) $(srcdir)/net/socket.cpp +test_gui_boxsizer.o: $(srcdir)/sizers/boxsizer.cpp $(TEST_GUI_ODEP) + $(CXXC) -c -o $@ $(TEST_GUI_CXXFLAGS) $(srcdir)/sizers/boxsizer.cpp + test_gui_clientsize.o: $(srcdir)/window/clientsize.cpp $(TEST_GUI_ODEP) $(CXXC) -c -o $@ $(TEST_GUI_CXXFLAGS) $(srcdir)/window/clientsize.cpp diff --git a/tests/makefile.bcc b/tests/makefile.bcc index d1d085adbf..373f224538 100644 --- a/tests/makefile.bcc +++ b/tests/makefile.bcc @@ -141,6 +141,7 @@ TEST_GUI_OBJECTS = \ $(OBJS)\test_gui_garbage.obj \ $(OBJS)\test_gui_settings.obj \ $(OBJS)\test_gui_socket.obj \ + $(OBJS)\test_gui_boxsizer.obj \ $(OBJS)\test_gui_clientsize.obj \ $(OBJS)\test_gui_setsize.obj @@ -688,6 +689,9 @@ $(OBJS)\test_gui_settings.obj: .\misc\settings.cpp $(OBJS)\test_gui_socket.obj: .\net\socket.cpp $(CXX) -q -c -P -o$@ $(TEST_GUI_CXXFLAGS) .\net\socket.cpp +$(OBJS)\test_gui_boxsizer.obj: .\sizers\boxsizer.cpp + $(CXX) -q -c -P -o$@ $(TEST_GUI_CXXFLAGS) .\sizers\boxsizer.cpp + $(OBJS)\test_gui_clientsize.obj: .\window\clientsize.cpp $(CXX) -q -c -P -o$@ $(TEST_GUI_CXXFLAGS) .\window\clientsize.cpp diff --git a/tests/makefile.gcc b/tests/makefile.gcc index 53fffc15f1..1595d84da8 100644 --- a/tests/makefile.gcc +++ b/tests/makefile.gcc @@ -135,6 +135,7 @@ TEST_GUI_OBJECTS = \ $(OBJS)\test_gui_garbage.o \ $(OBJS)\test_gui_settings.o \ $(OBJS)\test_gui_socket.o \ + $(OBJS)\test_gui_boxsizer.o \ $(OBJS)\test_gui_clientsize.o \ $(OBJS)\test_gui_setsize.o @@ -670,6 +671,9 @@ $(OBJS)\test_gui_settings.o: ./misc/settings.cpp $(OBJS)\test_gui_socket.o: ./net/socket.cpp $(CXX) -c -o $@ $(TEST_GUI_CXXFLAGS) $(CPPDEPS) $< +$(OBJS)\test_gui_boxsizer.o: ./sizers/boxsizer.cpp + $(CXX) -c -o $@ $(TEST_GUI_CXXFLAGS) $(CPPDEPS) $< + $(OBJS)\test_gui_clientsize.o: ./window/clientsize.cpp $(CXX) -c -o $@ $(TEST_GUI_CXXFLAGS) $(CPPDEPS) $< diff --git a/tests/makefile.vc b/tests/makefile.vc index 87a97c3c52..04e39ba393 100644 --- a/tests/makefile.vc +++ b/tests/makefile.vc @@ -136,6 +136,7 @@ TEST_GUI_OBJECTS = \ $(OBJS)\test_gui_garbage.obj \ $(OBJS)\test_gui_settings.obj \ $(OBJS)\test_gui_socket.obj \ + $(OBJS)\test_gui_boxsizer.obj \ $(OBJS)\test_gui_clientsize.obj \ $(OBJS)\test_gui_setsize.obj TEST_GUI_RESOURCES = \ @@ -814,6 +815,9 @@ $(OBJS)\test_gui_settings.obj: .\misc\settings.cpp $(OBJS)\test_gui_socket.obj: .\net\socket.cpp $(CXX) /c /nologo /TP /Fo$@ $(TEST_GUI_CXXFLAGS) .\net\socket.cpp +$(OBJS)\test_gui_boxsizer.obj: .\sizers\boxsizer.cpp + $(CXX) /c /nologo /TP /Fo$@ $(TEST_GUI_CXXFLAGS) .\sizers\boxsizer.cpp + $(OBJS)\test_gui_clientsize.obj: .\window\clientsize.cpp $(CXX) /c /nologo /TP /Fo$@ $(TEST_GUI_CXXFLAGS) .\window\clientsize.cpp diff --git a/tests/makefile.wat b/tests/makefile.wat index f43ac68775..f6da0821db 100644 --- a/tests/makefile.wat +++ b/tests/makefile.wat @@ -379,6 +379,7 @@ TEST_GUI_OBJECTS = & $(OBJS)\test_gui_garbage.obj & $(OBJS)\test_gui_settings.obj & $(OBJS)\test_gui_socket.obj & + $(OBJS)\test_gui_boxsizer.obj & $(OBJS)\test_gui_clientsize.obj & $(OBJS)\test_gui_setsize.obj @@ -725,6 +726,9 @@ $(OBJS)\test_gui_settings.obj : .AUTODEPEND .\misc\settings.cpp $(OBJS)\test_gui_socket.obj : .AUTODEPEND .\net\socket.cpp $(CXX) -bt=nt -zq -fo=$^@ $(TEST_GUI_CXXFLAGS) $< +$(OBJS)\test_gui_boxsizer.obj : .AUTODEPEND .\sizers\boxsizer.cpp + $(CXX) -bt=nt -zq -fo=$^@ $(TEST_GUI_CXXFLAGS) $< + $(OBJS)\test_gui_clientsize.obj : .AUTODEPEND .\window\clientsize.cpp $(CXX) -bt=nt -zq -fo=$^@ $(TEST_GUI_CXXFLAGS) $< diff --git a/tests/sizers/boxsizer.cpp b/tests/sizers/boxsizer.cpp new file mode 100644 index 0000000000..e4dbbec1df --- /dev/null +++ b/tests/sizers/boxsizer.cpp @@ -0,0 +1,107 @@ +/////////////////////////////////////////////////////////////////////////////// +// Name: tests/sizers/boxsizer.cpp +// Purpose: Unit tests for wxBoxSizer +// Author: Vadim Zeitlin +// Created: 2010-03-06 +// RCS-ID: $Id$ +// Copyright: (c) 2010 Vadim Zeitlin +/////////////////////////////////////////////////////////////////////////////// + +// ---------------------------------------------------------------------------- +// headers +// ---------------------------------------------------------------------------- + +#include "testprec.h" + +#ifdef __BORLANDC__ + #pragma hdrstop +#endif + +#ifndef WX_PRECOMP + #include "wx/app.h" + #include "wx/sizer.h" +#endif // WX_PRECOMP + +inline std::ostream& operator<<(std::ostream& o, const wxSize& s) +{ + return o << s.x << 'x' << s.y; +} + +// ---------------------------------------------------------------------------- +// test class +// ---------------------------------------------------------------------------- + +class BoxSizerTestCase : public CppUnit::TestCase +{ +public: + BoxSizerTestCase() { } + + virtual void setUp(); + virtual void tearDown(); + +private: + CPPUNIT_TEST_SUITE( BoxSizerTestCase ); + CPPUNIT_TEST( Size1 ); + CPPUNIT_TEST_SUITE_END(); + + void Size1(); + + wxWindow *m_win; + wxSizer *m_sizer; + + DECLARE_NO_COPY_CLASS(BoxSizerTestCase) +}; + +// register in the unnamed registry so that these tests are run by default +CPPUNIT_TEST_SUITE_REGISTRATION( BoxSizerTestCase ); + +// also include in it's own registry so that these tests can be run alone +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( BoxSizerTestCase, "BoxSizerTestCase" ); + +// ---------------------------------------------------------------------------- +// test initialization +// ---------------------------------------------------------------------------- + +void BoxSizerTestCase::setUp() +{ + m_win = new wxWindow(wxTheApp->GetTopWindow(), wxID_ANY); + m_win->SetClientSize(127, 35); + + m_sizer = new wxBoxSizer(wxHORIZONTAL); + m_win->SetSizer(m_sizer); +} + +void BoxSizerTestCase::tearDown() +{ + delete m_win; + m_win = NULL; + + m_sizer = NULL; +} + +// ---------------------------------------------------------------------------- +// tests themselves +// ---------------------------------------------------------------------------- + +void BoxSizerTestCase::Size1() +{ + const wxSize sizeTotal = m_win->GetClientSize(); + const wxSize sizeChild = sizeTotal / 2; + + wxWindow * const + child = new wxWindow(m_win, wxID_ANY, wxDefaultPosition, sizeChild); + m_sizer->Add(child); + m_win->Layout(); + CPPUNIT_ASSERT_EQUAL( sizeChild, child->GetSize() ); +; + m_sizer->Clear(); + m_sizer->Add(child, wxSizerFlags(1)); + m_win->Layout(); + CPPUNIT_ASSERT_EQUAL( wxSize(sizeTotal.x, sizeChild.y), child->GetSize() ); + + m_sizer->Clear(); + m_sizer->Add(child, wxSizerFlags(1).Expand()); + m_win->Layout(); + CPPUNIT_ASSERT_EQUAL( sizeTotal, child->GetSize() ); +} + diff --git a/tests/test.bkl b/tests/test.bkl index 77bc56251c..edb0c7ea8f 100644 --- a/tests/test.bkl +++ b/tests/test.bkl @@ -142,6 +142,7 @@ applications. --> net/socket.cpp + sizers/boxsizer.cpp window/clientsize.cpp window/setsize.cpp diff --git a/tests/test_test_gui.dsp b/tests/test_test_gui.dsp index 55121786eb..bb0d682928 100644 --- a/tests/test_test_gui.dsp +++ b/tests/test_test_gui.dsp @@ -235,6 +235,10 @@ LINK32=link.exe # PROP Default_Filter "" # Begin Source File +SOURCE=.\sizers\boxsizer.cpp +# End Source File +# Begin Source File + SOURCE=.\window\clientsize.cpp # End Source File # Begin Source File diff --git a/tests/test_vc7_test_gui.vcproj b/tests/test_vc7_test_gui.vcproj index 6b0092f821..ae44f24eac 100644 --- a/tests/test_vc7_test_gui.vcproj +++ b/tests/test_vc7_test_gui.vcproj @@ -566,6 +566,9 @@ Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx" UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"> + + + + diff --git a/tests/test_vc9_test_gui.vcproj b/tests/test_vc9_test_gui.vcproj index 941eb998ca..761934ff67 100644 --- a/tests/test_vc9_test_gui.vcproj +++ b/tests/test_vc9_test_gui.vcproj @@ -1,16 +1,10 @@ - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - -