File: test_zlib.sl

package info (click to toggle)
slang2 2.3.3-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 11,488 kB
  • sloc: ansic: 101,756; sh: 3,435; makefile: 1,046; pascal: 440
file content (109 lines) | stat: -rw-r--r-- 2,177 bytes parent folder | download | duplicates (2)
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
() = evalfile("./test.sl");
require ("zlib");

private define silly_deflate (z, str)
{
   variable x = "";
   foreach (str)
     {
	variable ch = ();
	x = x + z.deflate (pack("C", ch); flush=ZLIB_NO_FLUSH);
     }
   x = x + z.flush ();
   return x;
}

private define silly_inflate (z, zstr)
{
   variable x = "";
   foreach (zstr)
     {
	variable ch = ();
	x = x + z.inflate(pack("C", ch); flush=ZLIB_NO_FLUSH);
     }
   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 z = zlib_deflate_new ();
   variable zstr1 = silly_deflate (z, str0);
   if (zstr1 != zstr)
     {
	failed ("to deflate %s via multiple calls", str0);
	return;
     }
   % Repeat using the same object
   z.reset ();
   zstr1 = silly_deflate (z, str0);
   if (zstr1 != zstr)
     {
	failed ("to deflate %s via multiple calls", str0);
	return;
     }

   z = zlib_inflate_new ();
   str1 = silly_inflate (z, zstr1);
   if (str1 != str0)
     {
	failed ("to inflate %s via multiple calls", str0);
	return;
     }
   % Repeat using the same object
   z.reset ();
   str1 = silly_inflate (z, zstr1);
   if (str1 != str0)
     {
	failed ("to inflate %s via multiple calls", str0);
	return;
     }
}

private define check_usage ()
{
   foreach (["zlib_inflate()", "zlib_deflate()",
	     "zlib_inflate_new().inflate()",
	     "(@zlib_inflate_new().flush)()",
	     "zlib_deflate_new().deflate()",
	     "(@zlib_deflate_new().flush)()",
	     ])
     {
	variable f = ();
	try
	  {
	     eval (f);
	     failed ("%s usage", f);
	  }
	catch UsageError;
     }
}

define slsh_main ()
{
   testing_module ("zlib");

   check_usage ();
   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 ();
}