@@ -2,6 +2,7 @@ package goey
2
2
3
3
import (
4
4
"bytes"
5
+ "errors"
5
6
"reflect"
6
7
"runtime"
7
8
"testing"
@@ -494,3 +495,85 @@ func testingUpdateWidgets(t *testing.T, widgets []base.Widget, update []base.Wid
494
495
t .Errorf ("Failed to run GUI loop, %s" , err )
495
496
}
496
497
}
498
+
499
+ func testingUpdateWidget (t * testing.T ) (updater func (base.Widget ) bool , closer func ()) {
500
+ ready := make (chan * Window , 1 )
501
+ done := make (chan struct {})
502
+
503
+ go func () {
504
+ init := func () error {
505
+ // Create the window. Some of the tests here are not expected in
506
+ // production code, but we can be a little paranoid here.
507
+ window , err := NewWindow (t .Name (), nil )
508
+ if err != nil {
509
+ t .Errorf ("Failed to create window, %s" , err )
510
+ return nil
511
+ }
512
+ if window == nil {
513
+ t .Errorf ("Unexpected nil for window" )
514
+ return nil
515
+ }
516
+
517
+ // Check that the controls that were mounted match with the list
518
+ if len (window .children ()) != 0 {
519
+ t .Errorf ("Want len(window.Children())!=0" )
520
+ }
521
+
522
+ ready <- window
523
+ return nil
524
+ }
525
+
526
+ err := loop .Run (init )
527
+ if err != nil {
528
+ t .Errorf ("Failed to run GUI loop, %s" , err )
529
+ }
530
+ close (done )
531
+ }()
532
+
533
+ window := <- ready
534
+
535
+ updater = func (w base.Widget ) bool {
536
+ err := loop .Do (func () error {
537
+ err := window .SetChild (w )
538
+ if err != nil {
539
+ return err
540
+ }
541
+
542
+ child := window .Child ()
543
+ if n1 , n2 := child .Kind (), w .Kind (); n1 != n2 {
544
+ return errors .New ("child's kind does not match widget's kind" )
545
+ } else if widget , ok := child .(Proper ); ok {
546
+ data := widget .Props ()
547
+ if n1 , n2 := data .Kind (), w .Kind (); n1 != n2 {
548
+ return errors .New ("child's prop's kind does not match widget's kind" )
549
+ }
550
+ if ! equal (t , data , w ) {
551
+ return errors .New ("child's prop's not equal to widget" )
552
+ }
553
+ } else {
554
+ return errors .New ("child does not support props" )
555
+ }
556
+ return nil
557
+ })
558
+
559
+ if err != nil {
560
+ t .Errorf ("Error during widget update, %s" , err )
561
+ return false
562
+ }
563
+ return true
564
+ }
565
+ closer = func () {
566
+ // Close the window
567
+ err := loop .Do (func () error {
568
+ window .Close ()
569
+ return nil
570
+ })
571
+ if err != nil {
572
+ t .Errorf ("Error in Do, %s" , err )
573
+ }
574
+
575
+ // Wait for the GUI loop to terminate
576
+ <- done
577
+ }
578
+ return updater , closer
579
+ }
0 commit comments