func TestServer(t *testing.T) { s := NewServer() defer s.Close() c, err := net.Dial("tcp", s.Addr()) if err != nil { t.Fatal(err) } defer c.Close() rw := newConn(c) // bind p := pdu.NewBindTransmitter() f := p.Fields() f.Set(pdufield.SystemID, "client") f.Set(pdufield.Password, "secret") f.Set(pdufield.InterfaceVersion, 0x34) if err = rw.Write(p); err != nil { t.Fatal(err) } // bind resp resp, err := rw.Read() if err != nil { t.Fatal(err) } id, ok := resp.Fields()[pdufield.SystemID] if !ok { t.Fatalf("missing system_id field: %#v", resp) } if id.String() != "smpptest" { t.Fatalf("unexpected system_id: want smpptest, have %q", id) } // submit_sm p = pdu.NewSubmitSM() f = p.Fields() f.Set(pdufield.SourceAddr, "foobar") f.Set(pdufield.DestinationAddr, "bozo") f.Set(pdufield.ShortMessage, pdutext.Latin1("Lorem ipsum")) if err = rw.Write(p); err != nil { t.Fatal(err) } // same submit_sm r, err := rw.Read() if err != nil { t.Fatal(err) } want, have := *p.Header(), *r.Header() if want != have { t.Fatalf("unexpected header: want %#v, have %#v", want, have) } for k, v := range p.Fields() { vv, exists := r.Fields()[k] if !exists { t.Fatalf("unexpected fields: want %#v, have %#v", p.Fields(), r.Fields()) } if !bytes.Equal(v.Bytes(), vv.Bytes()) { t.Fatalf("unexpected field data: want %#v, have %#v", v, vv) } } }
func (t *Transmitter) bindFunc(c Conn) error { p := pdu.NewBindTransmitter() f := p.Fields() f.Set(pdufield.SystemID, t.User) f.Set(pdufield.Password, t.Passwd) f.Set(pdufield.SystemType, t.SystemType) resp, err := bind(c, p) if err != nil { return err } if resp.Header().ID != pdu.BindTransmitterRespID { return fmt.Errorf("unexpected response for BindTransmitter: %s", resp.Header().ID) } go t.handlePDU(nil) return nil }
func TestConn(t *testing.T) { s := smpptest.NewServer() defer s.Close() c, err := Dial(s.Addr(), nil) if err != nil { t.Fatal(err) } defer c.Close() p := pdu.NewBindTransmitter() f := p.Fields() f.Set(pdufield.SystemID, smpptest.DefaultUser) f.Set(pdufield.Password, smpptest.DefaultPasswd) f.Set(pdufield.InterfaceVersion, 0x34) if err = c.Write(p); err != nil { t.Fatal(err) } if _, err = c.Read(); err != nil { t.Fatal(err) } }