libhpdftbl 1.5.0
Table construction library for Haru PDF library
Loading...
Searching...
No Matches
unit_test.inc.h File Reference

Common functions for all unit-test/examples. More...

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <execinfo.h>
#include <unistd.h>
#include <libgen.h>
#include <sys/stat.h>
#include <sys/utsname.h>
#include <hpdf.h>
#include <math.h>
#include <setjmp.h>
#include <time.h>
#include "../src/hpdftbl.h"

Go to the source code of this file.

Macros

#define TESTS_DIR   "./tests_libharu/"
 
#define TUTEX_MAIN(_tbl_, _showgrid_)
 Macro to create a main() function to call the table creation function for each example. The name to the table function is given as the first and only argument to the macro. More...
 

Typedefs

typedef char ** content_t
 An array of char pointers.
 

Functions

void setup_hpdf (HPDF_Doc *pdf_doc, HPDF_Page *pdf_page, _Bool addgrid)
 Create a new PDF document with one page in A4 format. More...
 
char * setup_filename (int argc, char **argv)
 Return a pointer to a static buffer that holds the filename to be used for the PDF page. More...
 
int stroke_to_file (HPDF_Doc pdf_doc, int argc, char **argv)
 Stroke the created PDF page to a file. More...
 
void setup_dummy_content (content_t *content, size_t rows, size_t cols)
 Create an array of char pointers to simulate real table data. More...
 
void setup_dummy_content_label (content_t *content, content_t *labels, size_t rows, size_t cols)
 Create both array of char pointers to simulate real table content as well as an array of simulated labels. More...
 
char * mkfullpath (char *filename)
 Add the full path to the tests directory as prefix to the supplied filename as argument. More...
 

Variables

_Bool run_as_unit_test = FALSE
 For the case when we use this example as a unit/integration test we do not want data such as dates, times, and system-information to be updated since the checks compare the result to a stored copy of the PDF file. More...
 
jmp_buf _hpdftbl_jmp_env
 For simulated exception handling. More...
 

Detailed Description

Common functions for all unit-test/examples.

DO NOT EDIT examples/unit_test.inc.h. Generated from unit_test.inc.h.in by configure.

Macro Definition Documentation

◆ TUTEX_MAIN

#define TUTEX_MAIN (   _tbl_,
  _showgrid_ 
)
Value:
int \
main(int argc, char **argv) { \
HPDF_Doc pdf_doc; \
HPDF_Page pdf_page; \
run_as_unit_test = 2==argc ; \
if (setjmp(_hpdftbl_jmp_env)) { \
return EXIT_FAILURE; \
} \
hpdftbl_set_errhandler(table_error_handler); \
setup_hpdf(&pdf_doc, &pdf_page, _showgrid_); \
_tbl_(pdf_doc, pdf_page); \
if( -1 == stroke_to_file(pdf_doc, argc, argv) ) \
return EXIT_FAILURE; \
else \
return EXIT_SUCCESS; \
}
int stroke_to_file(HPDF_Doc pdf_doc, int argc, char **argv)
Stroke the created PDF page to a file.
Definition: unit_test.inc.h:210
jmp_buf _hpdftbl_jmp_env
For simulated exception handling.
Definition: unit_test.inc.h:45
_Bool run_as_unit_test
For the case when we use this example as a unit/integration test we do not want data such as dates,...
Definition: unit_test.inc.h:35

Macro to create a main() function to call the table creation function for each example. The name to the table function is given as the first and only argument to the macro.

Parameters
_tbl_The name of the main table creation function to be called.
_showgrid_Set to TRUE to display a dot-grid on the paper, FALSE otherwise.
Examples
tut_ex00.c, tut_ex01.c, tut_ex02.c, tut_ex02_1.c, tut_ex03.c, tut_ex04.c, tut_ex05.c, tut_ex06.c, tut_ex07.c, tut_ex08.c, tut_ex09.c, tut_ex10.c, tut_ex11.c, tut_ex12.c, tut_ex13_1.c, tut_ex13_2.c, tut_ex14.c, tut_ex15.c, tut_ex15_1.c, tut_ex20.c, tut_ex30.c, tut_ex40.c, and tut_ex41.c.

Function Documentation

◆ mkfullpath()

char * mkfullpath ( char *  filename)

Add the full path to the tests directory as prefix to the supplied filename as argument.

This is needed since it is not possible at compile time to know the location of the tests directory due to the autotools feature of VPATH. This makes it possible to build in a arbitrary separate directory from the source. The autotools support the variable '.' which gets replaced with the actual src directory which makes it possible to find the tests directory.

