void test_sib () throws Error
{
  var uistr = """
  <ui>
    <menubar>
      <menu name="FileMenu" action="FileAction" >
        <placeholder name="FileMenuAdditions" />
      </menu>
    </menubar>
  </ui>""";

  var actions = new Gtk.ActionGroup ("actions");
  var file_action = new Gtk.Action ("FileAction", "File", "File Tooltip", null);
  actions.add_action (file_action);
  var test_action = new Gtk.Action ("TestAction", "Testing", "Testing Tooltip", null);
  actions.add_action (test_action);
  var test2_action = new Gtk.Action ("Test2Action", "Testing2", "Testing2 Tooltip", null);
  actions.add_action (test2_action);

  var manager = new Gtk.UIManager ();
  manager.insert_action_group (actions, 0);
  manager.add_ui_from_string (uistr, -1);
  manager.ensure_update ();

  var mid = manager.new_merge_id ();
  manager.add_ui (mid, "/ui/menubar/FileMenu/FileMenuAdditions",
                  "Test", "TestAction",
                  Gtk.UIManagerItemType.MENUITEM, true);
  var mid2 = manager.new_merge_id ();
  manager.add_ui (mid2, "/ui/menubar/FileMenu/FileMenuAdditions",
                  "Test2", "Test2Action",
                  Gtk.UIManagerItemType.MENUITEM, true);
  manager.ensure_update ();

  weak Gtk.Widget menu = manager.get_widget ("/ui/menubar/FileMenu/FileMenuAdditions/Test");
  menu.destroy.connect (() => {
    print("Test destroyed, about to remove Test2\n");
    manager.remove_ui (mid2);
    print("about to update in destroy\n");
    manager.ensure_update ();
    print("done in destroy\n");
  });

  weak Gtk.Widget menu2 = manager.get_widget ("/ui/menubar/FileMenu/FileMenuAdditions/Test2");
  menu2.destroy.connect (() => {
    print("Test2 destroyed\n");
  });

  print("about to remove Test\n");
  manager.remove_ui (mid);
  print("about to update in main\n");
  manager.ensure_update ();
  print("done in main\n");
}

void test_child () throws Error
{
  var uistr = """
  <ui>
    <menubar>
      <menu name="FileMenu" action="FileAction" >
        <placeholder name="FileMenuAdditions" />
      </menu>
    </menubar>
  </ui>""";

  var actions = new Gtk.ActionGroup ("actions");
  var file_action = new Gtk.Action ("FileAction", "File", "File Tooltip", null);
  actions.add_action (file_action);
  var test_action = new Gtk.Action ("TestAction", "Testing", "Testing Tooltip", null);
  actions.add_action (test_action);
  var test2_action = new Gtk.Action ("Test2Action", "Testing2", "Testing2 Tooltip", null);
  actions.add_action (test2_action);

  var manager = new Gtk.UIManager ();
  manager.insert_action_group (actions, 0);
  manager.add_ui_from_string (uistr, -1);
  manager.ensure_update ();

  var mid2 = manager.new_merge_id ();
  manager.add_ui (mid2, "/ui/menubar/FileMenu/FileMenuAdditions",
                  "Test2", "Test2Action",
                  Gtk.UIManagerItemType.MENU, true);
  manager.ensure_update ();
  var mid = manager.new_merge_id ();
  manager.add_ui (mid, "/ui/menubar/FileMenu/FileMenuAdditions/Test2",
                  "Test", "TestAction",
                  Gtk.UIManagerItemType.MENUITEM, true);
  manager.ensure_update ();

  weak Gtk.Widget menu2 = manager.get_widget ("/ui/menubar/FileMenu/FileMenuAdditions/Test2");
  menu2.destroy.connect (() => {
    print("Test2 destroyed\n");
  });

  weak Gtk.Widget menu = manager.get_widget ("/ui/menubar/FileMenu/FileMenuAdditions/Test2/Test");
  menu.destroy.connect (() => {
    print("Test destroyed, about to remove Test2\n");
    manager.remove_ui (mid2);
    print("about to update in destroy\n");
    manager.ensure_update ();
    print("done in destroy\n");
  });

  print("about to remove Test\n");
  manager.remove_ui (mid);
  print("about to update in main\n");
  manager.ensure_update ();
  print("done in main\n");
}

int main (string[] args)
{
  Gtk.init (ref args);

  try {
    test_sib ();
    test_child ();
  }
  catch (Error e) {
    warning("%s\n", e.message);
  }

  return 0;
}
