func TestExportSubtree_exportPrecedence(t *testing.T) {
	connection, err := SessionBus()
	if err != nil {
		t.Fatalf("Unexpected error connecting to session bus: %s", err)
	}
	name := connection.Names()[0]
	connection.ExportSubtree(&fooExport{},
		"/org/guelfey/DBus/Test", "org.guelfey.DBus.Test")
	connection.Export(&barExport{}, "/org/guelfey/DBus/Test/Foo",
		"org.guelfey.DBus.Test")
	object := connection.Object(name, "/org/guelfey/DBus/Test/Foo")
	var response string
	err = object.Call("org.guelfey.DBus.Test.Foo", 0, "qux").Store(&response)
	if err != nil {
		t.Errorf("Unexpected error calling Foo: %s", err)
	}
	if response != "bar" {
		t.Errorf(`Response was %s, expected "bar"`, response)
	}
	response = ""  
	connection.Export(nil, "/org/guelfey/DBus/Test/Foo", "org.guelfey.DBus.Test")
	err = object.Call("org.guelfey.DBus.Test.Foo", 0, "qux").Store(&response)
	if err != nil {
		t.Errorf("Unexpected error calling Foo: %s", err)
	}
	if response != "foo" {
		t.Errorf(`Response was %s, expected "foo"`, response)
	}
}
Test that a regular Export takes precedence over ExportSubtree.
package dbus
import (
	"fmt"
	"regexp"
	"strings"
	"testing"
)
type lowerCaseExport struct{}
func (export lowerCaseExport) foo() (string, *Error) {
	return "bar", nil
}
type fooExport struct {
	message Message
}
func (export *fooExport) Foo(message Message, param string) (string, *Error) {
	export.message = message
	return "foo", nil
}
type barExport struct{}
func (export barExport) Foo(param string) (string, *Error) {
	return "bar", nil
}
type badExport struct{}
func (export badExport) Foo(param string) string {
	return "bar"
}
func TestExport(t *testing.T) {
	connection, err := SessionBus()
	if err != nil {
		t.Fatalf("Unexpected error connecting to session bus: %s", err)
	}
	name := connection.Names()[0]
	connection.Export(server{}, "/org/guelfey/DBus/Test", "org.guelfey.DBus.Test")
	object := connection.Object(name, "/org/guelfey/DBus/Test")
	subtreeObject := connection.Object(name, "/org/guelfey/DBus/Test/Foo")
	var response int64
	err = object.Call("org.guelfey.DBus.Test.Double", 0, int64(2)).Store(&response)
	if err != nil {
		t.Errorf("Unexpected error calling Double: %s", err)
	}
	if response != 4 {
		t.Errorf("Response was %d, expected 4", response)
	}
	err = subtreeObject.Call("org.guelfey.DBus.Test.Double", 0, int64(2)).Store(&response)
	if err == nil {
		t.Error("Expected error due to no object being exported on that path")
	}
	connection.Export(nil, "/org/guelfey/DBus/Test", "org.guelfey.DBus.Test")
	err = object.Call("org.guelfey.DBus.Test.Double", 0, int64(2)).Store(&response)
	if err == nil {
		t.Error("Expected an error since the export was removed")
	}
}
func TestExport_message(t *testing.T) {
	connection, err := SessionBus()
	if err != nil {
		t.Fatalf("Unexpected error connecting to session bus: %s", err)
	}
	name := connection.Names()[0]
	export := &fooExport{}
	connection.Export(export, "/org/guelfey/DBus/Test", "org.guelfey.DBus.Test")
	object := connection.Object(name, "/org/guelfey/DBus/Test")
	var response string
	err = object.Call("org.guelfey.DBus.Test.Foo", 0, "qux").Store(&response)
	if err != nil {
		t.Errorf("Unexpected error calling Foo: %s", err)
	}
	if response != "foo" {
		t.Errorf(`Response was %s, expected "foo"`, response)
	}
	if export.message.serial == 0 {
		t.Error("Expected a valid message to be given to handler")
	}
}
func TestExport_invalidPath(t *testing.T) {
	connection, err := SessionBus()
	if err != nil {
		t.Fatalf("Unexpected error connecting to session bus: %s", err)
	}
	err = connection.Export(nil, "foo", "bar")
	if err == nil {
		t.Error("Expected an error due to exporting with an invalid path")
	}
}
func TestExport_unexportedMethod(t *testing.T) {
	connection, err := SessionBus()
	if err != nil {
		t.Fatalf("Unexpected error connecting to session bus: %s", err)
	}
	name := connection.Names()[0]
	connection.Export(lowerCaseExport{}, "/org/guelfey/DBus/Test", "org.guelfey.DBus.Test")
	object := connection.Object(name, "/org/guelfey/DBus/Test")
	var response string
	call := object.Call("org.guelfey.DBus.Test.foo", 0)
	err = call.Store(&response)
	if err == nil {
		t.Errorf("Expected an error due to calling unexported method")
	}
}
func TestExport_badSignature(t *testing.T) {
	connection, err := SessionBus()
	if err != nil {
		t.Fatalf("Unexpected error connecting to session bus: %s", err)
	}
	name := connection.Names()[0]
	connection.Export(badExport{}, "/org/guelfey/DBus/Test", "org.guelfey.DBus.Test")
	object := connection.Object(name, "/org/guelfey/DBus/Test")
	var response string
	call := object.Call("org.guelfey.DBus.Test.Foo", 0)
	err = call.Store(&response)
	if err == nil {
		t.Errorf("Expected an error due to the method lacking the right signature")
	}
}
func TestExportWithMap(t *testing.T) {
	connection, err := SessionBus()
	if err != nil {
		t.Fatalf("Unexpected error connecting to session bus: %s", err)
	}
	name := connection.Names()[0]
	mapping := make(map[string]string)
	mapping["Double"] = "double"  
	connection.ExportWithMap(server{}, mapping, "/org/guelfey/DBus/Test", "org.guelfey.DBus.Test")
	object := connection.Object(name, "/org/guelfey/DBus/Test")
	var response int64
	err = object.Call("org.guelfey.DBus.Test.double", 0, int64(2)).Store(&response)
	if err != nil {
		t.Errorf("Unexpected error calling double: %s", err)
	}
	if response != 4 {
		t.Errorf("Response was %d, expected 4", response)
	}
}
func TestExportWithMap_bypassAlias(t *testing.T) {
	connection, err := SessionBus()
	if err != nil {
		t.Fatalf("Unexpected error connecting to session bus: %s", err)
	}
	name := connection.Names()[0]
	mapping := make(map[string]string)
	mapping["Double"] = "double"  
	connection.ExportWithMap(server{}, mapping, "/org/guelfey/DBus/Test", "org.guelfey.DBus.Test")
	object := connection.Object(name, "/org/guelfey/DBus/Test")
	var response int64
	err = object.Call("org.guelfey.DBus.Test.Double", 0, int64(2)).Store(&response)
	if err == nil {
		t.Error("Expected an error due to calling actual method, not alias")
	}
}
func TestExportSubtree(t *testing.T) {
	connection, err := SessionBus()
	if err != nil {
		t.Fatalf("Unexpected error connecting to session bus: %s", err)
	}
	name := connection.Names()[0]
	export := &fooExport{}
	connection.ExportSubtree(export, "/org/guelfey/DBus/Test", "org.guelfey.DBus.Test")
	object := connection.Object(name, "/org/guelfey/DBus/Test/Foo")
	var response string
	err = object.Call("org.guelfey.DBus.Test.Foo", 0, "qux").Store(&response)
	if err != nil {
		t.Errorf("Unexpected error calling Foo: %s", err)
	}
	if response != "foo" {
		t.Errorf(`Response was %s, expected "foo"`, response)
	}
	if export.message.serial == 0 {
		t.Error("Expected the raw message, got an invalid one")
	}
	connection.Export(nil, "/org/guelfey/DBus/Test", "org.guelfey.DBus.Test")
	err = object.Call("org.guelfey.DBus.Test.Foo", 0, "qux").Store(&response)
	if err == nil {
		t.Error("Expected an error since the export was removed")
	}
}
func TestExportSubtree_noMessage(t *testing.T) {
	connection, err := SessionBus()
	if err != nil {
		t.Fatalf("Unexpected error connecting to session bus: %s", err)
	}
	name := connection.Names()[0]
	connection.ExportSubtree(server{}, "/org/guelfey/DBus/Test", "org.guelfey.DBus.Test")
	object := connection.Object(name, "/org/guelfey/DBus/Test/Foo")
	var response int64
	err = object.Call("org.guelfey.DBus.Test.Double", 0, int64(2)).Store(&response)
	if err != nil {
		t.Errorf("Unexpected error calling Double: %s", err)
	}
	if response != 4 {
		t.Errorf("Response was %d, expected 4", response)
	}
	connection.Export(nil, "/org/guelfey/DBus/Test", "org.guelfey.DBus.Test")
	err = object.Call("org.guelfey.DBus.Test.Double", 0, int64(2)).Store(&response)
	if err == nil {
		t.Error("Expected an error since the export was removed")
	}
}