]> git.saurik.com Git - wxWidgets.git/blobdiff - tests/sizers/boxsizer.cpp
Don't ignore child process output if it exits with -1 exit code.
[wxWidgets.git] / tests / sizers / boxsizer.cpp
index ca203d23796cdf2a2a8eb819261213b4847dc64c..118cacf49443bd16cf4e11377451a876ebc18e8f 100644 (file)
 #ifndef WX_PRECOMP
     #include "wx/app.h"
     #include "wx/sizer.h"
+    #include "wx/listbox.h"
 #endif // WX_PRECOMP
 
-inline std::ostream& operator<<(std::ostream& o, const wxSize& s)
-{
-    return o << s.x << 'x' << s.y;
-}
+#include "asserthelper.h"
 
 // ----------------------------------------------------------------------------
 // test class
@@ -44,11 +42,17 @@ private:
         CPPUNIT_TEST( Size1 );
         CPPUNIT_TEST( Size3 );
         CPPUNIT_TEST( CalcMin );
+        CPPUNIT_TEST( BestSizeRespectsMaxSize );
+        CPPUNIT_TEST( RecalcSizesRespectsMaxSize1 );
+        CPPUNIT_TEST( RecalcSizesRespectsMaxSize2 );
     CPPUNIT_TEST_SUITE_END();
 
     void Size1();
     void Size3();
     void CalcMin();
+    void BestSizeRespectsMaxSize();
+    void RecalcSizesRespectsMaxSize1();
+    void RecalcSizesRespectsMaxSize2();
 
     wxWindow *m_win;
     wxSizer *m_sizer;
@@ -59,7 +63,7 @@ private:
 // 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
+// also include in its own registry so that these tests can be run alone
 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( BoxSizerTestCase, "BoxSizerTestCase" );
 
 // ----------------------------------------------------------------------------
@@ -233,7 +237,7 @@ void BoxSizerTestCase::Size3()
                 WX_ASSERT_EQUAL_MESSAGE
                 (
                     (
-                        "test %lu, permutation #%d: wrong size for child #%d "
+                        "test %lu, permutation #%lu: wrong size for child #%d "
                         "for total size %d",
                         static_cast<unsigned long>(i),
                         static_cast<unsigned long>(p),
@@ -301,3 +305,75 @@ void BoxSizerTestCase::CalcMin()
         );
     }
 }
+
+void BoxSizerTestCase::BestSizeRespectsMaxSize()
+{
+    m_sizer->Clear();
+
+    const int maxWidth = 100;
+
+    wxSizer* sizer = new wxBoxSizer(wxVERTICAL);
+    wxListBox* listbox = new wxListBox(m_win, wxID_ANY);
+    listbox->Append("some very very very very very very very very very very very long string");
+    listbox->SetMaxSize(wxSize(maxWidth, -1));
+    sizer->Add(listbox);
+
+    m_sizer->Add(sizer);
+    m_win->Layout();
+
+    CPPUNIT_ASSERT_EQUAL(maxWidth, listbox->GetSize().GetWidth());
+}
+
+void BoxSizerTestCase::RecalcSizesRespectsMaxSize1()
+{
+    m_sizer->Clear();
+
+    const int maxWidth = 100;
+
+    m_win->SetClientSize(300, 300);
+
+    wxSizer* sizer1 = new wxBoxSizer(wxVERTICAL);
+    m_sizer->Add(sizer1);
+
+    wxListBox* listbox1 = new wxListBox(m_win, wxID_ANY);
+    listbox1->Append("some very very very very very very very very very very very long string");
+    sizer1->Add(listbox1);
+
+    wxSizer* sizer2 = new wxBoxSizer(wxHORIZONTAL);
+    sizer1->Add(sizer2, wxSizerFlags().Expand());
+
+    wxListBox* listbox2 = new wxListBox(m_win, wxID_ANY);
+    listbox2->Append("some string");
+    listbox2->SetMaxSize(wxSize(100, -1));
+    sizer2->Add(listbox2, wxSizerFlags().Proportion(1));
+
+    m_win->Layout();
+
+    CPPUNIT_ASSERT_EQUAL(maxWidth, listbox2->GetSize().GetWidth());
+}
+
+void BoxSizerTestCase::RecalcSizesRespectsMaxSize2()
+{
+    m_sizer->Clear();
+
+    m_win->SetClientSize(300, 300);
+
+    wxSizer* sizer1 = new wxBoxSizer(wxVERTICAL);
+    m_sizer->Add(sizer1, wxSizerFlags().Expand());
+
+    wxWindow* child1 = new wxWindow(m_win, wxID_ANY);
+    sizer1->Add(child1, wxSizerFlags().Proportion(1));
+
+    wxWindow* child2 = new wxWindow(m_win, wxID_ANY);
+    child2->SetMaxSize(wxSize(-1, 50));
+    sizer1->Add(child2, wxSizerFlags().Proportion(1));
+
+    wxWindow* child3 = new wxWindow(m_win, wxID_ANY);
+    sizer1->Add(child3, wxSizerFlags().Proportion(1));
+
+    m_win->Layout();
+
+    CPPUNIT_ASSERT_EQUAL(125, child1->GetSize().GetHeight());
+    CPPUNIT_ASSERT_EQUAL(50, child2->GetSize().GetHeight());
+    CPPUNIT_ASSERT_EQUAL(125, child3->GetSize().GetHeight());
+}