Add a beginning of wxMenu unit test.
Test wxMenu and wxMenuBar item search and counting functions. See #12672. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@66139 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -200,6 +200,7 @@ TEST_GUI_OBJECTS = \
|
|||||||
test_gui_image.o \
|
test_gui_image.o \
|
||||||
test_gui_rawbmp.o \
|
test_gui_rawbmp.o \
|
||||||
test_gui_htmlwindow.o \
|
test_gui_htmlwindow.o \
|
||||||
|
test_gui_menu.o \
|
||||||
test_gui_guifuncs.o \
|
test_gui_guifuncs.o \
|
||||||
test_gui_selstoretest.o \
|
test_gui_selstoretest.o \
|
||||||
test_gui_garbage.o \
|
test_gui_garbage.o \
|
||||||
@@ -820,6 +821,9 @@ test_gui_rawbmp.o: $(srcdir)/image/rawbmp.cpp $(TEST_GUI_ODEP)
|
|||||||
test_gui_htmlwindow.o: $(srcdir)/html/htmlwindow.cpp $(TEST_GUI_ODEP)
|
test_gui_htmlwindow.o: $(srcdir)/html/htmlwindow.cpp $(TEST_GUI_ODEP)
|
||||||
$(CXXC) -c -o $@ $(TEST_GUI_CXXFLAGS) $(srcdir)/html/htmlwindow.cpp
|
$(CXXC) -c -o $@ $(TEST_GUI_CXXFLAGS) $(srcdir)/html/htmlwindow.cpp
|
||||||
|
|
||||||
|
test_gui_menu.o: $(srcdir)/menu/menu.cpp $(TEST_GUI_ODEP)
|
||||||
|
$(CXXC) -c -o $@ $(TEST_GUI_CXXFLAGS) $(srcdir)/menu/menu.cpp
|
||||||
|
|
||||||
test_gui_guifuncs.o: $(srcdir)/misc/guifuncs.cpp $(TEST_GUI_ODEP)
|
test_gui_guifuncs.o: $(srcdir)/misc/guifuncs.cpp $(TEST_GUI_ODEP)
|
||||||
$(CXXC) -c -o $@ $(TEST_GUI_CXXFLAGS) $(srcdir)/misc/guifuncs.cpp
|
$(CXXC) -c -o $@ $(TEST_GUI_CXXFLAGS) $(srcdir)/misc/guifuncs.cpp
|
||||||
|
|
||||||
|
@@ -185,6 +185,7 @@ TEST_GUI_OBJECTS = \
|
|||||||
$(OBJS)\test_gui_image.obj \
|
$(OBJS)\test_gui_image.obj \
|
||||||
$(OBJS)\test_gui_rawbmp.obj \
|
$(OBJS)\test_gui_rawbmp.obj \
|
||||||
$(OBJS)\test_gui_htmlwindow.obj \
|
$(OBJS)\test_gui_htmlwindow.obj \
|
||||||
|
$(OBJS)\test_gui_menu.obj \
|
||||||
$(OBJS)\test_gui_guifuncs.obj \
|
$(OBJS)\test_gui_guifuncs.obj \
|
||||||
$(OBJS)\test_gui_selstoretest.obj \
|
$(OBJS)\test_gui_selstoretest.obj \
|
||||||
$(OBJS)\test_gui_garbage.obj \
|
$(OBJS)\test_gui_garbage.obj \
|
||||||
@@ -866,6 +867,9 @@ $(OBJS)\test_gui_rawbmp.obj: .\image\rawbmp.cpp
|
|||||||
$(OBJS)\test_gui_htmlwindow.obj: .\html\htmlwindow.cpp
|
$(OBJS)\test_gui_htmlwindow.obj: .\html\htmlwindow.cpp
|
||||||
$(CXX) -q -c -P -o$@ $(TEST_GUI_CXXFLAGS) .\html\htmlwindow.cpp
|
$(CXX) -q -c -P -o$@ $(TEST_GUI_CXXFLAGS) .\html\htmlwindow.cpp
|
||||||
|
|
||||||
|
$(OBJS)\test_gui_menu.obj: .\menu\menu.cpp
|
||||||
|
$(CXX) -q -c -P -o$@ $(TEST_GUI_CXXFLAGS) .\menu\menu.cpp
|
||||||
|
|
||||||
$(OBJS)\test_gui_guifuncs.obj: .\misc\guifuncs.cpp
|
$(OBJS)\test_gui_guifuncs.obj: .\misc\guifuncs.cpp
|
||||||
$(CXX) -q -c -P -o$@ $(TEST_GUI_CXXFLAGS) .\misc\guifuncs.cpp
|
$(CXX) -q -c -P -o$@ $(TEST_GUI_CXXFLAGS) .\misc\guifuncs.cpp
|
||||||
|
|
||||||
@@ -892,3 +896,4 @@ $(OBJS)\test_gui_setsize.obj: .\window\setsize.cpp
|
|||||||
|
|
||||||
$(OBJS)\test_gui_xrctest.obj: .\xml\xrctest.cpp
|
$(OBJS)\test_gui_xrctest.obj: .\xml\xrctest.cpp
|
||||||
$(CXX) -q -c -P -o$@ $(TEST_GUI_CXXFLAGS) .\xml\xrctest.cpp
|
$(CXX) -q -c -P -o$@ $(TEST_GUI_CXXFLAGS) .\xml\xrctest.cpp
|
||||||
|
|
||||||
|
@@ -178,6 +178,7 @@ TEST_GUI_OBJECTS = \
|
|||||||
$(OBJS)\test_gui_image.o \
|
$(OBJS)\test_gui_image.o \
|
||||||
$(OBJS)\test_gui_rawbmp.o \
|
$(OBJS)\test_gui_rawbmp.o \
|
||||||
$(OBJS)\test_gui_htmlwindow.o \
|
$(OBJS)\test_gui_htmlwindow.o \
|
||||||
|
$(OBJS)\test_gui_menu.o \
|
||||||
$(OBJS)\test_gui_guifuncs.o \
|
$(OBJS)\test_gui_guifuncs.o \
|
||||||
$(OBJS)\test_gui_selstoretest.o \
|
$(OBJS)\test_gui_selstoretest.o \
|
||||||
$(OBJS)\test_gui_garbage.o \
|
$(OBJS)\test_gui_garbage.o \
|
||||||
@@ -847,6 +848,9 @@ $(OBJS)\test_gui_rawbmp.o: ./image/rawbmp.cpp
|
|||||||
$(OBJS)\test_gui_htmlwindow.o: ./html/htmlwindow.cpp
|
$(OBJS)\test_gui_htmlwindow.o: ./html/htmlwindow.cpp
|
||||||
$(CXX) -c -o $@ $(TEST_GUI_CXXFLAGS) $(CPPDEPS) $<
|
$(CXX) -c -o $@ $(TEST_GUI_CXXFLAGS) $(CPPDEPS) $<
|
||||||
|
|
||||||
|
$(OBJS)\test_gui_menu.o: ./menu/menu.cpp
|
||||||
|
$(CXX) -c -o $@ $(TEST_GUI_CXXFLAGS) $(CPPDEPS) $<
|
||||||
|
|
||||||
$(OBJS)\test_gui_guifuncs.o: ./misc/guifuncs.cpp
|
$(OBJS)\test_gui_guifuncs.o: ./misc/guifuncs.cpp
|
||||||
$(CXX) -c -o $@ $(TEST_GUI_CXXFLAGS) $(CPPDEPS) $<
|
$(CXX) -c -o $@ $(TEST_GUI_CXXFLAGS) $(CPPDEPS) $<
|
||||||
|
|
||||||
|
@@ -180,6 +180,7 @@ TEST_GUI_OBJECTS = \
|
|||||||
$(OBJS)\test_gui_image.obj \
|
$(OBJS)\test_gui_image.obj \
|
||||||
$(OBJS)\test_gui_rawbmp.obj \
|
$(OBJS)\test_gui_rawbmp.obj \
|
||||||
$(OBJS)\test_gui_htmlwindow.obj \
|
$(OBJS)\test_gui_htmlwindow.obj \
|
||||||
|
$(OBJS)\test_gui_menu.obj \
|
||||||
$(OBJS)\test_gui_guifuncs.obj \
|
$(OBJS)\test_gui_guifuncs.obj \
|
||||||
$(OBJS)\test_gui_selstoretest.obj \
|
$(OBJS)\test_gui_selstoretest.obj \
|
||||||
$(OBJS)\test_gui_garbage.obj \
|
$(OBJS)\test_gui_garbage.obj \
|
||||||
@@ -992,6 +993,9 @@ $(OBJS)\test_gui_rawbmp.obj: .\image\rawbmp.cpp
|
|||||||
$(OBJS)\test_gui_htmlwindow.obj: .\html\htmlwindow.cpp
|
$(OBJS)\test_gui_htmlwindow.obj: .\html\htmlwindow.cpp
|
||||||
$(CXX) /c /nologo /TP /Fo$@ $(TEST_GUI_CXXFLAGS) .\html\htmlwindow.cpp
|
$(CXX) /c /nologo /TP /Fo$@ $(TEST_GUI_CXXFLAGS) .\html\htmlwindow.cpp
|
||||||
|
|
||||||
|
$(OBJS)\test_gui_menu.obj: .\menu\menu.cpp
|
||||||
|
$(CXX) /c /nologo /TP /Fo$@ $(TEST_GUI_CXXFLAGS) .\menu\menu.cpp
|
||||||
|
|
||||||
$(OBJS)\test_gui_guifuncs.obj: .\misc\guifuncs.cpp
|
$(OBJS)\test_gui_guifuncs.obj: .\misc\guifuncs.cpp
|
||||||
$(CXX) /c /nologo /TP /Fo$@ $(TEST_GUI_CXXFLAGS) .\misc\guifuncs.cpp
|
$(CXX) /c /nologo /TP /Fo$@ $(TEST_GUI_CXXFLAGS) .\misc\guifuncs.cpp
|
||||||
|
|
||||||
@@ -1018,3 +1022,4 @@ $(OBJS)\test_gui_setsize.obj: .\window\setsize.cpp
|
|||||||
|
|
||||||
$(OBJS)\test_gui_xrctest.obj: .\xml\xrctest.cpp
|
$(OBJS)\test_gui_xrctest.obj: .\xml\xrctest.cpp
|
||||||
$(CXX) /c /nologo /TP /Fo$@ $(TEST_GUI_CXXFLAGS) .\xml\xrctest.cpp
|
$(CXX) /c /nologo /TP /Fo$@ $(TEST_GUI_CXXFLAGS) .\xml\xrctest.cpp
|
||||||
|
|
||||||
|
@@ -420,6 +420,7 @@ TEST_GUI_OBJECTS = &
|
|||||||
$(OBJS)\test_gui_image.obj &
|
$(OBJS)\test_gui_image.obj &
|
||||||
$(OBJS)\test_gui_rawbmp.obj &
|
$(OBJS)\test_gui_rawbmp.obj &
|
||||||
$(OBJS)\test_gui_htmlwindow.obj &
|
$(OBJS)\test_gui_htmlwindow.obj &
|
||||||
|
$(OBJS)\test_gui_menu.obj &
|
||||||
$(OBJS)\test_gui_guifuncs.obj &
|
$(OBJS)\test_gui_guifuncs.obj &
|
||||||
$(OBJS)\test_gui_selstoretest.obj &
|
$(OBJS)\test_gui_selstoretest.obj &
|
||||||
$(OBJS)\test_gui_garbage.obj &
|
$(OBJS)\test_gui_garbage.obj &
|
||||||
@@ -905,6 +906,9 @@ $(OBJS)\test_gui_rawbmp.obj : .AUTODEPEND .\image\rawbmp.cpp
|
|||||||
$(OBJS)\test_gui_htmlwindow.obj : .AUTODEPEND .\html\htmlwindow.cpp
|
$(OBJS)\test_gui_htmlwindow.obj : .AUTODEPEND .\html\htmlwindow.cpp
|
||||||
$(CXX) -bt=nt -zq -fo=$^@ $(TEST_GUI_CXXFLAGS) $<
|
$(CXX) -bt=nt -zq -fo=$^@ $(TEST_GUI_CXXFLAGS) $<
|
||||||
|
|
||||||
|
$(OBJS)\test_gui_menu.obj : .AUTODEPEND .\menu\menu.cpp
|
||||||
|
$(CXX) -bt=nt -zq -fo=$^@ $(TEST_GUI_CXXFLAGS) $<
|
||||||
|
|
||||||
$(OBJS)\test_gui_guifuncs.obj : .AUTODEPEND .\misc\guifuncs.cpp
|
$(OBJS)\test_gui_guifuncs.obj : .AUTODEPEND .\misc\guifuncs.cpp
|
||||||
$(CXX) -bt=nt -zq -fo=$^@ $(TEST_GUI_CXXFLAGS) $<
|
$(CXX) -bt=nt -zq -fo=$^@ $(TEST_GUI_CXXFLAGS) $<
|
||||||
|
|
||||||
@@ -931,3 +935,4 @@ $(OBJS)\test_gui_setsize.obj : .AUTODEPEND .\window\setsize.cpp
|
|||||||
|
|
||||||
$(OBJS)\test_gui_xrctest.obj : .AUTODEPEND .\xml\xrctest.cpp
|
$(OBJS)\test_gui_xrctest.obj : .AUTODEPEND .\xml\xrctest.cpp
|
||||||
$(CXX) -bt=nt -zq -fo=$^@ $(TEST_GUI_CXXFLAGS) $<
|
$(CXX) -bt=nt -zq -fo=$^@ $(TEST_GUI_CXXFLAGS) $<
|
||||||
|
|
||||||
|
266
tests/menu/menu.cpp
Normal file
266
tests/menu/menu.cpp
Normal file
@@ -0,0 +1,266 @@
|
|||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Name: tests/menu/menu.cpp
|
||||||
|
// Purpose: wxMenu unit test
|
||||||
|
// Author: wxWidgets team
|
||||||
|
// Created: 2010-11-10
|
||||||
|
// 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/menu.h"
|
||||||
|
#include <stdarg.h>
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// helper
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
MenuTestCase_Quit = wxID_EXIT,
|
||||||
|
MenuTestCase_About = wxID_ABOUT,
|
||||||
|
MenuTestCase_First = 10000
|
||||||
|
};
|
||||||
|
|
||||||
|
void PopulateMenu(wxMenu* menu, const wxString& name, size_t& itemcount)
|
||||||
|
{
|
||||||
|
// Start at item 1 to make it human-readable ;)
|
||||||
|
for (int n=1; n<6; ++n, ++itemcount)
|
||||||
|
{
|
||||||
|
wxString label = name; label << n;
|
||||||
|
menu->Append(MenuTestCase_First + itemcount, label, label + " help string");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void RecursivelyCountMenuItems(const wxMenu* menu, size_t& count)
|
||||||
|
{
|
||||||
|
CPPUNIT_ASSERT( menu );
|
||||||
|
|
||||||
|
count += menu->GetMenuItemCount();
|
||||||
|
for (size_t n=0; n < menu->GetMenuItemCount(); ++n)
|
||||||
|
{
|
||||||
|
wxMenuItem* item = menu->FindItemByPosition(n);
|
||||||
|
if (item->IsSubMenu())
|
||||||
|
{
|
||||||
|
RecursivelyCountMenuItems(item->GetSubMenu(), count);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // anon namespace
|
||||||
|
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// test class
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
class MenuTestCase : public CppUnit::TestCase
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
MenuTestCase() {}
|
||||||
|
|
||||||
|
virtual void setUp() { CreateFrame(); }
|
||||||
|
virtual void tearDown() { m_frame->Destroy(); }
|
||||||
|
|
||||||
|
private:
|
||||||
|
CPPUNIT_TEST_SUITE( MenuTestCase );
|
||||||
|
CPPUNIT_TEST( FindInMenubar );
|
||||||
|
CPPUNIT_TEST( FindInMenu );
|
||||||
|
CPPUNIT_TEST( Count );
|
||||||
|
CPPUNIT_TEST_SUITE_END();
|
||||||
|
|
||||||
|
void CreateFrame();
|
||||||
|
|
||||||
|
void FindInMenubar();
|
||||||
|
void FindInMenu();
|
||||||
|
void Count();
|
||||||
|
|
||||||
|
wxFrame* m_frame;
|
||||||
|
|
||||||
|
// Holds the number of menuitems contained in all the menus
|
||||||
|
size_t m_itemCount;
|
||||||
|
|
||||||
|
// Store here the id of a known submenu item, to be searched for later
|
||||||
|
int m_submenuItemId;
|
||||||
|
|
||||||
|
// and a sub-submenu item
|
||||||
|
int m_subsubmenuItemId;
|
||||||
|
|
||||||
|
wxArrayString m_menuLabels;
|
||||||
|
|
||||||
|
DECLARE_NO_COPY_CLASS(MenuTestCase)
|
||||||
|
};
|
||||||
|
|
||||||
|
// register in the unnamed registry so that these tests are run by default
|
||||||
|
CPPUNIT_TEST_SUITE_REGISTRATION( MenuTestCase );
|
||||||
|
|
||||||
|
// also include in it's own registry so that these tests can be run alone
|
||||||
|
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( MenuTestCase, "MenuTestCase" );
|
||||||
|
|
||||||
|
void MenuTestCase::CreateFrame()
|
||||||
|
{
|
||||||
|
m_frame = new wxFrame(NULL, wxID_ANY, "test frame");
|
||||||
|
|
||||||
|
wxMenu *fileMenu = new wxMenu;
|
||||||
|
wxMenu *helpMenu = new wxMenu;
|
||||||
|
wxMenu *subMenu = new wxMenu;
|
||||||
|
wxMenu *subsubMenu = new wxMenu;
|
||||||
|
|
||||||
|
size_t itemcount = 0;
|
||||||
|
|
||||||
|
PopulateMenu(subsubMenu, "Subsubmenu item ", itemcount);
|
||||||
|
|
||||||
|
// Store one of its IDs for later
|
||||||
|
m_subsubmenuItemId = MenuTestCase_First + itemcount - 2;
|
||||||
|
|
||||||
|
PopulateMenu(subMenu, "Submenu item ", itemcount);
|
||||||
|
|
||||||
|
// Store one of its IDs for later
|
||||||
|
m_submenuItemId = MenuTestCase_First + itemcount - 2;
|
||||||
|
|
||||||
|
subMenu->AppendSubMenu(subsubMenu, "Subsubmen&u", "Test a subsubmenu");
|
||||||
|
|
||||||
|
PopulateMenu(fileMenu, "Filemenu item ", itemcount);
|
||||||
|
// Add a 'real' item too, for future tests
|
||||||
|
fileMenu->Append(MenuTestCase_Quit, "E&xit\tAlt-X", "Quit this program");
|
||||||
|
|
||||||
|
|
||||||
|
PopulateMenu(helpMenu, "Helpmenu item ", itemcount);
|
||||||
|
helpMenu->Append(MenuTestCase_About, "&About...\tF1",
|
||||||
|
"(Would normally) Show about dialog");
|
||||||
|
helpMenu->AppendSubMenu(subMenu, "Sub&menu", "Test a submenu");
|
||||||
|
|
||||||
|
// +2 for E&xit and &About, +2 for the 2 submenus
|
||||||
|
m_itemCount = itemcount + 4;
|
||||||
|
|
||||||
|
// Use an arraystring here, to help with future tests
|
||||||
|
m_menuLabels.Add("&File");
|
||||||
|
m_menuLabels.Add("&Help");
|
||||||
|
|
||||||
|
wxMenuBar *menuBar = new wxMenuBar();
|
||||||
|
menuBar->Append(fileMenu, m_menuLabels[0]);
|
||||||
|
menuBar->Append(helpMenu, m_menuLabels[1]);
|
||||||
|
m_frame->SetMenuBar(menuBar);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MenuTestCase::FindInMenubar()
|
||||||
|
{
|
||||||
|
wxMenuBar* bar = m_frame->GetMenuBar();
|
||||||
|
|
||||||
|
// Find by name:
|
||||||
|
CPPUNIT_ASSERT( bar->FindMenu("File") != wxNOT_FOUND );
|
||||||
|
CPPUNIT_ASSERT( bar->FindMenu("&File") != wxNOT_FOUND );
|
||||||
|
CPPUNIT_ASSERT( bar->FindMenu("&Fail") == wxNOT_FOUND );
|
||||||
|
|
||||||
|
// Find by menu name plus item name:
|
||||||
|
CPPUNIT_ASSERT( bar->FindMenuItem("File", "Exit") != wxNOT_FOUND );
|
||||||
|
CPPUNIT_ASSERT( bar->FindMenuItem("&File", "E&xit") != wxNOT_FOUND );
|
||||||
|
// and using the menu title
|
||||||
|
int index = bar->FindMenu("&File");
|
||||||
|
CPPUNIT_ASSERT( index != wxNOT_FOUND );
|
||||||
|
wxString menutitle = bar->GetMenuLabel(index);
|
||||||
|
CPPUNIT_ASSERT( bar->FindMenuItem(menutitle, "E&xit") != wxNOT_FOUND );
|
||||||
|
|
||||||
|
// Find by position:
|
||||||
|
for (size_t n=0; n < bar->GetMenuCount(); ++n)
|
||||||
|
{
|
||||||
|
CPPUNIT_ASSERT( bar->GetMenu(n) );
|
||||||
|
}
|
||||||
|
|
||||||
|
// Find by id:
|
||||||
|
wxMenu* menu = NULL;
|
||||||
|
wxMenuItem* item = NULL;
|
||||||
|
item = bar->FindItem(MenuTestCase_Quit, &menu);
|
||||||
|
CPPUNIT_ASSERT( item );
|
||||||
|
CPPUNIT_ASSERT( menu );
|
||||||
|
// Check that the correct menu was found
|
||||||
|
CPPUNIT_ASSERT( menu->FindChildItem(MenuTestCase_Quit) );
|
||||||
|
|
||||||
|
// Find submenu item:
|
||||||
|
item = bar->FindItem(m_submenuItemId, &menu);
|
||||||
|
CPPUNIT_ASSERT( item );
|
||||||
|
CPPUNIT_ASSERT( menu );
|
||||||
|
// and, for completeness, a submenu one:
|
||||||
|
item = bar->FindItem(m_subsubmenuItemId, &menu);
|
||||||
|
CPPUNIT_ASSERT( item );
|
||||||
|
CPPUNIT_ASSERT( menu );
|
||||||
|
}
|
||||||
|
|
||||||
|
void MenuTestCase::FindInMenu()
|
||||||
|
{
|
||||||
|
wxMenuBar* bar = m_frame->GetMenuBar();
|
||||||
|
|
||||||
|
// Find by name:
|
||||||
|
wxMenu* menuFind = bar->GetMenu(0);
|
||||||
|
CPPUNIT_ASSERT( menuFind->FindItem("Exit") != wxNOT_FOUND );
|
||||||
|
CPPUNIT_ASSERT( menuFind->FindItem("E&xit") != wxNOT_FOUND );
|
||||||
|
// and for submenus
|
||||||
|
wxMenu* menuHelp = bar->GetMenu(1);
|
||||||
|
CPPUNIT_ASSERT( menuHelp->FindItem("Submenu") != wxNOT_FOUND );
|
||||||
|
CPPUNIT_ASSERT( menuHelp->FindItem("Sub&menu") != wxNOT_FOUND );
|
||||||
|
|
||||||
|
// Find by position:
|
||||||
|
for (size_t n=0; n < menuHelp->GetMenuItemCount(); ++n)
|
||||||
|
{
|
||||||
|
CPPUNIT_ASSERT( menuHelp->FindItemByPosition(n) );
|
||||||
|
}
|
||||||
|
|
||||||
|
// Find by id:
|
||||||
|
CPPUNIT_ASSERT( menuHelp->FindItem(MenuTestCase_About) );
|
||||||
|
CPPUNIT_ASSERT( menuHelp->FindItem(MenuTestCase_Quit) == NULL );
|
||||||
|
|
||||||
|
for (size_t n=0; n < menuHelp->GetMenuItemCount(); ++n)
|
||||||
|
{
|
||||||
|
size_t locatedAt;
|
||||||
|
wxMenuItem* itemByPos = menuHelp->FindItemByPosition(n);
|
||||||
|
CPPUNIT_ASSERT( itemByPos );
|
||||||
|
wxMenuItem* itemById = menuHelp->FindChildItem(itemByPos->GetId(), &locatedAt);
|
||||||
|
CPPUNIT_ASSERT_EQUAL( itemByPos, itemById );
|
||||||
|
CPPUNIT_ASSERT_EQUAL( locatedAt, n );
|
||||||
|
}
|
||||||
|
|
||||||
|
// Find submenu item:
|
||||||
|
for (size_t n=0; n < menuHelp->GetMenuItemCount(); ++n)
|
||||||
|
{
|
||||||
|
wxMenuItem* item = menuHelp->FindItemByPosition(n);
|
||||||
|
if (item->IsSubMenu())
|
||||||
|
{
|
||||||
|
wxMenu* submenu;
|
||||||
|
wxMenuItem* submenuItem = menuHelp->FindItem(m_submenuItemId, &submenu);
|
||||||
|
CPPUNIT_ASSERT( submenuItem );
|
||||||
|
CPPUNIT_ASSERT( item->GetSubMenu() == submenu );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MenuTestCase::Count()
|
||||||
|
{
|
||||||
|
wxMenuBar* bar = m_frame->GetMenuBar();
|
||||||
|
// I suppose you could call this "counting menubars" :)
|
||||||
|
CPPUNIT_ASSERT( bar );
|
||||||
|
|
||||||
|
CPPUNIT_ASSERT_EQUAL( bar->GetMenuCount(), 2 );
|
||||||
|
|
||||||
|
size_t count = 0;
|
||||||
|
for (size_t n=0; n < bar->GetMenuCount(); ++n)
|
||||||
|
{
|
||||||
|
RecursivelyCountMenuItems(bar->GetMenu(n), count);
|
||||||
|
}
|
||||||
|
CPPUNIT_ASSERT_EQUAL( count, m_itemCount );
|
||||||
|
}
|
@@ -181,6 +181,7 @@
|
|||||||
image/image.cpp
|
image/image.cpp
|
||||||
image/rawbmp.cpp
|
image/rawbmp.cpp
|
||||||
html/htmlwindow.cpp
|
html/htmlwindow.cpp
|
||||||
|
menu/menu.cpp
|
||||||
misc/guifuncs.cpp
|
misc/guifuncs.cpp
|
||||||
misc/selstoretest.cpp
|
misc/selstoretest.cpp
|
||||||
misc/garbage.cpp
|
misc/garbage.cpp
|
||||||
|
@@ -385,6 +385,10 @@ SOURCE=.\graphics\measuring.cpp
|
|||||||
# End Source File
|
# End Source File
|
||||||
# Begin Source File
|
# Begin Source File
|
||||||
|
|
||||||
|
SOURCE=.\menu\menu.cpp
|
||||||
|
# End Source File
|
||||||
|
# Begin Source File
|
||||||
|
|
||||||
SOURCE=.\controls\notebooktest.cpp
|
SOURCE=.\controls\notebooktest.cpp
|
||||||
# End Source File
|
# End Source File
|
||||||
# Begin Source File
|
# Begin Source File
|
||||||
|
@@ -724,6 +724,9 @@
|
|||||||
<File
|
<File
|
||||||
RelativePath=".\graphics\measuring.cpp">
|
RelativePath=".\graphics\measuring.cpp">
|
||||||
</File>
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\menu\menu.cpp">
|
||||||
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath=".\controls\notebooktest.cpp">
|
RelativePath=".\controls\notebooktest.cpp">
|
||||||
</File>
|
</File>
|
||||||
|
@@ -1039,6 +1039,10 @@
|
|||||||
RelativePath=".\graphics\measuring.cpp"
|
RelativePath=".\graphics\measuring.cpp"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\menu\menu.cpp"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath=".\controls\notebooktest.cpp"
|
RelativePath=".\controls\notebooktest.cpp"
|
||||||
>
|
>
|
||||||
|
@@ -1011,6 +1011,10 @@
|
|||||||
RelativePath=".\graphics\measuring.cpp"
|
RelativePath=".\graphics\measuring.cpp"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\menu\menu.cpp"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath=".\controls\notebooktest.cpp"
|
RelativePath=".\controls\notebooktest.cpp"
|
||||||
>
|
>
|
||||||
|
Reference in New Issue
Block a user