Made Stack.SetStretchy() panic on invalid index, ending that group of functions. Also added the tests for those functions who did not have tests already written.

This commit is contained in:
Pietro Gagliardi 2014-03-11 17:37:04 -04:00
parent 92fb9efce9
commit cdd535cc71
3 changed files with 42 additions and 6 deletions

View File

@ -48,7 +48,7 @@ func NewVerticalStack(controls ...Control) *Stack {
}
// SetStretchy marks a control in a Stack as stretchy. This cannot be called once the Window containing the Stack has been opened.
// (TODO action on invalid index)
// It panics if index is out of range.
func (s *Stack) SetStretchy(index int) {
s.lock.Lock()
defer s.lock.Unlock()
@ -56,7 +56,10 @@ func (s *Stack) SetStretchy(index int) {
if s.created {
panic("call to Stack.SetStretchy() after Stack has been created")
}
s.stretchy[index] = true // TODO explicitly check for index out of bounds?
if index < 0 || index > len(s.stretchy) {
panic(fmt.Errorf("index %d out of range in Stack.SetStretchy()", index))
}
s.stretchy[index] = true
}
func (s *Stack) make(window *sysData) error {

View File

@ -37,7 +37,7 @@ func gridWindow() (*Window, error) {
var macCrashTest = flag.Bool("maccrash", false, "attempt crash on Mac OS X on deleting too far (debug lack of panic on 32-bit)")
func invalidTest(c *Combobox, l *Listbox) {
func invalidTest(c *Combobox, l *Listbox, s *Stack, g *Grid) {
x := func(what string ) {
if j := recover(); j == nil {
MsgBoxError("test", "%s: no panic", what)
@ -71,6 +71,40 @@ func invalidTest(c *Combobox, l *Listbox) {
func() {
defer x("Listbox.Delete > len"); l.Delete(c.Len() + 5); panic(nil)
}()
if s != nil {
func() {
defer x("Stack.SetStretchy < 0"); s.SetStretchy(-5); panic(nil)
}()
func() {
defer x("Stack.SetStretchy > len"); s.SetStretchy(5555); panic(nil)
}()
}
if g != nil {
func() {
defer x("Grid.SetFilling x < 0"); g.SetFilling(-5, 0); panic(nil)
}()
func() {
defer x("Grid.SetFilling x > len"); g.SetFilling(5555, 0); panic(nil)
}()
func() {
defer x("Grid.SetFilling y < 0"); g.SetFilling(0, -5); panic(nil)
}()
func() {
defer x("Grid.SetFilling y > len"); g.SetFilling(0, 5555); panic(nil)
}()
func() {
defer x("Grid.SetStretchy x < 0"); g.SetStretchy(-5, 0); panic(nil)
}()
func() {
defer x("Grid.SetStretchy x > len"); g.SetStretchy(5555, 0); panic(nil)
}()
func() {
defer x("Grid.SetStretchy y < 0"); g.SetStretchy(0, -5); panic(nil)
}()
func() {
defer x("Grid.SetStretchy y > len"); g.SetStretchy(0, 5555); panic(nil)
}()
}
MsgBox("test", "all working as intended")
}
@ -120,7 +154,7 @@ func myMain() {
s.SetStretchy(0)
s.SetStretchy(1)
if *invalidBefore {
invalidTest(cb1, lb1)
invalidTest(cb1, lb1, s, NewGrid(1, Space()))
}
err := w.Open(s)
if err != nil {
@ -187,7 +221,7 @@ mainloop:
}
pbar.SetProgress(prog)
case <-invalidButton.Clicked:
invalidTest(cb1, lb1)
invalidTest(cb1, lb1, nil, nil)
}
}
w.Hide()

View File

@ -17,7 +17,6 @@ so I don't forget:
- Combobox/Listbox.Select (with Listbox.Select allowing bulk)
- Checkbox.Check or Checkbox.SetChecked
- Listbox.SelectAll
- have methods that take indices panic on invalid index, like the Stack and Grid stretchy methods
- make the Windows implementation of message boxes run on uitask
- ensure MsgBoxError can run if initialization failed if things change ever
- should Labels be selectable?