1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
() = evalfile("./test.sl");
require ("zlib");
private define silly_deflate (str)
{
variable z = zlib_deflate_new ();
variable x = "";
foreach (str)
{
variable ch = ();
x = x + _zlib_deflate (z.zobj, pack("C", ch), 0);
}
x = x + z.flush ();
return x;
}
private define silly_inflate (zstr)
{
variable z = zlib_inflate_new ();
variable x = "";
foreach (zstr)
{
variable ch = ();
x = x + _zlib_inflate (z.zobj, pack("C", ch), 0);
}
x = x + z.flush ();
return x;
}
define test_zlib (str0)
{
variable zstr = zlib_deflate (str0);
variable str1 = zlib_inflate (zstr);
if (str1 != str0)
{
failed ("to deflate/inflate %s", str0);
return;
}
variable zstr1 = silly_deflate (str0);
if (zstr1 != zstr)
{
failed ("to deflate %s via multiple calls", str0);
return;
}
str1 = silly_inflate (zstr1);
if (str1 != str0)
{
failed ("to inflate %s via multiple calls", str0);
return;
}
}
define slsh_main ()
{
testing_module ("zlib");
test_zlib ("");
test_zlib ("\0");
test_zlib ("\0\0\0");
test_zlib ("A");
test_zlib ("AA");
test_zlib ("AAA");
test_zlib ("AAAAAAAA");
test_zlib ("AAAAAAAABBBBBBB");
test_zlib ("AAAAAAAABBBBBBBAAAAAAA");
test_zlib ("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
test_zlib ("ABCDEFGHIJKLMNOPQRSTUVWXYZ\0");
test_zlib ("\0ABCDEFGHIJKLMNOPQRSTUVWXYZ\0");
end_test ();
}
|