Skip to content

Commit

Permalink
export: don't call IsValid separately for emitting signals
Browse files Browse the repository at this point in the history
  • Loading branch information
guelfey committed Apr 8, 2023
1 parent 449550c commit 06fc446
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
7 changes: 2 additions & 5 deletions export.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,18 +235,15 @@ func (conn *Conn) Emit(path ObjectPath, name string, values ...interface{}) erro
if len(values) > 0 {
msg.Headers[FieldSignature] = MakeVariant(SignatureOf(values...))
}
if err := msg.IsValid(); err != nil {
return err
}

var closed bool
conn.sendMessageAndIfClosed(msg, func() {
err := conn.sendMessageAndIfClosed(msg, func() {
closed = true
})
if closed {
return ErrClosed
}
return nil
return err
}

// Export registers the given value to be exported as an object on the
Expand Down
14 changes: 14 additions & 0 deletions export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,20 @@ func (export *noErrorExport) Run(message Message, param string) string {
return "cool"
}

// Test that trying to emit an invalid message leads to an error.
func TestEmit_invalidMessage(t *testing.T) {
connection, err := ConnectSessionBus()
if err != nil {
t.Fatalf("Unexpected error connecting to session bus: %s", err)
}
defer connection.Close()

err = connection.Emit("/org/guelfey/DBus/Test", "org.guelfey.DBusTest", "\x00")
if _, ok := err.(FormatError); !ok {
t.Fatal("expected FormatError when emitting invalid message")
}
}

// Test typical Export usage.
func TestExport(t *testing.T) {
connection, err := ConnectSessionBus()
Expand Down

0 comments on commit 06fc446

Please sign in to comment.