The replacement happens when the autotools creates unit_test.inc.h from `unit_test.inc.h.in with the created "config.status"

Parameters
filenameThe base filename (relative to the tests directory)
Returns
Pointer to a dynamic allocated storage for the full path filename. It is the clients responsibility to free() the allocated memory.
Examples
tut_ex40.c, and tut_ex41.c.

◆ setup_dummy_content()

void setup_dummy_content ( content_t content,
size_t  rows,
size_t  cols 
)

Create an array of char pointers to simulate real table data.

Parameters
[out]contentA pointer to an array of char pointers
[in]rowsNumber of rows in table
[in]colsNumber of columns in table
Examples
tut_ex02.c, tut_ex10.c, tut_ex11.c, tut_ex12.c, tut_ex15.c, and tut_ex15_1.c.

◆ setup_dummy_content_label()

void setup_dummy_content_label ( content_t content,
content_t labels,
size_t  rows,
size_t  cols 
)

Create both array of char pointers to simulate real table content as well as an array of simulated labels.

Parameters
[out]contentA pointer to an array of char pointers to represent content in a table
[out]labelsA pointer to an array of char pointers to represent labels in a table
[in]rowsNumber of rows in table
[in]colsNumber of columns in table
Examples
tut_ex00.c, tut_ex04.c, tut_ex05.c, tut_ex20.c, tut_ex40.c, and tut_ex41.c.

◆ setup_filename()

char * setup_filename ( int  argc,
char **  argv 
)

Return a pointer to a static buffer that holds the filename to be used for the PDF page.

The filename is create from the program arguments. If there are no arguments the file name will have the same basename as the program (but with an added "*.pdf" suffix and path "out/".

If there are exactly on argument this will in its entirety (incl path) be taken as the full name for the file.

Warning
It is the calling functions responsibility to check for a NULL return value.

More than one program argument will generate an error (return NULL)

Parameters
argcThe main() functions argc argument
argvThe main() functions argv argument
Returns
NULL on error, otherwise a pointer to a static string that holds the filename.

Referenced by stroke_to_file().

◆ setup_hpdf()

void setup_hpdf ( HPDF_Doc *  pdf_doc,
HPDF_Page *  pdf_page,
_Bool  addgrid 
)

Create a new PDF document with one page in A4 format.

This initializes a basic PDF document object and a page object that can then be used. A typical calling sequence would be:

HPDF_Doc pdf_doc;
HPDF_Page pdf_page;
setup_hpdf(&pdf_doc, &pdf_page, FALSE);
#define FALSE
Boolean false value.
Definition: hpdftbl.h:52
void setup_hpdf(HPDF_Doc *pdf_doc, HPDF_Page *pdf_page, _Bool addgrid)
Create a new PDF document with one page in A4 format.
Definition: unit_test.inc.h:151

The pdf_doc and pdf_page can subsequently be used in the other PDF functions.

By setting the addgrid to TRUE the paper background will be gridlines with coordinate system units in points. This is very useful to precisely position text and graphics on a page.

Parameters
[out]pdf_docA pointer The document handle
[out]pdf_pageA pointer to a page handle
[in]addgridSet to TRUE to add coordinate grid lines to the paper (in points)

◆ stroke_to_file()

int stroke_to_file ( HPDF_Doc  pdf_doc,
int  argc,
char **  argv 
)

Stroke the created PDF page to a file.

The filename to be used is determined by the setup_filename() function

Parameters
pdf_docThe PDF document to be written
argcThe main() functions argc argument
argvThe main() functions argv argument
Returns
0 on success, -1 on failure
See also
setup_filename(), hpdftbl_stroke_pdfdoc()
Examples
example01.c.

Variable Documentation

◆ _hpdftbl_jmp_env

jmp_buf _hpdftbl_jmp_env

For simulated exception handling.

This specifies the setjmp() buffer to be used in the error handling routine to jump (via a longjmp()) to a specfied recovery point.

See also
table_error_handler()
Examples
example01.c.

◆ run_as_unit_test

_Bool run_as_unit_test = FALSE

For the case when we use this example as a unit/integration test we do not want data such as dates, times, and system-information to be updated since the checks compare the result to a stored copy of the PDF file.

When this is true it is used as a flag in, for example, the call-back functions to suppress the printing of dates and times so the result may be compared to the styored versions of the document and not be dependent on a specific time and date.

Examples
example01.c, tut_ex06.c, tut_ex07.c, tut_ex08.c, tut_ex14.c, and tut_ex30.c.