summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Ortiz <sameo@linux.intel.com>2013-11-10 17:43:34 +0100
committerSamuel Ortiz <sameo@linux.intel.com>2013-11-10 17:57:09 +0100
commit196262d4e0a45f3f2262ebaab81edb1427c32aee (patch)
tree821bd58bf5b413a5d8f423f0994f8f8b20c31ed4
parent3174c325913f724408d7dfa457162ddec71b347c (diff)
downloadneard-196262d4e0a45f3f2262ebaab81edb1427c32aee.tar.gz
neard-196262d4e0a45f3f2262ebaab81edb1427c32aee.tar.bz2
neard-196262d4e0a45f3f2262ebaab81edb1427c32aee.zip
test: Add test-device script
-rwxr-xr-xtest/test-device115
1 files changed, 115 insertions, 0 deletions
diff --git a/test/test-device b/test/test-device
new file mode 100755
index 0000000..477ae58
--- /dev/null
+++ b/test/test-device
@@ -0,0 +1,115 @@
+#!/usr/bin/python
+
+import sys
+import dbus
+import neardutils
+
+bus = dbus.SystemBus()
+
+def extract_list(list):
+ val = "["
+ for i in list:
+ val += " " + str(i)
+ val += " ]"
+ return val
+
+def usage():
+ print("Usage: %s <command>" % (sys.argv[0]) )
+ print("")
+ print(" list")
+ print(" dump <device>")
+ print(" push <device> <type> <...>")
+ 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 " If type is StaticHandover, parameters are <carrier>"
+ print " If type is MIME, parameters are <mime_type> (only wifi_wsc and raw)"
+ print " raw is for sending raw payload, parameters are <mime_type> <payload>"
+ print "e.g. < %s push /org/neard/nfc0/device0 Text UTF-8 en-US hello,Type2! >" % (sys.argv[0])
+ print "e.g. < %s push /org/neard/nfc0/device0 URI http://www.nfc-forum.com >" % (sys.argv[0])
+ print "e.g. < %s push /org/neard/nfc0/device0 SmartPoster http://www.nfc-forum.com >" % (sys.argv[0])
+ print "e.g. < %s push /org/neard/nfc0/device0 Handover bluetooth,wifi >" % (sys.argv[0])
+ print "e.g. < %s push /org/neard/nfc0/device0 StaticHandover bluetooth,wifi >" % (sys.argv[0])
+ print "e.g. < %s push /org/neard/nfc0/device0 MIME wifi_wsc>" % (sys.argv[0])
+ print "e.g. < %s push /org/neard/nfc0/device0 MIME raw application/xml '<your><xml tags></your>' >" % (sys.argv[0])
+
+ sys.exit(1)
+
+if (len(sys.argv) < 2):
+ usage()
+
+if (sys.argv[1] == "list"):
+ if (len(sys.argv) < 3):
+ om = dbus.Interface(bus.get_object("org.neard", "/"),
+ "org.freedesktop.DBus.ObjectManager")
+ objects = om.GetManagedObjects()
+ for path, interfaces in objects.iteritems():
+ if "org.neard.Device" not in interfaces:
+ continue
+
+ print(" [ %s ]" % (path))
+
+ sys.exit(0)
+
+if (sys.argv[1] == "dump"):
+ if (len(sys.argv) < 3):
+ om = dbus.Interface(bus.get_object("org.neard", "/"),
+ "org.freedesktop.DBus.ObjectManager")
+ objects = om.GetManagedObjects()
+ for path, interfaces in objects.iteritems():
+ if "org.neard.Device" not in interfaces:
+ continue
+
+ print("[ %s ]" % (path))
+ neardutils.dump_all_records(path)
+
+ sys.exit(0)
+ else:
+ neardutils.dump_all_records(sys.argv[2])
+
+ sys.exit(0)
+
+if (sys.argv[1] == "push"):
+ if (len(sys.argv) < 5):
+ usage()
+
+ device = neardutils.find_device(sys.argv[2])
+
+ if len(sys.argv) == 7:
+ if sys.argv[3] in ["Text"]:
+ device.Push(({ "Type" : "Text",
+ "Encoding" : sys.argv[4],
+ "Language" : sys.argv[5],
+ "Representation" : sys.argv[6] }))
+ elif sys.argv[3] in ["MIME"]:
+ if sys.argv[4] in ["raw"]:
+ device.Push(({ "Type" : "MIME",
+ "MIME" : sys.argv[5],
+ "Payload" : dbus.ByteArray(sys.argv[6]) }))
+ else:
+ usage()
+
+ elif len(sys.argv) == 5:
+ if sys.argv[3] in ["URI"]:
+ device.Push(({ "Type" : "URI",
+ "URI" : sys.argv[4] }))
+ elif sys.argv[3] in ["SmartPoster"]:
+ device.Push(({ "Type" : "SmartPoster",
+ "URI" : sys.argv[4] }))
+ elif sys.argv[3] in ["Handover"]:
+ device.Push(({ "Type" : "Handover",
+ "Carrier" : sys.argv[4] }))
+ elif sys.argv[3] in ["StaticHandover"]:
+ device.Push(({ "Type" : "StaticHandover",
+ "Carrier" : sys.argv[4] }))
+ elif sys.argv[3] in ["MIME"]:
+ if sys.argv[4] in ["wifi_wsc"]:
+ device.Push(({ "Type" : "MIME",
+ "MIME" : "application/vnd.wfa.wsc"}))
+ else:
+ usage()
+ else:
+ usage()
+
+ sys.exit(0)