xmpp/status_test.go
changeset 153 bbd4166df95d
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/xmpp/status_test.go	Sat Sep 28 13:02:17 2013 -0600
@@ -0,0 +1,63 @@
+package xmpp
+
+import (
+	"testing"
+	"time"
+)
+
+func TestStatusListen(t *testing.T) {
+	sm := newStatmgr(nil)
+	l := sm.newListener()
+	stat, ok := <-l
+	if !ok {
+		t.Error()
+	} else if stat != StatusUnconnected {
+		t.Errorf("got %d", stat)
+	}
+
+	sm.setStatus(StatusConnected)
+	stat, ok = <-l
+	if !ok {
+		t.Error()
+	} else if stat != StatusConnected {
+		t.Errorf("got %d", stat)
+	}
+
+	sm.setStatus(StatusBound)
+	stat, ok = <-l
+	if !ok {
+		t.Error()
+	} else if stat != StatusBound {
+		t.Errorf("got %d", stat)
+	}
+
+	sm.setStatus(StatusShutdown)
+	stat = <-l
+	if stat != StatusShutdown {
+		t.Errorf("got %d", stat)
+	}
+}
+
+func TestAwaitStatus(t *testing.T) {
+	sm := newStatmgr(nil)
+
+	syncCh := make(chan int)
+
+	go func() {
+		sm.setStatus(StatusConnected)
+		sm.setStatus(StatusBound)
+		time.Sleep(100 * time.Millisecond)
+		syncCh <- 0
+	}()
+
+	err := sm.awaitStatus(StatusBound)
+	if err != nil {
+		t.Fatal(err)
+	}
+	select {
+	case <-syncCh:
+		t.Fatal("didn't wait")
+	default:
+	}
+	<-syncCh
+}