From 951cd1a9df71dfc0f4aeffa362d9c691ba651f86 Mon Sep 17 00:00:00 2001 From: "Mark W. Eichin" Date: Thu, 9 Apr 2009 03:28:45 +0000 Subject: move run from ZephyrTestSuite to TestSuite where it belongs (easier to replace that way too) add starting/done/failed to TestSuite.run output wrap ZCompareUID test ZCompareUID --- lib/zephyr_tests.py | 60 ++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 48 insertions(+), 12 deletions(-) (limited to 'lib/zephyr_tests.py') diff --git a/lib/zephyr_tests.py b/lib/zephyr_tests.py index 0aa4ffb..020f0a6 100755 --- a/lib/zephyr_tests.py +++ b/lib/zephyr_tests.py @@ -84,6 +84,22 @@ class TestSuite(object): for k, v in kwargs.items(): setattr(self, k, v) + def run(self): + tests = sorted([testname for testname in dir(self) + if testname.startswith("test_")]) + failures = [] + for test in tests: + try: + print "===", "starting", test, "===" + getattr(self, test)() + print "===", "done", test, "===" + except TestFailure, tf: + print "===", "FAILED", test, "===" + failures.append([test, tf]) + + return failures + + class TestFailure(Exception): pass @@ -305,6 +321,7 @@ class libZephyr(object): "Z_FormatRawHeader", "ZParseNotice", "ZFormatNotice", + "ZCompareUID", ] def __init__(self, library_path=None): """connect to the library and build the wrappers""" @@ -361,6 +378,14 @@ class libZephyr(object): c_void_p, # cert_routine ] + # int + # ZCompareUID(ZUnique_Id_t *uid1, + # ZUnique_Id_t *uid2) + self.ZCompareUID.argtypes = [ + POINTER(ZUnique_Id_t), # *uid1 + POINTER(ZUnique_Id_t), # *uid2 + ] + # library-specific setup... self.ZInitialize() @@ -377,18 +402,6 @@ class ZephyrTestSuite(TestSuite): libzephyr_path = os.path.join(self.builddir, ".libs", "libzephyr.so.4.0.0") self._libzephyr = libZephyr(libzephyr_path) - def run(self): - tests = sorted([testname for testname in dir(self) - if testname.startswith("test_")]) - failures = [] - for test in tests: - try: - getattr(self, test)() - except TestFailure, tf: - failures.append([test, tf]) - - return failures - def cleanup(self): # no cleanup needed yet pass @@ -418,6 +431,29 @@ class ZephyrTestSuite(TestSuite): print "\tz_version", new_notice.z_version ctypes_pprint(new_notice) + def test_z_compare_uid(self): + """test ZCompareUID""" + + uid1 = ZUnique_Id_t() + uid2 = ZUnique_Id_t() + assert self._libzephyr.ZCompareUID(uid1, uid2), "null uids don't match" + + # there's no ZUnique_Id_t constructor - Z_FormatHeader and Z_NewFormatHeader initialize notice->z_uid directly + notice1 = ZNotice_t() + zbuf = c_char_p(0) + zbuflen = c_int(0) + st = self._libzephyr.ZFormatNotice(notice1, zbuf, zbuflen, ZNOAUTH) + assert st == 0, "ZFormatNotice notice1 failed" + + notice2 = ZNotice_t() + zbuf = c_char_p(0) + zbuflen = c_int(0) + st = self._libzephyr.ZFormatNotice(notice2, zbuf, zbuflen, ZNOAUTH) + assert st == 0, "ZFormatNotice notice2 failed" + + assert not self._libzephyr.ZCompareUID(notice1.z_uid, notice2.z_uid), "distinct notices don't compare as distinct" + # ctypes_pprint(notice1.z_uid) + if __name__ == "__main__": parser = optparse.OptionParser(usage=__doc__, version = "%%prog %s" % __version__) -- cgit v1.2.3