Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/cmd/vczip/tests/tvchuffgroup.c
1810 views
1
/***********************************************************************
2
* *
3
* This software is part of the ast package *
4
* Copyright (c) 2003-2011 AT&T Intellectual Property *
5
* and is licensed under the *
6
* Eclipse Public License, Version 1.0 *
7
* by AT&T Intellectual Property *
8
* *
9
* A copy of the License is available at *
10
* http://www.eclipse.org/org/documents/epl-v10.html *
11
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
12
* *
13
* Information and Software Systems Research *
14
* AT&T Research *
15
* Florham Park NJ *
16
* *
17
* Phong Vo <[email protected]> *
18
* Glenn Fowler <[email protected]> *
19
* *
20
***********************************************************************/
21
#include "vctest.h"
22
23
int main()
24
{
25
Vcodex_t *vch, *vcu;
26
ssize_t k, n;
27
int c;
28
char data[64*1024], *d, *endd;
29
30
/* generate random data */
31
c = 'a';
32
for(endd = (d = data)+sizeof(data); d < endd; )
33
{
34
for(k = 0; k < 64 && d < endd; ++k, ++d)
35
*d = c + (random()%2);
36
if((c += 2) > 'h')
37
c = 'a';
38
}
39
40
if(!(vch = vcopen(0, Vchuffgroup, 0, 0, VC_ENCODE)) )
41
terror("Cannot open Vchuffgroup handle");
42
if(!(vcu = vcopen(0, Vchuffgroup, 0, 0, VC_DECODE)) )
43
terror("Cannot open Vchuffgroup handle to decode");
44
if((k = vcapply(vch, data, sizeof(data), &d)) <= 0)
45
terror("Can't compress");
46
twarn("Vchuffgroup: original size=%d compressed size=%d\n",sizeof(data),k);
47
if((n = vcapply(vcu, d, k, &d)) != sizeof(data))
48
terror("Can't decompress n=%d", n);
49
for(k = 0; k < sizeof(data); ++k)
50
if(d[k] != data[k])
51
terror("Bad decompressed data");
52
53
if(!(vch = vcopen(0, Vchuffpart, 0, 0, VC_ENCODE)) )
54
terror("Cannot open Vchuffpart handle");
55
if(!(vcu = vcopen(0, Vchuffpart, 0, 0, VC_DECODE)) )
56
terror("Cannot open Vchuffpart handle to decode");
57
if((k = vcapply(vch, data, sizeof(data), &d)) <= 0)
58
terror("Can't compress");
59
twarn("Vchuffpart: original size=%d compressed size=%d\n",sizeof(data),k);
60
if((n = vcapply(vcu, d, k, &d)) != sizeof(data))
61
terror("Can't decompress n=%d", n);
62
for(k = 0; k < sizeof(data); ++k)
63
if(d[k] != data[k])
64
terror("Bad decompressed data");
65
66
exit(0);
67
}
68
69