-
Notifications
You must be signed in to change notification settings - Fork 0
/
gb96:zlib-tests.js
124 lines (100 loc) · 4.29 KB
/
gb96:zlib-tests.js
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/**
* Copyright Greg Bowering <gerg.bowering@gmail.com> 2014 All Rights Reserved
*
* Unit tests for gb96:zlib
*/
var uncompressedString = 'The quick brown fox jumped over the lazy dog.';
var uncompressedBuffer = new Buffer(uncompressedString, 'utf-8');
Tinytest.add('deflate method defined', function (test) {
var isDefined = false;
try {
deflate;
isDefined = true;
}
catch (e) {
}
test.isTrue(isDefined, "deflate is not defined");
});
Tinytest.add('deflate defined in package', function (test) {
test.isTrue(Package['gb96:zlib'].deflate, "Package.gb96:zlib.deflate is not defined");
});
Tinytest.add('deflateSync method defined', function (test) {
var isDefined = false;
try {
deflateSync;
isDefined = true;
}
catch (e) {
}
test.isTrue(isDefined, "deflateSync is not defined");
});
Tinytest.add('deflateSync defined in package', function (test) {
test.isTrue(Package['gb96:zlib'].deflateSync, "Package.gb96:zlib.deflateSync is not defined");
});
Tinytest.add('inflate method defined', function (test) {
var isDefined = false;
try {
inflate;
isDefined = true;
}
catch (e) {
}
test.isTrue(isDefined, "inflate is not defined");
});
Tinytest.add('inflate defined in package', function (test) {
test.isTrue(Package['gb96:zlib'].inflate, "Package.gb96:zlib.inflate is not defined");
});
Tinytest.add('inflateSync method defined', function (test) {
var isDefined = false;
try {
inflateSync;
isDefined = true;
}
catch (e) {
}
test.isTrue(isDefined, "inflateSync is not defined");
});
Tinytest.add('inflateSync defined in package', function (test) {
test.isTrue(Package['gb96:zlib'].inflateSync, "Package.gb96:zlib.inflateSync is not defined");
});
// Test gzipping then gunzipping to get back original string:
Tinytest.add('Call gzipSync then gunzipSync', function (test) {
var compressedBuffer = gzipSync(uncompressedBuffer);
test.isTrue(compressedBuffer, "gzipSync failed to return a value");
var uncompressedBuffer2 = gunzipSync(compressedBuffer);
test.isTrue(uncompressedBuffer2, "gunzipSync failed to return a value");
var uncompressedString2 = uncompressedBuffer2.toString('utf-8');
//console.log('uncompressedString2=' + uncompressedString2);
test.equal(uncompressedString, uncompressedString2, "Expected original string to be returned after compress+uncompress.");
});
// Test deflating then inflating to get back original string:
Tinytest.add('Call deflateSync then inflateSync', function (test) {
var compressedBuffer = deflateSync(uncompressedBuffer);
test.isTrue(compressedBuffer, "deflateSync failed to return a value");
var uncompressedBuffer2 = inflateSync(compressedBuffer);
test.isTrue(uncompressedBuffer2, "inflateSync failed to return a value");
var uncompressedString2 = uncompressedBuffer2.toString('utf-8');
//console.log('uncompressedString2=' + uncompressedString2);
test.equal(uncompressedString, uncompressedString2, "Expected original string to be returned after compress+uncompress.");
});
// Test deflating then unzipping to get back original string:
Tinytest.add('Call gzipSync then unzipSync', function (test) {
var compressedBuffer = gzipSync(uncompressedBuffer);
test.isTrue(compressedBuffer, "gzipSync failed to return a value");
var uncompressedBuffer2 = unzipSync(compressedBuffer);
test.isTrue(uncompressedBuffer2, "unzipSync failed to return a value");
var uncompressedString2 = uncompressedBuffer2.toString('utf-8');
//console.log('uncompressedString2=' + uncompressedString2);
test.equal(uncompressedString, uncompressedString2, "Expected original string to be returned after compress+uncompress.");
});
// Test deflating then unzipping to get back original string:
Tinytest.add('Call deflateSync then unzipSync', function (test) {
var compressedBuffer = deflateSync(uncompressedBuffer);
test.isTrue(compressedBuffer, "deflateSync failed to return a value");
var uncompressedBuffer2 = unzipSync(compressedBuffer);
test.isTrue(uncompressedBuffer2, "unzipSync failed to return a value");
var uncompressedString2 = uncompressedBuffer2.toString('utf-8');
//console.log('uncompressedString2=' + uncompressedString2);
test.equal(uncompressedString, uncompressedString2, "Expected original string to be returned after compress+uncompress.");
});
// TODO test deflateRawSync and inflateRawSync