]> git.saurik.com Git - wxWidgets.git/blame - tests/controls/choicetest.cpp
wxMessageBox off the main thread lost result code.
[wxWidgets.git] / tests / controls / choicetest.cpp
CommitLineData
232fdc63
VZ
1///////////////////////////////////////////////////////////////////////////////
2// Name: tests/controls/choice.cpp
3// Purpose: wxChoice unit test
4// Author: Steven Lamerton
5// Created: 2010-06-29
232fdc63
VZ
6// Copyright: (c) 2010 Steven Lamerton
7///////////////////////////////////////////////////////////////////////////////
8
9#include "testprec.h"
10
11#if wxUSE_CHOICE
12
13#ifdef __BORLANDC__
14 #pragma hdrstop
15#endif
16
17#ifndef WX_PRECOMP
18 #include "wx/app.h"
19 #include "wx/choice.h"
20#endif // WX_PRECOMP
21
22#include "itemcontainertest.h"
23
24class ChoiceTestCase : public ItemContainerTestCase, public CppUnit::TestCase
25{
26public:
27 ChoiceTestCase() { }
28
29 virtual void setUp();
30 virtual void tearDown();
31
32private:
33 virtual wxItemContainer *GetContainer() const { return m_choice; }
34 virtual wxWindow *GetContainerWindow() const { return m_choice; }
35
36 CPPUNIT_TEST_SUITE( ChoiceTestCase );
37 wxITEM_CONTAINER_TESTS();
38 CPPUNIT_TEST( Sort );
39 CPPUNIT_TEST_SUITE_END();
40
41 void Sort();
42
43 wxChoice* m_choice;
44
45 DECLARE_NO_COPY_CLASS(ChoiceTestCase)
46};
47
48// register in the unnamed registry so that these tests are run by default
49CPPUNIT_TEST_SUITE_REGISTRATION( ChoiceTestCase );
50
e3778b4d 51// also include in its own registry so that these tests can be run alone
232fdc63
VZ
52CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ChoiceTestCase, "ChoiceTestCase" );
53
54void ChoiceTestCase::setUp()
55{
56 m_choice = new wxChoice(wxTheApp->GetTopWindow(), wxID_ANY);
57}
58
59void ChoiceTestCase::tearDown()
60{
61 wxDELETE(m_choice);
62}
63
64void ChoiceTestCase::Sort()
65{
a6856aa8 66#if !defined(__WXOSX__)
232fdc63
VZ
67 wxDELETE(m_choice);
68 m_choice = new wxChoice(wxTheApp->GetTopWindow(), wxID_ANY,
69 wxDefaultPosition, wxDefaultSize, 0, 0,
70 wxCB_SORT);
71
72 wxArrayString testitems;
73 testitems.Add("aaa");
74 testitems.Add("Aaa");
75 testitems.Add("aba");
76 testitems.Add("aaab");
77 testitems.Add("aab");
78 testitems.Add("AAA");
79
80 m_choice->Append(testitems);
81
82 CPPUNIT_ASSERT_EQUAL("AAA", m_choice->GetString(0));
83 CPPUNIT_ASSERT_EQUAL("Aaa", m_choice->GetString(1));
84 CPPUNIT_ASSERT_EQUAL("aaa", m_choice->GetString(2));
85 CPPUNIT_ASSERT_EQUAL("aaab", m_choice->GetString(3));
86 CPPUNIT_ASSERT_EQUAL("aab", m_choice->GetString(4));
87 CPPUNIT_ASSERT_EQUAL("aba", m_choice->GetString(5));
88
89 m_choice->Append("a");
90
91 CPPUNIT_ASSERT_EQUAL("a", m_choice->GetString(0));
92#endif
93}
94
95#endif //wxUSE_CHOICE