[Pyobjc-dev] unittests for C code
Brought to you by:
ronaldoussoren
From: Ronald O. <ous...@ci...> - 2003-09-03 14:37:23
|
Hi, I just ran into a problem w.r.t. converting some structs to/from Objective-C. It turns out that the code in objc_support.m isn't entirely correct, especially for structs that are not carefully layed out by the programmer. Specifically: struct Foo { int i; double d; short s[5]; }; The sizeof(struct Foo) is different from objc_sizeof_type(@encode(struct Foo)). The best way to test if this code is correct would be to write some unittests in C. I'm thinking of adding a extension module containing those unittests. Every test would be in a function, and would raise AssertionError when the tests fails, just like the code in unittest.py. A header-file would create some usefull definitions that make it easier to write these tests. The tests I'll add: - Convert Python to struct, and check the struct value (and likewise for other ObjC values) - Convert struct to Python, and check the Python value ( ,,, ) - Check objc_sizeof_type, objc_alignof_type, ... Adding these as unittests makes debugging slightly easier, I currently get core-dumps in test_methods2 (when I add testcases for the struct mentioned above). Is there pre-existing code for this, or should I just write this from scratch. The problem looks easy enough to just write from scratch. I'd also like opionions regarding delaying the 1.0 release because of this problem. Ronald |