Agreed; a unit test of pack() and unpack() should not be concerned with the actual bytes of platform-dependent packings unless there is an independent, bug-free way of doing the packs and unpacks on that platform. The following would be good tests for the above formats:
$x = pack($format, $original);
ok($original == unpack($format, $x),
'reversible unpack');
$x = external_platform_pack($format, $original);
ok($original == unpack($format, $x),
'unpack from platform-specific source');
$x = pack($format, $original);
ok($original == external_platform_unpack($format, $x),
'pack to platform-specific source');
Only the first one is devoid of platform-dependence. Of course, a diverse pool of $original value samples should be run.
-- [ e d @ h a l l e y . c c ]
|