xrif
A fast lossless compression system
xrif_test_init.c
Go to the documentation of this file.
1 /** \file xrif_test_init.c
2  * \brief Tests of xrif initialization.
3  *
4  * \author Jared R. Males (jaredmales@gmail.com)
5  *
6  * \ingroup xrif_files
7  */
8 
9 /* This file is part of the xrif library.
10 
11 Copyright (c) 2019, 2020, The Arizona Board of Regents on behalf of The
12 University of Arizona
13 
14 All rights reserved.
15 
16 Developed by: The Arizona Board of Regents on behalf of the
17 University of Arizona.
18 
19 Redistribution and use for noncommercial purposes in source and
20 binary forms, with or without modification, are permitted provided
21 that the following conditions are met:
22 
23 1. The software is used solely for noncommercial purposes.
24 
25 2. Redistributions of source code must retain the above copyright
26 notice, terms and conditions specified herein and the disclaimer
27 specified in Section 4 below.
28 
29 3. Redistributions in binary form must reproduce the above
30 copyright notice, this list of conditions and the following
31 disclaimer in the documentation and/or other materials provided
32 with the distribution.
33 
34 4. Neither the name of the Arizona Board of Regents, the University
35 of Arizona nor the names of other contributors may be used to
36 endorse or promote products derived from this software without
37 specific prior written permission.
38 
39 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
40 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
41 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
42 FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
43 COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
44 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
45 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
46 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 OF THE POSSIBILITY OF SUCH DAMAGE.
51 
52 Arizona Required Clauses:
53 
54 1.1. Arbitration. The parties agree that if a dispute arises
55 between them concerning this Agreement, the parties may be required
56 to submit the matter to arbitration pursuant to Arizona law.
57 
58 1.2. Applicable Law and Venue. This Agreement shall be interpreted
59 pursuant to the laws of the State of Arizona. Any arbitration or
60 litigation between the Parties shall be conducted in Pima County,
61 ARIZONA, and LICENSEE hereby submits to venue and jurisdiction in
62 Pima County, ARIZONA.
63 
64 1.3. Non-Discrimination. The Parties agree to be bound by state and
65 federal laws and regulations governing equal opportunity and non-
66 discrimination and immigration.
67 
68 1.4. Appropriation of Funds. The Parties recognize that performance
69 by ARIZONA may depend upon appropriation of funds by the State
70 Legislature of ARIZONA. If the Legislature fails to appropriate the
71 necessary funds, or if ARIZONA’S appropriation is reduced during
72 the fiscal year, ARIZONA may cancel this Agreement without further
73 duty or obligation. ARIZONA will notify LICENSEE as soon as
74 reasonably possible after it knows of the loss of funds.
75 
76 1.5. Conflict of Interest. This Agreement is subject to the
77 provisions of A.R.S. 38-511 and other conflict of interest
78 regulations. Within three years of the EFFECTIVE DATE, ARIZONA may
79 cancel this Agreement if any person significantly involved in
80 initiating, negotiating, drafting, securing, or creating this
81 Agreement for or on behalf of ARIZONA becomes an employee or
82 consultant in any capacity of LICENSEE with respect to the subject
83 matter of this Agreement.
84 
85 */
86 
87 #include <check.h>
88 #include <stdlib.h>
89 #include <stdio.h>
90 
91 #include "../src/xrif.h"
92 
93 /// Verify handle initialization
94 /** Tests that each member is properly initialized.
95  *
96  * \anchor tests_initialize_handle_noerror
97  *
98  */
99 START_TEST (initialize_handle_noerror)
100 {
101  //Verify that all fields are initialized to their defaults.
102 
103  xrif_handle hand;
104 
106 
107  ck_assert_int_eq( hand.width, 0);
108  ck_assert_int_eq( hand.height, 0);
109  ck_assert_int_eq( hand.depth, 0);
110  ck_assert_int_eq( hand.frames, 0);
111  ck_assert_int_eq( hand.type_code, 0);
112  ck_assert_int_eq( hand.data_size, 0);
113  ck_assert_int_eq( hand.compressed_size, 0);
114  ck_assert_int_eq( hand.difference_method, XRIF_DIFFERENCE_DEFAULT);
115  ck_assert_int_eq( hand.reorder_method, XRIF_REORDER_DEFAULT);
116  ck_assert_int_eq( hand.compress_method, XRIF_COMPRESS_DEFAULT);
117  ck_assert_int_eq( hand.lz4_acceleration, 1);
118  ck_assert_int_eq( hand.omp_parallel, 0);
119  ck_assert_int_eq( hand.omp_numthreads, 1);
120  ck_assert_int_eq( hand.compress_on_raw, 1);
121  ck_assert_int_eq( hand.own_raw, 0);
122  ck_assert( hand.raw_buffer == NULL );
123  ck_assert_int_eq( hand.raw_buffer_size, 0);
124  ck_assert_int_eq( hand.own_reordered, 0);
125  ck_assert( hand.reordered_buffer == NULL );
126  ck_assert_int_eq( hand.reordered_buffer_size, 0);
127  ck_assert_int_eq( hand.own_compressed, 0);
128  ck_assert( hand.compressed_buffer == NULL );
129  ck_assert_int_eq( hand.compressed_buffer_size, 0);
130 
131  ck_assert( rv == XRIF_NOERROR );
132 }
133 END_TEST
134 
135 /// Verify xrif_initialize_handle returns error on NULL pointer
136 /**
137  *
138  * \anchor tests_initialize_handle_nullptr
139  *
140  */
141 START_TEST (initialize_handle_nullptr)
142 {
143  xrif_handle * hand = NULL;
144 
146 
147  ck_assert( rv == XRIF_ERROR_NULLPTR );
148 }
149 END_TEST
150 
151 START_TEST (new_delete_noerror)
152 {
153  //Verify that all fields are initialized to their defaults.
154 
155  xrif_t hand = 0;
156 
157  xrif_error_t rv = xrif_new(&hand);
158 
159  ck_assert( hand != NULL);
160  ck_assert_int_eq( hand->width, 0);
161  ck_assert_int_eq( hand->height, 0);
162  ck_assert_int_eq( hand->depth, 0);
163  ck_assert_int_eq( hand->frames, 0);
164  ck_assert_int_eq( hand->type_code, 0);
165  ck_assert_int_eq( hand->data_size, 0);
166  ck_assert_int_eq( hand->compressed_size, 0);
167  ck_assert_int_eq( hand->difference_method, XRIF_DIFFERENCE_DEFAULT);
168  ck_assert_int_eq( hand->reorder_method, XRIF_REORDER_DEFAULT);
169  ck_assert_int_eq( hand->compress_method, XRIF_COMPRESS_DEFAULT);
170  ck_assert_int_eq( hand->lz4_acceleration, 1);
171  ck_assert_int_eq( hand->omp_parallel, 0);
172  ck_assert_int_eq( hand->omp_numthreads, 1);
173  ck_assert_int_eq( hand->compress_on_raw, 1);
174  ck_assert_int_eq( hand->own_raw, 0);
175  ck_assert( hand->raw_buffer == NULL );
176  ck_assert_int_eq( hand->raw_buffer_size, 0);
177  ck_assert_int_eq( hand->own_reordered, 0);
178  ck_assert( hand->reordered_buffer == NULL );
179  ck_assert_int_eq( hand->reordered_buffer_size, 0);
180  ck_assert_int_eq( hand->own_compressed, 0);
181  ck_assert( hand->compressed_buffer == NULL );
182  ck_assert_int_eq( hand->compressed_buffer_size, 0);
183 
184  ck_assert( rv == XRIF_NOERROR );
185 
186  rv = xrif_delete(hand);
187  ck_assert( rv == XRIF_NOERROR );
188 
189 }
190 END_TEST
191 
192 
193 START_TEST (setup_noerror)
194 {
195  //Verfiy that the setup function sets only the expected members
196 
197  xrif_handle hand;
198 
200 
201  ck_assert( rv == XRIF_NOERROR );
202 
203  rv = xrif_set_size(&hand, 1024,64,32,1000, XRIF_TYPECODE_INT16);
204 
205  ck_assert_int_eq( hand.width, 1024);
206  ck_assert_int_eq( hand.height, 64);
207  ck_assert_int_eq( hand.depth, 32);
208  ck_assert_int_eq( hand.frames, 1000);
209  ck_assert_int_eq( hand.type_code, XRIF_TYPECODE_INT16);
210  ck_assert_int_eq( hand.data_size, sizeof(int16_t));
211 
212  //And we check that everything else is unaltered
213  ck_assert_int_eq( hand.compressed_size, 0);
214  ck_assert_int_eq( hand.difference_method, XRIF_DIFFERENCE_DEFAULT);
215  ck_assert_int_eq( hand.reorder_method, XRIF_REORDER_DEFAULT);
216  ck_assert_int_eq( hand.compress_method, XRIF_COMPRESS_DEFAULT);
217  ck_assert_int_eq( hand.lz4_acceleration, 1);
218  ck_assert_int_eq( hand.omp_parallel, 0);
219  ck_assert_int_eq( hand.omp_numthreads, 1);
220  ck_assert_int_eq( hand.compress_on_raw, 1);
221  ck_assert_int_eq( hand.own_raw, 0);
222  ck_assert( hand.raw_buffer == NULL );
223  ck_assert_int_eq( hand.raw_buffer_size, 0);
224  ck_assert_int_eq( hand.own_reordered, 0);
225  ck_assert( hand.reordered_buffer == NULL );
226  ck_assert_int_eq( hand.reordered_buffer_size, 0);
227  ck_assert_int_eq( hand.own_compressed, 0);
228  ck_assert( hand.compressed_buffer == NULL );
229  ck_assert_int_eq( hand.compressed_buffer_size, 0);
230 
231  ck_assert( rv == XRIF_NOERROR );
232 }
233 END_TEST
234 
235 START_TEST (setup_nullptr)
236 {
237  //Verfiy that the setup function returns an error on a null ptr
238 
239  xrif_error_t rv = xrif_set_size(NULL, 1024,64,32,1000, XRIF_TYPECODE_INT16);
240 
241  ck_assert( rv == XRIF_ERROR_NULLPTR );
242 
243 }
244 END_TEST
245 
246 START_TEST (set_raw_noerrors)
247 {
248  //Verfiy that the raw buffer setup works properly
249 
250  xrif_handle hand;
251 
253 
254  ck_assert( rv == XRIF_NOERROR );
255 
256  rv = xrif_set_size(&hand, 120,120,3,120, XRIF_TYPECODE_INT16);
257 
258  ck_assert( rv == XRIF_NOERROR );
259 
260  //First do this with compress_on_raw == false
261  hand.compress_on_raw = 0;
262  int16_t buff;
263 
264  rv = xrif_set_raw( &hand, &buff, 120*120*3*120*sizeof(int16_t));
265 
266  ck_assert( hand.own_raw == 0 );
267  ck_assert( hand.raw_buffer == (char *) &buff );
268  ck_assert( hand.raw_buffer_size = 120*120*3*120*sizeof(int16_t) );
269 
270  ck_assert( rv == XRIF_NOERROR );
271 
272  //And then do this with compress_on_raw == true
273  hand.compress_on_raw = 1;
274 
275  rv = xrif_set_raw( &hand, &buff, LZ4_compressBound( 120*120*3*120*sizeof(int16_t) ));
276 
277  ck_assert( hand.own_raw == 0 );
278  ck_assert( hand.raw_buffer == (char *) &buff );
279  ck_assert( hand.raw_buffer_size = LZ4_compressBound( 120*120*3*120*sizeof(int16_t) ) );
280 
281  ck_assert( rv == XRIF_NOERROR );
282 
283 }
284 END_TEST
285 
286 START_TEST (set_raw_errors)
287 {
288  //Verfiy that the raw buffer returns expected errors.
289 
290  xrif_error_t rv = xrif_set_raw(NULL,0,0);
291  ck_assert( rv == XRIF_ERROR_NULLPTR );
292 
293  xrif_handle hand;
294 
295  rv = xrif_initialize_handle(&hand);
296 
297  ck_assert( rv == XRIF_NOERROR );
298 
299  rv = xrif_set_size(&hand, 120,120,3,120, XRIF_TYPECODE_INT16);
300 
301  ck_assert( rv == XRIF_NOERROR );
302 
303  // Test case where buffer is not null, but size is 0
304  int16_t * buff = (uint16_t *) 10;
305 
306  rv = xrif_set_raw( &hand, buff, 0);
307 
308  ck_assert( rv == XRIF_ERROR_INVALID_SIZE );
309 
310  buff = NULL;
311 
312  rv = xrif_set_raw( &hand, buff, 10);
313 
314  ck_assert( rv == XRIF_ERROR_INVALID_SIZE );
315 
316  //--Now test errors on wrong sizes
317  //First do this with compress_on_raw == false
318  hand.compress_on_raw = 0;
319 
320  rv = xrif_set_raw( &hand, buff, 0.5*120*120*3*120*sizeof(int16_t));
321 
322  ck_assert( hand.own_raw == 0 );
323  ck_assert( hand.raw_buffer == (char *) buff );
324  ck_assert( hand.raw_buffer_size = 0.5*120*120*3*120*sizeof(int16_t) );
325 
326  ck_assert( rv == XRIF_ERROR_INSUFFICIENT_SIZE );
327 
328  //And then do this with compress_on_raw == true
329  hand.compress_on_raw = 1;
330 
331  rv = xrif_set_raw( &hand, buff, 0.5*120*120*3*120*sizeof(int16_t) );
332 
333  ck_assert( hand.own_raw == 0 );
334  ck_assert( hand.raw_buffer == (char *) buff );
335  ck_assert( hand.raw_buffer_size = 0.5*120*120*3*120*sizeof(int16_t) );
336 
337  ck_assert( rv == XRIF_ERROR_INSUFFICIENT_SIZE );
338 }
339 END_TEST
340 
341 
342 
343 START_TEST (set_reordered_noerrors)
344 {
345  //Verfiy that the reordered buffer setup works properly
346 
347  xrif_handle hand;
348 
350 
351  ck_assert( rv == XRIF_NOERROR );
352 
353  rv = xrif_set_size(&hand, 120,120,3,120, XRIF_TYPECODE_INT16);
354 
355  ck_assert( rv == XRIF_NOERROR );
356 
357  int16_t buff;
358 
359  rv = xrif_set_reordered( &hand, &buff, 120*120*3*120*sizeof(int16_t));
360 
361  ck_assert( hand.own_reordered == 0 );
362  ck_assert( hand.reordered_buffer == (char *) &buff );
363  ck_assert( hand.reordered_buffer_size = 120*120*3*120*sizeof(int16_t) );
364 
365  ck_assert( rv == XRIF_NOERROR );
366 
367 }
368 END_TEST
369 
370 START_TEST (set_reordered_errors)
371 {
372  //Verfiy that the raw buffer returns expected errors.
373 
374  xrif_error_t rv = xrif_set_reordered(NULL,0,0);
375  ck_assert( rv == XRIF_ERROR_NULLPTR );
376 
377  xrif_handle hand;
378 
379  rv = xrif_initialize_handle(&hand);
380 
381  ck_assert( rv == XRIF_NOERROR );
382 
383  rv = xrif_set_size(&hand, 120,120,3,120, XRIF_TYPECODE_INT16);
384 
385  ck_assert( rv == XRIF_NOERROR );
386 
387  // Test case where buffer is not null, but size is 0
388  int16_t * buff = (uint16_t *) 10;
389 
390  rv = xrif_set_reordered( &hand, buff, 0);
391 
392  ck_assert( rv == XRIF_ERROR_INVALID_SIZE );
393 
394  buff = NULL;
395 
396  rv = xrif_set_reordered( &hand, buff, 10);
397 
398  ck_assert( rv == XRIF_ERROR_INVALID_SIZE );
399 }
400 END_TEST
401 
402 START_TEST (set_compressed_noerrors)
403 {
404  //Verfiy that the compress buffer setup works properly
405 
406  xrif_handle hand;
407 
409 
410  ck_assert( rv == XRIF_NOERROR );
411 
412  rv = xrif_set_size(&hand, 120,120,3,120, XRIF_TYPECODE_INT16);
413 
414  ck_assert( rv == XRIF_NOERROR );
415 
416  int16_t buff;
417  size_t lz4sz = LZ4_compressBound(120*120*3*120*sizeof(int16_t));
418 
419  rv = xrif_set_compressed( &hand, &buff, lz4sz);
420 
421  ck_assert( hand.own_compressed == 0 );
422  ck_assert( hand.compressed_buffer == (char *) &buff );
423  ck_assert( hand.compressed_buffer_size = lz4sz);
424 
425  ck_assert( rv == XRIF_NOERROR );
426 
427 }
428 END_TEST
429 
430 START_TEST (set_compressed_errors)
431 {
432  //Verfiy that the raw buffer returns expected errors.
433 
434  xrif_error_t rv = xrif_set_compressed(NULL,0,0);
435  ck_assert( rv == XRIF_ERROR_NULLPTR );
436 
437  xrif_handle hand;
438 
439  rv = xrif_initialize_handle(&hand);
440 
441  ck_assert( rv == XRIF_NOERROR );
442 
443  rv = xrif_set_size(&hand, 120,120,3,120, XRIF_TYPECODE_INT16);
444 
445  ck_assert( rv == XRIF_NOERROR );
446 
447  // Test case where buffer is not null, but size is 0
448  int16_t * buff = (uint16_t *) 10;
449 
450  rv = xrif_set_compressed( &hand, buff, 0);
451 
452  ck_assert( rv == XRIF_ERROR_INVALID_SIZE );
453 
454  buff = NULL;
455 
456  rv = xrif_set_compressed( &hand, buff, 10);
457 
458  ck_assert( rv == XRIF_ERROR_INVALID_SIZE );
459 
460  //Check that not matching LZ4_compressBound returns error
461  buff = (uint16_t *) 10;
462  rv = xrif_set_compressed( &hand, buff, 1024);
463  ck_assert( rv == XRIF_ERROR_INSUFFICIENT_SIZE );
464 }
465 END_TEST
466 
467 
468 START_TEST (allocate_raw_noerrors)
469 {
470  //Verfiy that the compress buffer setup works properly
471 
472  xrif_handle hand;
473 
475 
476  ck_assert( rv == XRIF_NOERROR );
477 
478  rv = xrif_set_size(&hand, 120,120,3,120, XRIF_TYPECODE_INT16);
479 
480  ck_assert( rv == XRIF_NOERROR );
481 
482  rv = xrif_allocate_raw(&hand);
483 
484  ck_assert( rv == XRIF_NOERROR );
485 
486 }
487 END_TEST
488 
489 //-------------------------------------------------------------------
490 
491 START_TEST (header_write)
492 {
493  //This test verifies that header fields are correctly populated
494  xrif_handle hand;
495 
497 
498  ck_assert( rv == XRIF_NOERROR );
499 
500  rv = xrif_set_size(&hand, 120,120,1,1000, XRIF_TYPECODE_INT16);
501 
502  ck_assert( rv == XRIF_NOERROR );
503 
504  hand.compressed_size = 256;
505 
506  char header[XRIF_HEADER_SIZE];
507 
508  rv = xrif_write_header( header, &hand );
509 
510  ck_assert( rv == XRIF_NOERROR );
511 
512  ck_assert( header[0] == 'x' );
513  ck_assert( header[1] == 'r' );
514  ck_assert( header[2] == 'i' );
515  ck_assert( header[3] == 'f' );
516 
517  ck_assert( *((uint32_t *) &header[4]) == XRIF_VERSION);
518  ck_assert( *((uint32_t *) &header[8]) == XRIF_HEADER_SIZE);
519  ck_assert( *((uint32_t *) &header[12]) == hand.width);
520  ck_assert( *((uint32_t *) &header[16]) == hand.height);
521  ck_assert( *((uint32_t *) &header[20]) == hand.depth);
522  ck_assert( *((uint32_t *) &header[24]) == hand.frames);
523  ck_assert( *((uint16_t *) &header[28]) == hand.type_code);
524  ck_assert( *((uint16_t *) &header[30]) == hand.difference_method);
525  ck_assert( *((uint16_t *) &header[32]) == hand.reorder_method);
526  ck_assert( *((uint16_t *) &header[34]) == hand.compress_method);
527  ck_assert( *((uint32_t *) &header[36]) == hand.compressed_size);
528  ck_assert( *((uint16_t *) &header[40]) == hand.lz4_acceleration);
529  ck_assert( *((uint16_t *) &header[42]) == 0);
530  ck_assert( *((uint16_t *) &header[44]) == 0);
531  ck_assert( *((uint16_t *) &header[46]) == 0);
532 }
533 END_TEST
534 
535 START_TEST (header_read)
536 {
537  //This test writes a setup handle to a header
538  //Then reads it to a new handle, verifying that members are set properly.
539 
540  xrif_handle hand;
541 
543 
544  ck_assert( rv == XRIF_NOERROR );
545 
546  rv = xrif_set_size(&hand, 120,240,2,1000, XRIF_TYPECODE_INT16);
547 
548  ck_assert( rv == XRIF_NOERROR );
549 
550  hand.compressed_size = 1025;
551  hand.lz4_acceleration = 10; //Change this from init value
552 
553  char header[XRIF_HEADER_SIZE];
554 
555  rv = xrif_write_header( header, &hand );
556 
557  ck_assert( rv == XRIF_NOERROR );
558 
559  //New handle to populate with read from header
560  xrif_handle hand2;
561 
562  rv = xrif_initialize_handle(&hand2);
563 
564  ck_assert( rv == XRIF_NOERROR );
565 
566  uint32_t header_size;
567  rv = xrif_read_header( &hand2, &header_size, header );
568 
569  ck_assert( rv == XRIF_NOERROR );
570 
571  ck_assert_int_eq( header_size, XRIF_HEADER_SIZE);
572  ck_assert_int_eq( hand2.width, 120);
573  ck_assert_int_eq( hand2.height, 240);
574  ck_assert_int_eq( hand2.depth, 2);
575  ck_assert_int_eq( hand2.frames, 1000);
576  ck_assert_int_eq( hand2.type_code, XRIF_TYPECODE_INT16);
577  ck_assert_int_eq( hand2.data_size, sizeof(int16_t));
578  ck_assert_int_eq( hand2.compressed_size, 1025);
579  ck_assert_int_eq( hand2.lz4_acceleration, 10);
580 
581  //And we check that everything else is unaltered
582  ck_assert_int_eq( hand2.difference_method, XRIF_DIFFERENCE_DEFAULT);
583  ck_assert_int_eq( hand2.reorder_method, XRIF_REORDER_DEFAULT);
584  ck_assert_int_eq( hand2.compress_method, XRIF_COMPRESS_DEFAULT);
585  ck_assert_int_eq( hand2.omp_parallel, 0);
586  ck_assert_int_eq( hand2.omp_numthreads, 1);
587  ck_assert_int_eq( hand2.compress_on_raw, 1);
588  ck_assert_int_eq( hand2.own_raw, 0);
589  ck_assert( hand2.raw_buffer == NULL );
590  ck_assert_int_eq( hand2.raw_buffer_size, 0);
591  ck_assert_int_eq( hand2.own_reordered, 0);
592  ck_assert( hand2.reordered_buffer == NULL );
593  ck_assert_int_eq( hand2.reordered_buffer_size, 0);
594  ck_assert_int_eq( hand2.own_compressed, 0);
595  ck_assert( hand2.compressed_buffer == NULL );
596  ck_assert_int_eq( hand2.compressed_buffer_size, 0);
597 
598 }
599 
600 END_TEST
601 
602 Suite * initandalloc_suite(void)
603 {
604  Suite *s;
605  TCase *tc_core;
606 
607  s = suite_create("Initialize and Allocate");
608 
609  /* Core test case */
610  tc_core = tcase_create("Initial Setups");
611 
612  tcase_add_test(tc_core, initialize_handle_noerror);
613  tcase_add_test(tc_core, initialize_handle_nullptr);
614  tcase_add_test(tc_core, new_delete_noerror);
615  tcase_add_test(tc_core, setup_noerror );
616  tcase_add_test(tc_core, setup_nullptr );
617  tcase_add_test(tc_core, allocate_raw_noerrors);
618  tcase_add_test(tc_core, set_raw_noerrors);
619  tcase_add_test(tc_core, set_raw_noerrors);
620  tcase_add_test(tc_core, set_reordered_noerrors);
621  tcase_add_test(tc_core, set_reordered_errors);
622  tcase_add_test(tc_core, set_compressed_noerrors);
623  tcase_add_test(tc_core, set_compressed_errors);
624  suite_add_tcase(s, tc_core);
625 
626  return s;
627 }
628 
629 Suite * headerformat_suite(void)
630 {
631  Suite *s;
632  TCase *tc_core;
633 
634  s = suite_create("Header Formatting");
635 
636  /* Core test case */
637  tc_core = tcase_create("Write and Read No Errors");
638 
639  tcase_add_test(tc_core, header_write );
640  tcase_add_test(tc_core, header_read );
641  suite_add_tcase(s, tc_core);
642 
643  return s;
644 }
645 
646 /* todo:
647  * [] test all possible ways of configuring, e.g. with COMPRESS_NONE which is a -1.
648  */
649 int main()
650 {
651  int number_failed;
652  Suite *s;
653  SRunner *sr;
654 
655  s = initandalloc_suite();
656  sr = srunner_create(s);
657 
658  srunner_run_all(sr, CK_NORMAL);
659  number_failed = srunner_ntests_failed(sr);
660  srunner_free(sr);
661 
662  s = headerformat_suite();
663  sr = srunner_create(s);
664 
665  srunner_run_all(sr, CK_NORMAL);
666  number_failed = srunner_ntests_failed(sr);
667  srunner_free(sr);
668 
669  return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
670 
671 }
672 
xrif_set_compressed
xrif_error_t xrif_set_compressed(xrif_t handle, void *compressed, size_t size)
Set the compressed data buffer to a pre-allocated pointer.
Definition: xrif.c:715
XRIF_ERROR_INVALID_SIZE
#define XRIF_ERROR_INVALID_SIZE
Return code indicating that an invalid size was passed.
Definition: xrif.h:169
XRIF_ERROR_NULLPTR
#define XRIF_ERROR_NULLPTR
Return code indicating that a NULL pointer was passed.
Definition: xrif.h:163
xrif_handle::width
xrif_dimension_t width
The width of a single image, in pixels.
Definition: xrif.h:308
xrif_handle::reordered_buffer
char * reordered_buffer
The reordered buffer pointer, contains the reordered data.
Definition: xrif.h:343
xrif_handle::difference_method
int difference_method
The difference method to use.
Definition: xrif.h:320
xrif_read_header
xrif_error_t xrif_read_header(xrif_t handle, uint32_t *header_size, char *header)
Configure an xrif handle by reading a xrif protocol header.
Definition: xrif.c:901
xrif_handle::compress_method
int compress_method
The compression method used.
Definition: xrif.h:324
xrif_handle::omp_numthreads
int omp_numthreads
Definition: xrif.h:331
xrif_handle::compressed_buffer
char * compressed_buffer
The compressed buffer pointer, contains the compressed data.
Definition: xrif.h:349
XRIF_TYPECODE_INT16
#define XRIF_TYPECODE_INT16
16-bit signed integer
Definition: xrif.h:217
xrif_handle::reorder_method
int reorder_method
The method to use for bit reordering.
Definition: xrif.h:322
xrif_handle::omp_parallel
int omp_parallel
Definition: xrif.h:328
xrif_allocate_raw
xrif_error_t xrif_allocate_raw(xrif_t handle)
Allocate the raw buffer based on the already set stream dimensions.
Definition: xrif.c:584
xrif_handle::lz4_acceleration
int lz4_acceleration
LZ4 acceleration parameter, >=1, higher is faster with less comporession. Default is 1.
Definition: xrif.h:326
xrif_handle
The xrif library configuration structure, organizing various parameters used by the functions.
Definition: xrif.h:306
xrif_handle::frames
xrif_dimension_t frames
The number of frames in the stream.
Definition: xrif.h:311
xrif_set_raw
xrif_error_t xrif_set_raw(xrif_t handle, void *raw, size_t size)
Set the raw data buffer to a pre-allocated pointer.
Definition: xrif.c:538
xrif_write_header
xrif_error_t xrif_write_header(char *header, xrif_t handle)
Populate a header buffer with the xrif protocol details.
Definition: xrif.c:846
xrif_handle::reordered_buffer_size
size_t reordered_buffer_size
Definition: xrif.h:344
xrif_new
xrif_error_t xrif_new(xrif_t *handle_ptr)
Allocate a handle and initialize it.
Definition: xrif.c:107
xrif_handle::height
xrif_dimension_t height
The height of a single image, in pixels.
Definition: xrif.h:309
xrif_handle::own_reordered
unsigned char own_reordered
Flag (true/false) indicating whether the reordered_buffer pointer is managed by this handle.
Definition: xrif.h:342
xrif_set_reordered
xrif_error_t xrif_set_reordered(xrif_t handle, void *reordered, size_t size)
Set the rordered (working) data buffer to a pre-allocated pointer.
Definition: xrif.c:627
xrif_handle::compress_on_raw
unsigned char compress_on_raw
Flag (true/false) indicating whether the raw buffer is used for compression. Default on initializeati...
Definition: xrif.h:334
xrif_error_t
int xrif_error_t
The error reporting type.
Definition: xrif.h:157
xrif_set_size
xrif_error_t xrif_set_size(xrif_t handle, xrif_dimension_t w, xrif_dimension_t h, xrif_dimension_t d, xrif_dimension_t f, xrif_typecode_t c)
Set the basic parameters of an xrif handle.
Definition: xrif.c:128
START_TEST
START_TEST(initialize_handle_noerror)
Verify handle initialization.
Definition: xrif_test_init.c:99
xrif_initialize_handle
xrif_error_t xrif_initialize_handle(xrif_t handle)
Initialize an xrif handle object.
Definition: xrif.c:294
xrif_handle::raw_buffer
char * raw_buffer
The raw buffer pointer, contains the image data, and if compress_on_raw == true the compressed data.
Definition: xrif.h:337
xrif_handle::depth
xrif_dimension_t depth
The depth of a single image, in pixels.
Definition: xrif.h:310
xrif_delete
xrif_error_t xrif_delete(xrif_t handle)
Deallocate a handle, including any memory that it owns.
Definition: xrif.c:277
xrif_handle::compressed_size
size_t compressed_size
Size of the stream after compression. Set dynamically by compression functions or from header.
Definition: xrif.h:318
xrif_handle::raw_buffer_size
size_t raw_buffer_size
Definition: xrif.h:338
XRIF_NOERROR
#define XRIF_NOERROR
Return code for success.
Definition: xrif.h:160
xrif_handle::compressed_buffer_size
size_t compressed_buffer_size
Definition: xrif.h:350
xrif_handle::own_raw
unsigned char own_raw
Flag (true/false) indicating whether the raw_buffer pointer is managed by this handle.
Definition: xrif.h:336
xrif_handle::data_size
size_t data_size
The size of the pixels, bytes. This corresponds to sizeof(type).
Definition: xrif.h:315
xrif_handle::own_compressed
unsigned char own_compressed
Flag (true/false) indicating whether the compressed_buffer pointer is managed by this handle.
Definition: xrif.h:348
XRIF_ERROR_INSUFFICIENT_SIZE
#define XRIF_ERROR_INSUFFICIENT_SIZE
Return code indicating that an insufficient size was given.
Definition: xrif.h:175
xrif_handle::type_code
xrif_typecode_t type_code
The code specifying the data type of the pixels.
Definition: xrif.h:313