1 /*===========================================================================
2 *
3 * PUBLIC DOMAIN NOTICE
4 * National Center for Biotechnology Information
5 *
6 * This software/database is a "United States Government Work" under the
7 * terms of the United States Copyright Act. It was written as part of
8 * the author's official duties as a United States Government employee and
9 * thus cannot be copyrighted. This software/database is freely available
10 * to the public for use. The National Library of Medicine and the U.S.
11 * Government have not placed any restriction on its use or reproduction.
12 *
13 * Although all reasonable efforts have been taken to ensure the accuracy
14 * and reliability of the software and data, the NLM and the U.S.
15 * Government do not and cannot warrant the performance or results that
16 * may be obtained by using this software or data. The NLM and the U.S.
17 * Government disclaim all warranties, express or implied, including
18 * warranties of performance, merchantability or fitness for any particular
19 * purpose.
20 *
21 * Please cite the author in any work or product based on this material.
22 *
23 * ===========================================================================
24 *
25 */
26
27 #include <ktst/unit_test.hpp>
28
29 TEST_SUITE(VxfTestSuite);
30
31 #include "wb-irzip-impl.h"
32
33 ////////////////////////////////////////// IZIP encoding tests
34
35 // test fixture for scanner tests
36 class EncoderFixture
37 {
38 public:
EncoderFixture()39 EncoderFixture()
40 : dSize(BufSize), used(0), series_count(0), planes(0)
41 {
42 min[0] = min[1] = 0;
43 slope[0] = slope[1] = 0;
44 }
45
46 static const int BufSize = 102400;
47 uint8_t dst[BufSize];
48 size_t dSize;
49 size_t used;
50 int64_t min[2];
51 int64_t slope[2];
52 uint8_t series_count;
53 uint8_t planes;
54 };
55
56 #define ARR_SIZE(a) (sizeof(a) / sizeof(a[0]))
57
58 #define REQUIRE_EQ_ARR(a, b, size) \
59 for (size_t i=0; i < size; ++i) \
60 { \
61 REQUIRE_EQUAL(a[i], b[i]); \
62 }
63
64 // exposes an assert failure when encoding unsigned 64 bit integers (#VDB-539), case 1
FIXTURE_TEST_CASE(IRZIP_u64_assert1,EncoderFixture)65 FIXTURE_TEST_CASE(IRZIP_u64_assert1, EncoderFixture)
66 {
67 uint64_t y[]={
68 UINT64_C(353878216),
69 UINT64_C(353878152),
70 UINT64_C(353877873),
71 UINT64_C(353877162),
72 UINT64_C(353876785),
73 UINT64_C(353875727),
74 UINT64_C(353874605),
75 UINT64_C(353873979),
76 UINT64_C(353873604),
77 UINT64_C(353872503)
78 };
79 uint64_t decoded[ARR_SIZE(y)];
80 REQUIRE_RC(doEncode_u64(dst, dSize, &used, min, slope, &series_count, &planes, y, ARR_SIZE(y)));
81 REQUIRE_RC(doDecode_u64(decoded, ARR_SIZE(y), min, slope, series_count, planes, dst, used));
82 REQUIRE_EQ_ARR(y, decoded, ARR_SIZE(y));
83 }
84
85 // exposes an assert failure when encoding unsigned 64 bit integers (#VDB-539), case 2
FIXTURE_TEST_CASE(IRZIP_u64_assert2,EncoderFixture)86 FIXTURE_TEST_CASE(IRZIP_u64_assert2, EncoderFixture)
87 {
88 uint64_t y[]={
89 UINT64_C(353878216),
90 UINT64_C(353878152),
91 UINT64_C( 0),
92 UINT64_C( 0),
93 UINT64_C( 0),
94 UINT64_C( 0),
95 UINT64_C( 0),
96 UINT64_C( 0),
97 UINT64_C( 0),
98 UINT64_C( 0)
99 };
100 uint64_t decoded[ARR_SIZE(y)];
101 REQUIRE_RC(doEncode_u64(dst, dSize, &used, min, slope, &series_count, &planes, y, ARR_SIZE(y)));
102 REQUIRE_RC(doDecode_u64(decoded, ARR_SIZE(y), min, slope, series_count, planes, dst, used));
103 REQUIRE_EQ_ARR(y, decoded, ARR_SIZE(y));
104 }
105
106 // tries to expose the same assert failure as above (#VDB-539), using 32 bit integers (#VDB-539), case 1
FIXTURE_TEST_CASE(IRZIP_u32_assert1,EncoderFixture)107 FIXTURE_TEST_CASE(IRZIP_u32_assert1, EncoderFixture)
108 {
109 uint32_t y[]={
110 78216,
111 78152,
112 77873,
113 77162,
114 76785,
115 75727,
116 74605,
117 73979,
118 73604,
119 72503
120 };
121 uint32_t decoded[ARR_SIZE(y)];
122 REQUIRE_RC(doEncode_u32(dst, dSize, &used, min, slope, &series_count, &planes, y, ARR_SIZE(y)));
123 REQUIRE_RC(doDecode_u32(decoded, ARR_SIZE(y), min, slope, series_count, planes, dst, used));
124 REQUIRE_EQ_ARR(y, decoded, ARR_SIZE(y));
125 }
126
127 // tries to expose the same assert failure as above (#VDB-539), using 32 bit integers (#VDB-539), case 2
FIXTURE_TEST_CASE(IRZIP_u32_assert2,EncoderFixture)128 FIXTURE_TEST_CASE(IRZIP_u32_assert2, EncoderFixture)
129 {
130 uint32_t y[]={
131 78216,
132 78152,
133 0,
134 0,
135 0,
136 0,
137 0,
138 0,
139 0,
140 0
141 };
142 uint32_t decoded[ARR_SIZE(y)];
143 REQUIRE_RC(doEncode_u32(dst, dSize, &used, min, slope, &series_count, &planes, y, ARR_SIZE(y)));
144 REQUIRE_RC(doDecode_u32(decoded, ARR_SIZE(y), min, slope, series_count, planes, dst, used));
145 REQUIRE_EQ_ARR(y, decoded, ARR_SIZE(y));
146 }
147
148 // exposes an assert failure when encoding unsigned 64 bit integers, case 3
FIXTURE_TEST_CASE(IRZIP_u64_assert3,EncoderFixture)149 FIXTURE_TEST_CASE(IRZIP_u64_assert3, EncoderFixture)
150 {
151 uint64_t y[]={
152 UINT64_C( 388750),
153 UINT64_C( 490295),
154 UINT64_C( 813277),
155 UINT64_C( 725540),
156 UINT64_C( 85294),
157 UINT64_C( 178363),
158 UINT64_C(1607062),
159 UINT64_C( 825545),
160 UINT64_C( 474451),
161 UINT64_C( 745337),
162 };
163 uint64_t decoded[ARR_SIZE(y)];
164 REQUIRE_RC(doEncode_u64(dst, dSize, &used, min, slope, &series_count, &planes, y, ARR_SIZE(y)));
165 REQUIRE_RC(doDecode_u64(decoded, ARR_SIZE(y), min, slope, series_count, planes, dst, used));
166 REQUIRE_EQ_ARR(y, decoded, ARR_SIZE(y));
167 }
168
169 // exposes an assert failure when encoding unsigned 64 bit integers, case 4
FIXTURE_TEST_CASE(IRZIP_u64_assert4,EncoderFixture)170 FIXTURE_TEST_CASE(IRZIP_u64_assert4, EncoderFixture)
171 {
172 uint64_t y[]={
173 UINT64_C( 2800167),
174 UINT64_C(47247557592),
175 UINT64_C(64427423880),
176 UINT64_C(30067744899),
177 UINT64_C(64427423881),
178 UINT64_C(21477638667),
179 UINT64_C( 8592622326),
180 UINT64_C(12887443839),
181 UINT64_C( 8592622323),
182 UINT64_C(12887443837),
183 UINT64_C( 773768),
184 UINT64_C(60132272802),
185 UINT64_C(25772592326),
186 UINT64_C( 4297746473),
187 UINT64_C(21477638660),
188 };
189 uint64_t decoded[ARR_SIZE(y)];
190 REQUIRE_RC(doEncode_u64(dst, dSize, &used, min, slope, &series_count, &planes, y, ARR_SIZE(y)));
191 REQUIRE_RC(doDecode_u64(decoded, ARR_SIZE(y), min, slope, series_count, planes, dst, used));
192 REQUIRE_EQ_ARR(y, decoded, ARR_SIZE(y));
193 }
194
195
196 // encoding/decoding of signed 64 bit integers
FIXTURE_TEST_CASE(IRZIP_i64_assert1,EncoderFixture)197 FIXTURE_TEST_CASE(IRZIP_i64_assert1, EncoderFixture)
198 {
199 int64_t y[]={
200 INT64_C( 353878216),
201 INT64_C(-353878152),
202 INT64_C( 353877873),
203 INT64_C(-353877162),
204 INT64_C(-353876785),
205 INT64_C( 353875727),
206 INT64_C(-353874605),
207 INT64_C( 353873979),
208 INT64_C(-353873604),
209 INT64_C( 353872503)
210 };
211 int64_t decoded[ARR_SIZE(y)];
212 REQUIRE_RC(doEncode_i64(dst, dSize, &used, min, slope, &series_count, &planes, y, ARR_SIZE(y)));
213 REQUIRE_RC(doDecode_i64(decoded, ARR_SIZE(y), min, slope, series_count, planes, dst, used));
214 REQUIRE_EQ_ARR(y, decoded, ARR_SIZE(y));
215 }
216
217 // encoding/decoding of signed 32 bit integers
FIXTURE_TEST_CASE(IRZIP_i32_assert1,EncoderFixture)218 FIXTURE_TEST_CASE(IRZIP_i32_assert1, EncoderFixture)
219 {
220 int32_t y[]={
221 78216,
222 78152,
223 -77873,
224 -77162,
225 -76785,
226 75727,
227 74605,
228 -73979,
229 -73604,
230 72503
231 };
232 int32_t decoded[ARR_SIZE(y)];
233 REQUIRE_RC(doEncode_i32(dst, dSize, &used, min, slope, &series_count, &planes, y, ARR_SIZE(y)));
234 REQUIRE_RC(doDecode_i32(decoded, ARR_SIZE(y), min, slope, series_count, planes, dst, used));
235 REQUIRE_EQ_ARR(y, decoded, ARR_SIZE(y));
236 }
237
238 //////////////////////////////////////////// Main
239 extern "C"
240 {
241
242 #include <kapp/args.h>
243 #include <kfg/config.h>
244
KAppVersion(void)245 ver_t CC KAppVersion ( void )
246 {
247 return 0x1000000;
248 }
UsageSummary(const char * progname)249 rc_t CC UsageSummary (const char * progname)
250 {
251 return 0;
252 }
253
Usage(const Args * args)254 rc_t CC Usage ( const Args * args )
255 {
256 return 0;
257 }
258
259 const char UsageDefaultName[] = "wb-test-vxf";
260
KMain(int argc,char * argv[])261 rc_t CC KMain ( int argc, char *argv [] )
262 {
263 KConfigDisableUserSettings();
264 rc_t rc=VxfTestSuite(argc, argv);
265 return rc;
266 }
267
268 }
269