require 'test/unit'
require 'fox'

include Fox

class TC_FXTreeList < Test::Unit::TestCase
  def setup
    if FXApp.instance.nil?
      @app = FXApp.new('TC_FXTreeList', 'FXRuby')
      @app.init([])
      @mainwin = FXMainWindow.new(@app, 'TC_FXTreeList')
    else
      @app = FXApp.instance
      @mainwin = @app.mainWindow
    end
    @treeList = FXTreeList.new(@mainwin, 0, nil, 0,
      (TREELIST_BROWSESELECT|TREELIST_SHOWS_LINES|TREELIST_SHOWS_BOXES|
       TREELIST_ROOT_BOXES|LAYOUT_FILL_X|LAYOUT_FILL_Y))
  end
  
  def test_firstItem
    assert_nil(@treeList.firstItem)
    item = @treeList.addItemFirst(nil, "first")
    assert_same(item, @treeList.firstItem)
  end

  def test_lastItem
    assert_nil(@treeList.lastItem)
    item = @treeList.addItemFirst(nil, "first")
    assert_same(item, @treeList.lastItem)
  end

  def test_SEL_INSERTED
    anItem = nil
    @treeList.connect(SEL_INSERTED) { |sender, sel, ptr|
      anItem = ptr
    }
    theItem = @treeList.addItemLast(nil, "", nil, nil, nil, true)
    assert_same(theItem, anItem)
  end
  
  def test_SEL_DELETED
    theItem = @treeList.addItemLast(nil, "")
    anItem = nil
    @treeList.connect(SEL_DELETED) { |sender, sel, ptr|
      anItem = ptr
    }
    @treeList.removeItem(theItem, true)
    assert_same(theItem, anItem)
  end
end
