radioboxtest.cpp 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Name: tests/controls/radioboxtest.cpp
  3. // Purpose: wxRadioBox unit test
  4. // Author: Steven Lamerton
  5. // Created: 2010-07-14
  6. // Copyright: (c) 2010 Steven Lamerton
  7. ///////////////////////////////////////////////////////////////////////////////
  8. #include "testprec.h"
  9. #if wxUSE_RADIOBOX
  10. #ifdef __BORLANDC__
  11. #pragma hdrstop
  12. #endif
  13. #ifndef WX_PRECOMP
  14. #include "wx/app.h"
  15. #include "wx/radiobox.h"
  16. #endif // WX_PRECOMP
  17. #include "wx/tooltip.h"
  18. class RadioBoxTestCase : public CppUnit::TestCase
  19. {
  20. public:
  21. RadioBoxTestCase() { }
  22. void setUp();
  23. void tearDown();
  24. private:
  25. CPPUNIT_TEST_SUITE( RadioBoxTestCase );
  26. CPPUNIT_TEST( FindString );
  27. CPPUNIT_TEST( RowColCount );
  28. CPPUNIT_TEST( Enable );
  29. CPPUNIT_TEST( Show );
  30. CPPUNIT_TEST( HelpText );
  31. CPPUNIT_TEST( ToolTip );
  32. CPPUNIT_TEST( Selection );
  33. CPPUNIT_TEST( Count );
  34. CPPUNIT_TEST( SetString );
  35. CPPUNIT_TEST_SUITE_END();
  36. void FindString();
  37. void RowColCount();
  38. void Enable();
  39. void Show();
  40. void HelpText();
  41. void ToolTip();
  42. void Selection();
  43. void Count();
  44. void SetString();
  45. wxRadioBox* m_radio;
  46. DECLARE_NO_COPY_CLASS(RadioBoxTestCase)
  47. };
  48. // register in the unnamed registry so that these tests are run by default
  49. CPPUNIT_TEST_SUITE_REGISTRATION( RadioBoxTestCase );
  50. // also include in its own registry so that these tests can be run alone
  51. CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( RadioBoxTestCase, "RadioBoxTestCase" );
  52. void RadioBoxTestCase::setUp()
  53. {
  54. wxArrayString choices;
  55. choices.push_back("item 0");
  56. choices.push_back("item 1");
  57. choices.push_back("item 2");
  58. m_radio = new wxRadioBox(wxTheApp->GetTopWindow(), wxID_ANY, "RadioBox",
  59. wxDefaultPosition, wxDefaultSize, choices);
  60. }
  61. void RadioBoxTestCase::tearDown()
  62. {
  63. wxTheApp->GetTopWindow()->DestroyChildren();
  64. }
  65. void RadioBoxTestCase::FindString()
  66. {
  67. CPPUNIT_ASSERT_EQUAL(wxNOT_FOUND, m_radio->FindString("not here"));
  68. CPPUNIT_ASSERT_EQUAL(1, m_radio->FindString("item 1"));
  69. CPPUNIT_ASSERT_EQUAL(2, m_radio->FindString("ITEM 2"));
  70. CPPUNIT_ASSERT_EQUAL(wxNOT_FOUND, m_radio->FindString("ITEM 2", true));
  71. }
  72. void RadioBoxTestCase::RowColCount()
  73. {
  74. #ifndef __WXGTK__
  75. wxArrayString choices;
  76. choices.push_back("item 0");
  77. choices.push_back("item 1");
  78. choices.push_back("item 2");
  79. m_radio = new wxRadioBox(wxTheApp->GetTopWindow(), wxID_ANY, "RadioBox",
  80. wxDefaultPosition, wxDefaultSize, choices, 2);
  81. CPPUNIT_ASSERT_EQUAL(2, m_radio->GetColumnCount());
  82. CPPUNIT_ASSERT_EQUAL(2, m_radio->GetRowCount());
  83. m_radio = new wxRadioBox(wxTheApp->GetTopWindow(), wxID_ANY, "RadioBox",
  84. wxDefaultPosition, wxDefaultSize, choices, 1,
  85. wxRA_SPECIFY_ROWS);
  86. CPPUNIT_ASSERT_EQUAL(3, m_radio->GetColumnCount());
  87. CPPUNIT_ASSERT_EQUAL(1, m_radio->GetRowCount());
  88. #endif
  89. }
  90. void RadioBoxTestCase::Enable()
  91. {
  92. #ifndef __WXOSX__
  93. m_radio->Enable(false);
  94. CPPUNIT_ASSERT(!m_radio->IsItemEnabled(0));
  95. m_radio->Enable(1, true);
  96. CPPUNIT_ASSERT(!m_radio->IsItemEnabled(0));
  97. CPPUNIT_ASSERT(m_radio->IsItemEnabled(1));
  98. CPPUNIT_ASSERT(!m_radio->IsItemEnabled(2));
  99. m_radio->Enable(true);
  100. CPPUNIT_ASSERT(m_radio->IsItemEnabled(0));
  101. CPPUNIT_ASSERT(m_radio->IsItemEnabled(1));
  102. CPPUNIT_ASSERT(m_radio->IsItemEnabled(2));
  103. m_radio->Enable(0, false);
  104. CPPUNIT_ASSERT(!m_radio->IsItemEnabled(0));
  105. CPPUNIT_ASSERT(m_radio->IsItemEnabled(1));
  106. CPPUNIT_ASSERT(m_radio->IsItemEnabled(2));
  107. #endif
  108. }
  109. void RadioBoxTestCase::Show()
  110. {
  111. m_radio->Show(false);
  112. CPPUNIT_ASSERT(!m_radio->IsItemShown(0));
  113. m_radio->Show(1, true);
  114. CPPUNIT_ASSERT(!m_radio->IsItemShown(0));
  115. CPPUNIT_ASSERT(m_radio->IsItemShown(1));
  116. CPPUNIT_ASSERT(!m_radio->IsItemShown(2));
  117. m_radio->Show(true);
  118. CPPUNIT_ASSERT(m_radio->IsItemShown(0));
  119. CPPUNIT_ASSERT(m_radio->IsItemShown(1));
  120. CPPUNIT_ASSERT(m_radio->IsItemShown(2));
  121. m_radio->Show(0, false);
  122. CPPUNIT_ASSERT(!m_radio->IsItemShown(0));
  123. CPPUNIT_ASSERT(m_radio->IsItemShown(1));
  124. CPPUNIT_ASSERT(m_radio->IsItemShown(2));
  125. }
  126. void RadioBoxTestCase::HelpText()
  127. {
  128. CPPUNIT_ASSERT_EQUAL(wxEmptyString, m_radio->GetItemHelpText(0));
  129. m_radio->SetItemHelpText(1, "Item 1 help");
  130. CPPUNIT_ASSERT_EQUAL("Item 1 help", m_radio->GetItemHelpText(1));
  131. m_radio->SetItemHelpText(1, "");
  132. CPPUNIT_ASSERT_EQUAL(wxEmptyString, m_radio->GetItemHelpText(1));
  133. }
  134. void RadioBoxTestCase::ToolTip()
  135. {
  136. #if defined (__WXMSW__) || defined(__WXGTK__)
  137. //GetItemToolTip returns null if there is no tooltip set
  138. CPPUNIT_ASSERT(!m_radio->GetItemToolTip(0));
  139. m_radio->SetItemToolTip(1, "Item 1 help");
  140. CPPUNIT_ASSERT_EQUAL("Item 1 help", m_radio->GetItemToolTip(1)->GetTip());
  141. m_radio->SetItemToolTip(1, "");
  142. //However if we set a blank tip this does count as a tooltip
  143. CPPUNIT_ASSERT(!m_radio->GetItemToolTip(1));
  144. #endif
  145. }
  146. void RadioBoxTestCase::Selection()
  147. {
  148. //Until other item containers the first item is selected by default
  149. CPPUNIT_ASSERT_EQUAL(0, m_radio->GetSelection());
  150. CPPUNIT_ASSERT_EQUAL("item 0", m_radio->GetStringSelection());
  151. m_radio->SetSelection(1);
  152. CPPUNIT_ASSERT_EQUAL(1, m_radio->GetSelection());
  153. CPPUNIT_ASSERT_EQUAL("item 1", m_radio->GetStringSelection());
  154. m_radio->SetStringSelection("item 2");
  155. CPPUNIT_ASSERT_EQUAL(2, m_radio->GetSelection());
  156. CPPUNIT_ASSERT_EQUAL("item 2", m_radio->GetStringSelection());
  157. }
  158. void RadioBoxTestCase::Count()
  159. {
  160. //A trivial test for the item count as items can neither
  161. //be added or removed
  162. CPPUNIT_ASSERT_EQUAL(3, m_radio->GetCount());
  163. CPPUNIT_ASSERT(!m_radio->IsEmpty());
  164. }
  165. void RadioBoxTestCase::SetString()
  166. {
  167. m_radio->SetString(0, "new item 0");
  168. m_radio->SetString(2, "");
  169. CPPUNIT_ASSERT_EQUAL("new item 0", m_radio->GetString(0));
  170. CPPUNIT_ASSERT_EQUAL("", m_radio->GetString(2));
  171. }
  172. #endif // wxUSE_RADIOBOX