summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorUlf <ulf.hofemeier@intel.com>2012-10-15 08:48:33 -0700
committerUlf <ulf.hofemeier@intel.com>2012-10-15 08:48:33 -0700
commitea5e13a057fdebdcc293c9da0b6544187ed0596f (patch)
treeb56b2772983e28566121a5109300be28eeba6add /test
downloadneard-ea5e13a057fdebdcc293c9da0b6544187ed0596f.tar.gz
neard-ea5e13a057fdebdcc293c9da0b6544187ed0596f.tar.bz2
neard-ea5e13a057fdebdcc293c9da0b6544187ed0596f.zip
Diffstat (limited to 'test')
-rwxr-xr-xtest/bt-handover69
-rwxr-xr-xtest/disable-adapter23
-rwxr-xr-xtest/dump-device30
-rwxr-xr-xtest/dump-record24
-rwxr-xr-xtest/dump-tag45
-rwxr-xr-xtest/enable-adapter23
-rwxr-xr-xtest/list-adapters40
-rwxr-xr-xtest/monitor-near62
-rw-r--r--test/push-device48
-rwxr-xr-xtest/simple-agent61
-rwxr-xr-xtest/start-poll30
-rwxr-xr-xtest/stop-poll23
-rw-r--r--test/write-tag43
13 files changed, 521 insertions, 0 deletions
diff --git a/test/bt-handover b/test/bt-handover
new file mode 100755
index 0000000..95b6dbf
--- /dev/null
+++ b/test/bt-handover
@@ -0,0 +1,69 @@
+#!/usr/bin/python
+
+import os
+import sys
+import gobject
+
+import dbus
+import dbus.mainloop.glib
+
+from dbus.lowlevel import MethodCallMessage, HANDLER_RESULT_NOT_YET_HANDLED
+
+mainloop = gobject.MainLoop()
+
+def property_changed_adapter(name, value, path):
+ if name in ["Devices"]:
+ if (len(value) == 0):
+ print "Lost device, exiting"
+ mainloop.quit()
+ else:
+ device_path = value[0]
+
+ print "Pairing with %s" % (device_path)
+
+ device = dbus.Interface(bus.get_object("org.neard", device_path), "org.neard.Device")
+ device.Push(({ "Type" : "Handover", "Carrier" : "bluetooth"}))
+
+if __name__ == '__main__':
+ dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
+
+ bus = dbus.SystemBus()
+
+ bluez_manager = dbus.Interface(bus.get_object("org.bluez", "/"), "org.bluez.Manager")
+
+ bluez_adapter_path = bluez_manager.DefaultAdapter()
+
+ bluez_adapter = dbus.Interface(bus.get_object("org.bluez", bluez_adapter_path),
+ "org.bluez.Adapter")
+
+ for bluez_path in bluez_adapter.ListDevices():
+ print("Removing %s" % (bluez_path))
+ bluez_adapter.RemoveDevice(bluez_path)
+
+
+ manager = dbus.Interface(bus.get_object("org.neard", "/"),
+ "org.neard.Manager")
+
+ properties = manager.GetProperties()
+ device_path = properties["Adapters"][0]
+ adapter = dbus.Interface(bus.get_object("org.neard", device_path),
+ "org.neard.Adapter")
+
+ adapter_properties = adapter.GetProperties()
+
+ for key in adapter_properties.keys():
+ if key in ["Polling"]:
+ if adapter_properties[key] == dbus.Boolean(1):
+ print "Stoping poll on %s" % (device_path)
+ adapter.StopPollLoop()
+
+ print "Starting poll on %s" % (device_path)
+ adapter.StartPollLoop("Initiator")
+
+ bus.add_signal_receiver(property_changed_adapter,
+ bus_name="org.neard",
+ dbus_interface="org.neard.Adapter",
+ signal_name = "PropertyChanged",
+ path_keyword="path")
+
+ mainloop.run()
diff --git a/test/disable-adapter b/test/disable-adapter
new file mode 100755
index 0000000..fe514ff
--- /dev/null
+++ b/test/disable-adapter
@@ -0,0 +1,23 @@
+#!/usr/bin/python
+
+import sys
+import dbus
+
+if len(sys.argv) < 2:
+ print "Usage: %s <nfc device>" % (sys.argv[0])
+ sys.exit(1)
+
+bus = dbus.SystemBus()
+
+manager = dbus.Interface(bus.get_object("org.neard", "/"),
+ "org.neard.Manager")
+
+
+path = "/org/neard/" + sys.argv[1]
+adapter = dbus.Interface(bus.get_object("org.neard", path),
+ "org.neard.Adapter")
+
+try:
+ adapter.SetProperty("Powered", dbus.Boolean(0), timeout = 10)
+except dbus.DBusException, error:
+ print "%s: %s" % (error._dbus_error_name, error.message) \ No newline at end of file
diff --git a/test/dump-device b/test/dump-device
new file mode 100755
index 0000000..58b090c
--- /dev/null
+++ b/test/dump-device
@@ -0,0 +1,30 @@
+#!/usr/bin/python
+
+import sys
+import dbus
+
+bus = dbus.SystemBus()
+
+def extract_record(key, list):
+ for i in list:
+ record = dbus.Interface(bus.get_object("org.neard", i),
+ "org.neard.Record")
+
+ properties = record.GetProperties()
+ print " Record = [ %s ]" % (str(i))
+
+ for key in properties.keys():
+ val = str(properties[key])
+ print " %s = %s" % (key, val)
+
+device = dbus.Interface(bus.get_object("org.neard", sys.argv[1]),
+ "org.neard.Device")
+
+properties = device.GetProperties()
+
+print "[ %s ]" % (sys.argv[1])
+
+for key in properties.keys():
+ if key in ["Records"]:
+ extract_record(key, properties[key])
+
diff --git a/test/dump-record b/test/dump-record
new file mode 100755
index 0000000..8cf3cb1
--- /dev/null
+++ b/test/dump-record
@@ -0,0 +1,24 @@
+#!/usr/bin/python
+
+import sys
+import dbus
+
+def extract_list(list):
+ val = "["
+ for i in list:
+ val += " " + str(i)
+ val += " ]"
+ return val
+
+bus = dbus.SystemBus()
+
+record = dbus.Interface(bus.get_object("org.neard", sys.argv[1]),
+ "org.neard.Record")
+
+properties = record.GetProperties()
+
+print "[ %s ]" % (sys.argv[1])
+
+for key in properties.keys():
+ val = str(properties[key])
+ print " %s = %s" % (key, val)
diff --git a/test/dump-tag b/test/dump-tag
new file mode 100755
index 0000000..8ce8d6b
--- /dev/null
+++ b/test/dump-tag
@@ -0,0 +1,45 @@
+#!/usr/bin/python
+
+import sys
+import dbus
+
+bus = dbus.SystemBus()
+
+def extract_list(list):
+ val = "["
+ for i in list:
+ val += " " + str(i)
+ val += " ]"
+
+ return val
+
+def extract_record(key, list):
+ for i in list:
+ record = dbus.Interface(bus.get_object("org.neard", i),
+ "org.neard.Record")
+
+ properties = record.GetProperties()
+ print " Record = [ %s ]" % (str(i))
+
+ for key in properties.keys():
+ val = str(properties[key])
+ print " %s = %s" % (key, val)
+
+tag = dbus.Interface(bus.get_object("org.neard", sys.argv[1]),
+ "org.neard.Tag")
+
+properties = tag.GetProperties()
+
+print "[ %s ]" % (sys.argv[1])
+
+for key in properties.keys():
+ if key in ["Type"]:
+ val = str(properties[key])
+ print " %s = %s" % (key, val)
+ elif key in ["Protocol"]:
+ val = str(properties[key])
+ print " %s = %s" % (key, val)
+
+ if key in ["Records"]:
+ extract_record(key, properties[key])
+
diff --git a/test/enable-adapter b/test/enable-adapter
new file mode 100755
index 0000000..bd6f03a
--- /dev/null
+++ b/test/enable-adapter
@@ -0,0 +1,23 @@
+#!/usr/bin/python
+
+import sys
+import dbus
+
+if len(sys.argv) < 2:
+ print "Usage: %s <nfc device>" % (sys.argv[0])
+ sys.exit(1)
+
+bus = dbus.SystemBus()
+
+manager = dbus.Interface(bus.get_object("org.neard", "/"),
+ "org.neard.Manager")
+
+
+path = "/org/neard/" + sys.argv[1]
+adapter = dbus.Interface(bus.get_object("org.neard", path),
+ "org.neard.Adapter")
+
+try:
+ adapter.SetProperty("Powered", dbus.Boolean(1), timeout = 10)
+except dbus.DBusException, error:
+ print "%s: %s" % (error._dbus_error_name, error.message)
diff --git a/test/list-adapters b/test/list-adapters
new file mode 100755
index 0000000..9e11322
--- /dev/null
+++ b/test/list-adapters
@@ -0,0 +1,40 @@
+#!/usr/bin/python
+
+import dbus
+
+
+def extract_list(list):
+ val = "["
+ for i in list:
+ val += " " + str(i)
+ val += " ]"
+ return val
+
+bus = dbus.SystemBus()
+
+manager = dbus.Interface(bus.get_object("org.neard", "/"),
+ "org.neard.Manager")
+
+
+properties = manager.GetProperties()
+
+for path in properties["Adapters"]:
+ print "[ %s ]" % (path)
+
+ adapter = dbus.Interface(bus.get_object("org.neard", path),
+ "org.neard.Adapter")
+
+ properties = adapter.GetProperties()
+
+ for key in properties.keys():
+ if key in ["Powered", "Polling"]:
+ if properties[key] == dbus.Boolean(1):
+ val = "true"
+ else:
+ val = "false"
+ elif key in ["Protocols", "Tags", "Devices"]:
+ val = extract_list(properties[key])
+ else:
+ val = str(properties[key])
+
+ print " %s = %s" % (key, val)
diff --git a/test/monitor-near b/test/monitor-near
new file mode 100755
index 0000000..fef307e
--- /dev/null
+++ b/test/monitor-near
@@ -0,0 +1,62 @@
+#!/usr/bin/python
+
+import gobject
+
+import dbus
+import dbus.mainloop.glib
+
+from dbus.lowlevel import MethodCallMessage, HANDLER_RESULT_NOT_YET_HANDLED
+
+def extract_list(list):
+ val = "["
+ for i in list:
+ val += " " + str(i)
+ val += " ]"
+ return val
+
+def extract_bool(b):
+ if b == dbus.Boolean(1):
+ val = "true"
+ else:
+ val = "false"
+ return val
+
+
+def property_changed_adapter(name, value, path):
+ adapter = path[path.rfind("/") + 1:]
+ if name in ["Polling"]:
+ val = extract_bool(value)
+ elif name in ["Tags", "Devices"]:
+ val = extract_list(value)
+ else:
+ val = str(value)
+
+ print "[Adapter] [%s] %s = %s" % (adapter, name, val)
+
+def property_changed_manager(name, value, path):
+ manager = path[path.rfind("/") + 1:]
+ if name in ["Adapters"]:
+ val = extract_list(value)
+
+ print "[Manager] %s = %s" % (name, val)
+
+
+if __name__ == '__main__':
+ dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
+
+ bus = dbus.SystemBus()
+
+ bus.add_signal_receiver(property_changed_manager,
+ bus_name="org.neard",
+ dbus_interface="org.neard.Manager",
+ signal_name = "PropertyChanged",
+ path_keyword="path")
+
+ bus.add_signal_receiver(property_changed_adapter,
+ bus_name="org.neard",
+ dbus_interface="org.neard.Adapter",
+ signal_name = "PropertyChanged",
+ path_keyword="path")
+
+ mainloop = gobject.MainLoop()
+ mainloop.run()
diff --git a/test/push-device b/test/push-device
new file mode 100644
index 0000000..614f4fa
--- /dev/null
+++ b/test/push-device
@@ -0,0 +1,48 @@
+#!/usr/bin/python
+
+import sys
+import dbus
+
+def help_text():
+ print "Usage: %s <device-path> <record-type> <...>" % (sys.argv[0])
+ print " If type is Text, parameters are <encoding> <language> <representation>"
+ print " If type is URI, parameters are <uri>"
+ print " If type is SmartPoster, parameters are <uri>"
+ print " If type is Handover, parameters are <carrier>"
+ print "e.g. < %s /org/neard/nfc0/device0 Text UTF-8 en-US hello,Type2! >" % (sys.argv[0])
+ print "e.g. < %s /org/neard/nfc0/device0 URI http://www.nfc-forum.com >" % (sys.argv[0])
+ print "e.g. < %s /org/neard/nfc0/device0 SmartPoster http://www.nfc-forum.com >" % (sys.argv[0])
+ print "e.g. < %s /org/neard/nfc0/device0 Handover bluetooth >" % (sys.argv[0])
+ sys.exit(1)
+
+if len(sys.argv) < 2:
+ help_text()
+
+bus = dbus.SystemBus()
+
+device = dbus.Interface(bus.get_object("org.neard", sys.argv[1]),
+ "org.neard.Device")
+
+if len(sys.argv) == 6:
+ if sys.argv[2] in ["Text"]:
+ device.Push(({ "Type" : "Text",
+ "Encoding" : sys.argv[3],
+ "Language" : sys.argv[4],
+ "Representation" : sys.argv[5] }))
+ else:
+ help_text()
+
+elif len(sys.argv) == 4:
+ if sys.argv[2] in ["URI"]:
+ device.Push(({ "Type" : "URI",
+ "URI" : sys.argv[3] }))
+ elif sys.argv[2] in ["SmartPoster"]:
+ device.Push(({ "Type" : "SmartPoster",
+ "URI" : sys.argv[3] }))
+ elif sys.argv[2] in ["Handover"]:
+ device.Push(({ "Type" : "Handover",
+ "Carrier" : sys.argv[3] }))
+ else:
+ help_text()
+else:
+ help_text()
diff --git a/test/simple-agent b/test/simple-agent
new file mode 100755
index 0000000..4db0a9f
--- /dev/null
+++ b/test/simple-agent
@@ -0,0 +1,61 @@
+#!/usr/bin/python
+
+import gobject
+
+import dbus
+import dbus.service
+import dbus.mainloop.glib
+import sys
+
+class NDEFAgent(dbus.service.Object):
+
+ @dbus.service.method("org.neard.NDEFAgent",
+ in_signature='', out_signature='')
+ def Release(self):
+ print "Release"
+ mainloop.quit()
+
+ @dbus.service.method("org.neard.NDEFAgent",
+ in_signature='a{sv}',
+ out_signature='')
+ def GetNDEF(self, fields):
+ print "GetNDEF"
+
+ if fields.has_key("Records"):
+ for path in fields["Records"]:
+ print "Record path %s" % (path)
+
+ return
+
+ @dbus.service.method("org.neard.NDEFAgent",
+ in_signature='', out_signature='')
+ def Cancel(self):
+ print "Cancel"
+
+def print_usage():
+ print "Usage:"
+ print "For NDEF agent:"
+ print "%s NDEF Type=<record type>" % (sys.argv[0])
+ print "Help: %s help" % (sys.argv[0])
+ sys.exit(1)
+
+if __name__ == '__main__':
+ if len(sys.argv) == 2 and sys.argv[1] == "help":
+ print_usage()
+
+ dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
+
+ bus = dbus.SystemBus()
+ manager = dbus.Interface(bus.get_object('org.neard', "/"),
+ 'org.neard.Manager')
+
+ if len(sys.argv) > 2:
+ if sys.argv[1] == "NDEF":
+ path = "/test/ndef/agent"
+ object = NDEFAgent(bus, path)
+ rec_type = sys.argv[2].replace("Type=", "", 1)
+
+ manager.RegisterNDEFAgent(path, rec_type)
+
+ mainloop = gobject.MainLoop()
+ mainloop.run()
diff --git a/test/start-poll b/test/start-poll
new file mode 100755
index 0000000..858597b
--- /dev/null
+++ b/test/start-poll
@@ -0,0 +1,30 @@
+#!/usr/bin/python
+
+import sys
+import dbus
+
+if len(sys.argv) < 2:
+ print "Usage: %s [nfc device] <polling mode>" % (sys.argv[0])
+ sys.exit(1)
+
+if len(sys.argv) < 3:
+ mode = "Initiator"
+else:
+ mode = sys.argv[2]
+
+bus = dbus.SystemBus()
+
+manager = dbus.Interface(bus.get_object("org.neard", "/"),
+ "org.neard.Manager")
+
+
+print "Polling Mode %s" % (mode)
+
+path = "/org/neard/" + sys.argv[1]
+adapter = dbus.Interface(bus.get_object("org.neard", path),
+ "org.neard.Adapter")
+
+try:
+ adapter.StartPollLoop(mode)
+except dbus.DBusException, error:
+ print "%s: %s" % (error._dbus_error_name, error.message)
diff --git a/test/stop-poll b/test/stop-poll
new file mode 100755
index 0000000..5ef2ef9
--- /dev/null
+++ b/test/stop-poll
@@ -0,0 +1,23 @@
+#!/usr/bin/python
+
+import sys
+import dbus
+
+if len(sys.argv) < 2:
+ print "Usage: %s <nfc device>" % (sys.argv[0])
+ sys.exit(1)
+
+bus = dbus.SystemBus()
+
+manager = dbus.Interface(bus.get_object("org.neard", "/"),
+ "org.neard.Manager")
+
+
+path = "/org/neard/" + sys.argv[1]
+adapter = dbus.Interface(bus.get_object("org.neard", path),
+ "org.neard.Adapter")
+
+try:
+ adapter.StopPollLoop()
+except dbus.DBusException, error:
+ print "%s: %s" % (error._dbus_error_name, error.message)
diff --git a/test/write-tag b/test/write-tag
new file mode 100644
index 0000000..aec413f
--- /dev/null
+++ b/test/write-tag
@@ -0,0 +1,43 @@
+#!/usr/bin/python
+
+import sys
+import dbus
+
+def help_text():
+ print "Usage: %s <tag-path> <record-type> <...>" % (sys.argv[0])
+ print " If type is Text, parameters are <encoding> <language> <representation>"
+ print " If type is URI, parameters are <uri>"
+ print " If type is SmartPoster, parameters are <uri>"
+ print "e.g. < %s /org/neard/nfc0/tag0 Text UTF-8 en-US hello,Type2! >" % (sys.argv[0])
+ print "e.g. < %s /org/neard/nfc0/tag0 URI http://www.nfc-forum.com >" % (sys.argv[0])
+ print "e.g. < %s /org/neard/nfc0/tag0 SmartPoster http://www.nfc-forum.com >" % (sys.argv[0])
+ sys.exit(1)
+
+if len(sys.argv) < 2:
+ help_text()
+
+bus = dbus.SystemBus()
+
+tag = dbus.Interface(bus.get_object("org.neard", sys.argv[1]),
+ "org.neard.Tag")
+
+if len(sys.argv) == 6:
+ if sys.argv[2] in ["Text"]:
+ tag.Write(({ "Type" : "Text",
+ "Encoding" : sys.argv[3],
+ "Language" : sys.argv[4],
+ "Representation" : sys.argv[5] }))
+ else:
+ help_text()
+
+elif len(sys.argv) == 4:
+ if sys.argv[2] in ["URI"]:
+ tag.Write(({ "Type" : "URI",
+ "URI" : sys.argv[3] }))
+ elif sys.argv[2] in ["SmartPoster"]:
+ tag.Write(({ "Type" : "SmartPoster",
+ "URI" : sys.argv[3] }))
+ else:
+ help_text()
+else:
+ help_text() \ No newline at end of file