Hey,

I found a bug. Please, see attachment.
BTW: there are regression found after updating to the latest git
(I believe after fixing WMenuItem's memory issue). After running
my test case (or any code which calls new WMenuItem(...)
you'll see Segmentation fault error!

-- 
// Dmitriy.
// -*- C++ -*-
// 
// (C) 2013 Dmitry Igrishin
//
// Bug report.
// Description: incorrect WMenu internal path handling for submenu items.
// How to reproduce:
// 1) Open URL: host (or host/search)
//    (works as expected)
// 2) Open URL: host/settings
//    (OOPS, submenu does not handle internal path at all since
//    unnecessary check -- if (!parentItem_) in
//    WMenu::handleInternalPathChange(const std::string&))

#include <Wt/WApplication>
#include <Wt/WMenu>
#include <Wt/WMenuItem>
#include <Wt/WPopupMenu>
#include <Wt/WStackedWidget>
#include <Wt/WText>

using namespace Wt;

namespace {

class App : public WApplication {
public:
  App(const WEnvironment& e);
private:
  WMenu*
  make_menu();

  WPopupMenu*
  make_submenu(WStackedWidget*);

  WMenu* menu_;
};

App::App(const WEnvironment& e)
  : WApplication(e)
{
  root()->addWidget(make_menu());
}

WMenu*
App::make_menu()
{
  WMenu* const m = new WMenu(new WStackedWidget);
  m->setInternalPathEnabled("/");

  WMenuItem* mi = new WMenuItem("Search", new WText("Search page"));
  mi->setInternalPathEnabled(true);
  mi->setPathComponent("search");
  m->addItem(mi);

  // Submenu "More"
  mi = new WMenuItem("More");   // Item only for grouping, but submenu
                                // will participate in the internal path...
  mi->setInternalPathEnabled(false);
  mi->setMenu(make_submenu(m->contentsStack()));
  m->addItem(mi);

  return m;
}

WPopupMenu*
App::make_submenu(WStackedWidget* const contents)
{
  WPopupMenu* const m = new WPopupMenu(contents);
  m->setInternalPathEnabled("/");

  WMenuItem* const mi = new WMenuItem("Settings", new WText("Settings page"));
  mi->setInternalPathEnabled(true);
  mi->setPathComponent("settings");
  m->addItem(mi);

  return m;
}

WApplication*
create_app(const WEnvironment& env)
{
  return new App(env);
}

} // namespace

int
main(int argc, char* argv[])
{
  return WRun(argc, argv, create_app);
}
------------------------------------------------------------------------------
Rapidly troubleshoot problems before they affect your business. Most IT 
organizations don't have a clear picture of how application performance 
affects their revenue. With AppDynamics, you get 100% visibility into your 
Java,.NET, & PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro!
http://pubads.g.doubleclick.net/gampad/clk?id=84349831&iu=/4140/ostg.clktrk
_______________________________________________
witty-interest mailing list
witty-interest@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/witty-interest

Reply via email to