Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/cmd/vczip/tests/tvcrtable.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
static char *Record1[] =
24
{
25
"123:cdcd:111.222/3:vv:10\n",
26
"456:cdcd:222.333/4:uu:20\n",
27
"789:cdcd:333.111/1:tt:30\n",
28
};
29
static char *Record2[] =
30
{
31
"123:abab:222.333/4:99:11\n",
32
"xxx:abab:333.444/1:88:21\n",
33
"789:abab:444.111/2:77:31\n",
34
};
35
36
static Vcchar_t Data[1024];
37
38
int main()
39
{
40
Vcodex_t *tz, *uz;
41
Vcodex_t *huf, *rle, *mtf;
42
Vcchar_t *dt, *cmp;
43
ssize_t nc, nu, n, k, r, dtsz1, dtsz2;
44
Vcmethod_t *Vcrtable;
45
46
if(!(Vcrtable = vcgetmeth("rtable", 0)))
47
terror("rtable plugin not found");
48
/* construct first half of test data */
49
dtsz1 = 0;
50
for(k = 0, r = 0; r < 6; ++r, ++k)
51
{ if(k >= sizeof(Record1)/sizeof(Record1[0]))
52
k = 0;
53
n = strlen(Record1[k]);
54
if(dtsz1+n > sizeof(Data)/2)
55
break;
56
memcpy(Data+dtsz1, Record1[k], n);
57
dtsz1 += n;
58
}
59
60
/* construct second half of test data */
61
dtsz2 = dtsz1;
62
for(k = 0, r = 0; r < 6; ++r, ++k)
63
{ if(k >= sizeof(Record2)/sizeof(Record2[0]))
64
k = 0;
65
n = strlen(Record2[k]);
66
if(dtsz2+n > sizeof(Data))
67
break;
68
memcpy(Data+dtsz2, Record2[k], n);
69
dtsz2 += n;
70
}
71
72
/* construct encoder */
73
if(!(huf = vcopen(0, Vchuffgroup, 0, 0, VC_ENCODE)) )
74
terror("Can't open Vchuffgroup handle to compress");
75
if(!(rle = vcopen(0, Vcrle, "0", huf, VC_ENCODE|VC_CLOSECODER)) )
76
terror("Can't open Vcrle handle to compress");
77
if(!(mtf = vcopen(0, Vcmtf, 0, rle, VC_ENCODE|VC_CLOSECODER)) )
78
terror("Can't open Vcrle handle to compress");
79
if(!(tz = vcopen(0, Vcrtable, 0, mtf, VC_ENCODE)) )
80
terror("Vcrtable: could not open handle to encode");
81
82
/* construct decoder */
83
if(!(huf = vcopen(0, Vchuffgroup, 0, 0, VC_DECODE)) )
84
terror("Can't open Vchuffgroup handle to decompress");
85
if(!(rle = vcopen(0, Vcrle, "0", huf, VC_DECODE|VC_CLOSECODER)) )
86
terror("Can't open Vcrle handle to decompress");
87
if(!(mtf = vcopen(0, Vcmtf, 0, rle, VC_DECODE|VC_CLOSECODER)) )
88
terror("Can't open Vcrle handle to decompress");
89
if(!(uz = vcopen(0, Vcrtable, 0, mtf, VC_DECODE)) )
90
terror("Vcrtable: could not open handle to decode");
91
92
/* compress first half */
93
if((nc = vcapply(tz, Data, dtsz1+4, &cmp)) <= 0 )
94
terror("Vcrtable: fail transforming");
95
if(vcundone(tz) != 4)
96
terror("Vcrtable: wrong size of undone data");
97
twarn("Vctable: rawsz=%d cmpsz=%d\n", dtsz1, nc);
98
99
if((nu = vcapply(uz, cmp, nc, &dt)) != dtsz1)
100
terror("Vcrtable: fail decoding");
101
if(memcmp(dt, Data, nu) != 0)
102
terror("Vcrtable: results did not match");
103
104
/* compress all data */
105
if((nc = vcapply(tz, Data, dtsz2, &cmp)) <= 0 )
106
terror("Vcrtable: fail transforming");
107
twarn("Vctable: rawsz=%d cmpsz=%d\n", dtsz2, nc);
108
109
if((nu = vcapply(uz, cmp, nc, &dt)) != dtsz2)
110
terror("Vcrtable: fail decoding");
111
if(memcmp(dt, Data, nu) != 0)
112
terror("Vcrtable: results did not match");
113
114
exit(0);
115
}
116
117