summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGravatar Mark W. Eichin <eichin@thok.org>2009-04-17 05:33:49 +0000
committerGravatar Mark W. Eichin <eichin@thok.org>2009-04-17 05:33:49 +0000
commit7dffd27e0267e0585c35c5f1b59497a1431501a3 (patch)
treede7a9c533dfc7177ba76a95b6f69771dacd99da8 /lib
parent15de7f028f59ff0a7cdf3b5457c85b7d74c9b7bf (diff)
basic Zcode test
Diffstat (limited to 'lib')
-rwxr-xr-xlib/zephyr_tests.py17
-rw-r--r--lib/zephyr_tests.txt13
2 files changed, 29 insertions, 1 deletions
diff --git a/lib/zephyr_tests.py b/lib/zephyr_tests.py
index 12864e0..791dccc 100755
--- a/lib/zephyr_tests.py
+++ b/lib/zephyr_tests.py
@@ -326,6 +326,7 @@ class libZephyr(object):
"ZOpenPort",
"ZClosePort",
"ZMakeAscii",
+ "ZMakeZcode",
]
def __init__(self, library_path=None):
"""connect to the library and build the wrappers"""
@@ -418,6 +419,18 @@ class libZephyr(object):
c_int, # num
]
+ # Code_t
+ # ZMakeZcode(register char *ptr,
+ # int len,
+ # unsigned char *field,
+ # int num)
+ self.ZMakeZcode.argtypes = [
+ c_char_p, # ptr
+ c_int, # len
+ c_char_p, # field; c_uchar_p?
+ c_int, # num
+ ]
+
# library-specific setup...
self.ZInitialize()
@@ -430,7 +443,9 @@ def py_make_ascii(input):
output.append("0x" + "".join(hexes[i:i+4]))
return " ".join(output)
-
+def py_make_zcode(input):
+ """reference ZMakeZcode expressed as python..."""
+ return "Z" + input.replace("\xff", "\xff\xf1").replace("\0", "\xff\xf0")
class ZephyrTestSuite(TestSuite):
diff --git a/lib/zephyr_tests.txt b/lib/zephyr_tests.txt
index 5ae3e31..4762c6c 100644
--- a/lib/zephyr_tests.txt
+++ b/lib/zephyr_tests.txt
@@ -131,6 +131,19 @@ A few simple string tests:
>>> zma("jK__\0")
'0x6A4B5F5F 0x00'
+Same thing with ZMakeZcode, a compact binary format that is still NUL-terminated...
+
+ >>> sample = "test\0message"
+ >>> ref = zephyr_tests.py_make_zcode(sample)
+ >>> from ctypes import create_string_buffer
+ >>> outlen = len(sample) * 2
+ >>> outbuf = create_string_buffer(outlen)
+ >>> st = _z.ZMakeZcode(outbuf, outlen, sample, len(sample))
+ >>> assert st == 0
+ >>> assert outbuf.value == ref, "%r != %r" % (outbuf.value, ref)
+
+
+
Coverage:
Files complete: