summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xlib/zephyr_tests.py8
-rw-r--r--lib/zephyr_tests.txt27
2 files changed, 35 insertions, 0 deletions
diff --git a/lib/zephyr_tests.py b/lib/zephyr_tests.py
index e78e2a2..bfd2901 100755
--- a/lib/zephyr_tests.py
+++ b/lib/zephyr_tests.py
@@ -68,6 +68,11 @@ class Enum(c_int):
except IndexError:
return ["unknown enum value(%d)" % (self.value)]
+def populate_enum(cls):
+ """make members for each of the enum values"""
+ for value, tag in enumerate(cls._values_):
+ setattr(cls, tag, cls(value))
+
# not really an enum, but we get a richer effect by treating it as one
class Enum_u16(c_uint16):
def pformat(self):
@@ -127,6 +132,8 @@ class AF_(Enum_u16):
_socket_af = dict([(v,n) for n,v in socket.__dict__.items() if n.startswith("AF_")])
_values_ = [_socket_af.get(k, "unknown address family") for k in range(min(_socket_af), max(_socket_af)+1)]
+populate_enum(AF_)
+
class sockaddr(Structure):
_fields_ = [
("sa_family", AF_),
@@ -171,6 +178,7 @@ class ZNotice_Kind_t(Enum):
_values_ = [
"UNSAFE", "UNACKED", "ACKED", "HMACK", "HMCTL", "SERVACK", "SERVNAK", "CLIENTACK", "STAT",
]
+populate_enum(ZNotice_Kind_t)
def pformat_timeval(tv_sec, tv_usec):
"""format timeval parts as seconds and human-readable time"""
diff --git a/lib/zephyr_tests.txt b/lib/zephyr_tests.txt
index af429f8..8bd5e0b 100644
--- a/lib/zephyr_tests.txt
+++ b/lib/zephyr_tests.txt
@@ -52,6 +52,33 @@ settings and assertions to be a real round-trip test...)
Should we check for ZEPH0.2 now, or leave that open?
+ >>> notice = zephyr_tests.ZNotice_t()
+ >>> notice.z_kind = zephyr_tests.ZNotice_Kind_t.UNSAFE
+ >>> notice.z_class = c_char_p("testclass")
+ >>> notice.z_class_inst = c_char_p("testinstance")
+ >>> notice.z_opcode = c_char_p("TESTOPCODE")
+ >>> notice.z_sender = c_char_p("someone")
+ >>> notice.z_recipient = c_char_p("someone_else")
+ >>> notice.z_message = c_char_p("short message body")
+ >>> notice.z_message_len = c_int(len("short message body"))
+ >>> zbuf = c_char_p(0)
+ >>> zbuflen = c_int(0)
+ >>> st = _z.ZFormatNotice(notice, zbuf, zbuflen, zephyr_tests.ZNOAUTH)
+ >>> assert st == 0
+ >>> assert zbuf.value.startswith("ZEPH")
+ >>> new_notice = zephyr_tests.ZNotice_t()
+ >>> st = _z.ZParseNotice(zbuf, zbuflen, new_notice)
+ >>> assert st == 0
+ >>> assert new_notice.z_version.startswith("ZEPH")
+ >>> new_notice.z_class
+ 'testclass'
+ >>> new_notice.z_class_inst
+ 'testinstance'
+ >>> new_notice.z_opcode
+ 'TESTOPCODE'
+ >>> new_notice.z_message[:new_notice.z_message_len]
+ 'short message body'
+
Simple test of ZCompareUID:
>>> uid1 = zephyr_tests.ZUnique_Id_t()