summaryrefslogtreecommitdiffstats
path: root/test/test-device
diff options
context:
space:
mode:
authorMarcel Holtmann <marcel@holtmann.org>2008-09-01 22:34:04 +0200
committerMarcel Holtmann <marcel@holtmann.org>2008-09-01 22:34:04 +0200
commitcf92b6dc9c0fe11ace1a9ca4e7d18cb411ba56ba (patch)
tree54bfe64770b761a0148972fd9446921d446ef895 /test/test-device
parentb2d5d2c1062af55008c5759c0fee2a1aecd83f66 (diff)
Move test scripts into test directory
Diffstat (limited to 'test/test-device')
-rwxr-xr-xtest/test-device128
1 files changed, 128 insertions, 0 deletions
diff --git a/test/test-device b/test/test-device
new file mode 100755
index 00000000..f8f2d14a
--- /dev/null
+++ b/test/test-device
@@ -0,0 +1,128 @@
+#!/usr/bin/python
+
+import sys
+import dbus
+import re
+
+bus = dbus.SystemBus()
+
+manager = dbus.Interface(bus.get_object("org.bluez", "/"), "org.bluez.Manager")
+
+adapter = dbus.Interface(bus.get_object("org.bluez", manager.DefaultAdapter()),
+ "org.bluez.Adapter")
+
+if (len(sys.argv) < 2):
+ print "Usage: %s <command>" % (sys.argv[0])
+ print ""
+ print " list"
+ print " create <address>"
+ print " remove <address|path>"
+ print " discover <address> [pattern]"
+ print " class <address>"
+ print " name <address>"
+ print " alias <address> [alias]"
+ print " trusted <address> [yes/no]"
+ sys.exit(1)
+
+if (sys.argv[1] == "list"):
+ list = adapter.ListDevices()
+ print list
+ sys.exit(0)
+
+if (sys.argv[1] == "create"):
+ if (len(sys.argv) < 3):
+ print "Need address parameter"
+ else:
+ device = adapter.CreateDevice(sys.argv[2])
+ print device
+ sys.exit(0)
+
+if (sys.argv[1] == "remove"):
+ if (len(sys.argv) < 3):
+ print "Need address or object path parameter"
+ else:
+ try:
+ path = adapter.FindDevice(sys.argv[2])
+ except:
+ path = sys.argv[2]
+ adapter.RemoveDevice(path)
+ sys.exit(0)
+
+if (sys.argv[1] == "discover"):
+ if (len(sys.argv) < 3):
+ print "Need address parameter"
+ else:
+ path = adapter.FindDevice(sys.argv[2])
+ device = dbus.Interface(bus.get_object("org.bluez", path),
+ "org.bluez.Device")
+ if (len(sys.argv) < 4):
+ pattern = ""
+ else:
+ pattern = sys.argv[3]
+ services = device.DiscoverServices(pattern);
+ for key in services.keys():
+ p = re.compile(">.*?<")
+ xml = p.sub("><", services[key].replace("\n", ""))
+ print "[ 0x%5x ]" % (key)
+ print xml
+ print
+ sys.exit(0)
+
+if (sys.argv[1] == "class"):
+ if (len(sys.argv) < 3):
+ print "Need address parameter"
+ else:
+ path = adapter.FindDevice(sys.argv[2])
+ device = dbus.Interface(bus.get_object("org.bluez", path),
+ "org.bluez.Device")
+ properties = device.GetProperties()
+ print "0x%06x" % (properties["Class"])
+ sys.exit(0)
+
+if (sys.argv[1] == "name"):
+ if (len(sys.argv) < 3):
+ print "Need address parameter"
+ else:
+ path = adapter.FindDevice(sys.argv[2])
+ device = dbus.Interface(bus.get_object("org.bluez", path),
+ "org.bluez.Device")
+ properties = device.GetProperties()
+ print properties["Name"]
+ sys.exit(0)
+
+if (sys.argv[1] == "alias"):
+ if (len(sys.argv) < 3):
+ print "Need address parameter"
+ else:
+ path = adapter.FindDevice(sys.argv[2])
+ device = dbus.Interface(bus.get_object("org.bluez", path),
+ "org.bluez.Device")
+ if (len(sys.argv) < 4):
+ properties = device.GetProperties()
+ print properties["Alias"]
+ else:
+ device.SetProperty("Alias", sys.argv[3])
+ sys.exit(0)
+
+if (sys.argv[1] == "trusted"):
+ if (len(sys.argv) < 3):
+ print "Need address parameter"
+ else:
+ path = adapter.FindDevice(sys.argv[2])
+ device = dbus.Interface(bus.get_object("org.bluez", path),
+ "org.bluez.Device")
+ if (len(sys.argv) < 4):
+ properties = device.GetProperties()
+ print properties["Trusted"]
+ else:
+ if (sys.argv[3] == "yes"):
+ value = dbus.Boolean(1)
+ elif (sys.argv[3] == "no"):
+ value = dbus.Boolean(0)
+ else:
+ value = dbus.Boolean(sys.argv[3])
+ device.SetProperty("Trusted", value)
+ sys.exit(0)
+
+print "Unknown command"
+sys.exit(1)