2019-09-02 08:09:47 +12:00
|
|
|
/*
|
|
|
|
libzint - the open source barcode library
|
2021-03-22 10:20:16 +13:00
|
|
|
Copyright (C) 2019 - 2021 Robin Stuart <rstuart114@gmail.com>
|
2019-09-02 08:09:47 +12:00
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
modification, are permitted provided that the following conditions
|
|
|
|
are met:
|
|
|
|
|
|
|
|
1. Redistributions of source code must retain the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer.
|
|
|
|
2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer in the
|
|
|
|
documentation and/or other materials provided with the distribution.
|
|
|
|
3. Neither the name of the project nor the names of its contributors
|
|
|
|
may be used to endorse or promote products derived from this software
|
|
|
|
without specific prior written permission.
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
|
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
|
|
|
|
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
SUCH DAMAGE.
|
|
|
|
*/
|
2019-10-17 22:06:21 +13:00
|
|
|
/* vim: set ts=4 sw=4 et : */
|
2019-09-02 08:09:47 +12:00
|
|
|
/*
|
|
|
|
* Adapted from qrencode/tests/common.h
|
|
|
|
* Copyright (C) 2006-2017 Kentaro Fukuchi <kentaro@fukuchi.org>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef TESTCOMMON_H
|
|
|
|
#define TESTCOMMON_H
|
|
|
|
|
2021-05-26 07:42:26 +12:00
|
|
|
#define ZINT_DEBUG_TEST_PRINT 16
|
|
|
|
#define ZINT_DEBUG_TEST_LESS_NOISY 32
|
|
|
|
#define ZINT_DEBUG_TEST_KEEP_OUTFILE 64
|
|
|
|
#define ZINT_DEBUG_TEST_BWIPP 128
|
|
|
|
#define ZINT_DEBUG_TEST_PERFORMANCE 256
|
|
|
|
|
2021-03-31 00:18:40 +13:00
|
|
|
#ifdef _WIN32
|
|
|
|
#include <malloc.h>
|
|
|
|
#define alloca(nmemb) _malloca(nmemb)
|
|
|
|
#define popen(command, mode) _popen(command, mode)
|
|
|
|
#define pclose(stream) _pclose(stream)
|
|
|
|
#else
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
2019-09-02 08:09:47 +12:00
|
|
|
#include <stdio.h>
|
|
|
|
#include "../common.h"
|
|
|
|
|
2020-12-22 08:30:07 +13:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2020-05-06 09:28:25 +12:00
|
|
|
#ifndef ARRAY_SIZE
|
|
|
|
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
|
|
|
|
#endif
|
|
|
|
|
2019-09-02 08:09:47 +12:00
|
|
|
extern int assertionFailed;
|
|
|
|
extern int assertionNum;
|
|
|
|
|
|
|
|
#define testStart(__arg__) (testStartReal(__func__, __arg__))
|
|
|
|
#define testEndExp(__arg__) (testEnd(!(__arg__)))
|
|
|
|
void testStartReal(const char *func, const char *name);
|
|
|
|
void testEnd(int result);
|
|
|
|
void testFinish(void);
|
2020-05-06 09:28:25 +12:00
|
|
|
void testSkip(const char *msg);
|
2019-09-02 08:09:47 +12:00
|
|
|
void testReport();
|
|
|
|
|
2020-05-06 09:28:25 +12:00
|
|
|
typedef struct s_testFunction { const char *name; void *func; int has_index; int has_generate; int has_debug; } testFunction;
|
|
|
|
void testRun(int argc, char *argv[], testFunction funcs[], int funcs_size);
|
|
|
|
|
2019-09-02 08:09:47 +12:00
|
|
|
#define assert_exp(__exp__, ...) \
|
2020-05-06 09:28:25 +12:00
|
|
|
{assertionNum++; if (!(__exp__)) {assertionFailed++; printf(__VA_ARGS__); testFinish(); return;}}
|
2019-09-02 08:09:47 +12:00
|
|
|
|
|
|
|
#define assert_zero(__exp__, ...) assert_exp((__exp__) == 0, __VA_ARGS__)
|
|
|
|
#define assert_nonzero(__exp__, ...) assert_exp((__exp__) != 0, __VA_ARGS__)
|
|
|
|
#define assert_null(__ptr__, ...) assert_exp((__ptr__) == NULL, __VA_ARGS__)
|
|
|
|
#define assert_nonnull(__ptr__, ...) assert_exp((__ptr__) != NULL, __VA_ARGS__)
|
|
|
|
#define assert_equal(__e1__, __e2__, ...) assert_exp((__e1__) == (__e2__), __VA_ARGS__)
|
|
|
|
#define assert_notequal(__e1__, __e2__, ...) assert_exp((__e1__) != (__e2__), __VA_ARGS__)
|
2019-10-14 21:49:15 +13:00
|
|
|
#define assert_fail(...) assert_exp(0, __VA_ARGS__)
|
2019-09-02 08:09:47 +12:00
|
|
|
#define assert_nothing(__exp__, ...) {printf(__VA_ARGS__); __exp__;}
|
|
|
|
|
2020-12-22 08:30:07 +13:00
|
|
|
INTERNAL void vector_free(struct zint_symbol *symbol); /* Free vector structures */
|
2019-09-02 08:09:47 +12:00
|
|
|
|
2020-05-16 21:22:33 +12:00
|
|
|
int testUtilSetSymbol(struct zint_symbol *symbol, int symbology, int input_mode, int eci, int option_1, int option_2, int option_3, int output_options, char *data, int length, int debug);
|
2020-10-01 00:19:12 +13:00
|
|
|
const char *testUtilBarcodeName(int symbology);
|
|
|
|
const char *testUtilErrorName(int error_number);
|
|
|
|
const char *testUtilInputModeName(int input_mode);
|
|
|
|
const char *testUtilOption3Name(int option_3);
|
|
|
|
const char *testUtilOutputOptionsName(int output_options);
|
2020-05-06 09:28:25 +12:00
|
|
|
int testUtilDAFTConvert(const struct zint_symbol *symbol, char *buffer, int buffer_size);
|
2021-02-23 13:01:15 +13:00
|
|
|
int testUtilIsValidUTF8(const unsigned char str[], const int length);
|
2020-05-06 09:28:25 +12:00
|
|
|
char *testUtilEscape(char *buffer, int length, char *escaped, int escaped_size);
|
|
|
|
char *testUtilReadCSVField(char *buffer, char *field, int field_size);
|
2020-05-06 12:33:56 +12:00
|
|
|
void testUtilStrCpyRepeat(char *buffer, char *repeat, int size);
|
2020-05-06 09:28:25 +12:00
|
|
|
int testUtilSymbolCmp(const struct zint_symbol *a, const struct zint_symbol *b);
|
|
|
|
struct zint_vector *testUtilVectorCpy(const struct zint_vector *in);
|
|
|
|
int testUtilVectorCmp(const struct zint_vector *a, const struct zint_vector *b);
|
2021-02-23 13:01:15 +13:00
|
|
|
int testUtilModulesDump(const struct zint_symbol *symbol, char dump[], int dump_size);
|
|
|
|
void testUtilModulesPrint(const struct zint_symbol *symbol, const char *prefix, const char *postfix);
|
|
|
|
void testUtilModulesPrintRow(const struct zint_symbol *symbol, int row, const char *prefix, const char *postfix);
|
2020-06-15 01:42:40 +12:00
|
|
|
int testUtilModulesCmp(const struct zint_symbol *symbol, const char *expected, int *width, int *row);
|
|
|
|
int testUtilModulesCmpRow(const struct zint_symbol *symbol, int row, const char *expected, int *width);
|
2020-05-06 09:28:25 +12:00
|
|
|
int testUtilModulesDumpHex(const struct zint_symbol *symbol, char dump[], int dump_size);
|
2020-06-15 01:42:40 +12:00
|
|
|
char *testUtilUIntArrayDump(unsigned int *array, int size, char *dump, int dump_size);
|
|
|
|
char *testUtilUCharArrayDump(unsigned char *array, int size, char *dump, int dump_size);
|
2020-11-02 07:32:55 +13:00
|
|
|
void testUtilBitmapPrint(const struct zint_symbol *symbol, const char *prefix, const char *postfix);
|
|
|
|
int testUtilBitmapCmp(const struct zint_symbol *symbol, const char *expected, int *row, int *column);
|
2020-05-06 09:28:25 +12:00
|
|
|
int testUtilExists(char *filename);
|
|
|
|
int testUtilCmpPngs(char *file1, char *file2);
|
|
|
|
int testUtilCmpTxts(char *txt1, char *txt2);
|
|
|
|
int testUtilCmpBins(char *bin1, char *bin2);
|
|
|
|
int testUtilCmpSvgs(char *svg1, char *svg2);
|
|
|
|
int testUtilCmpEpss(char *eps1, char *eps2);
|
|
|
|
int testUtilHaveIdentify();
|
|
|
|
int testUtilVerifyIdentify(char *filename, int debug);
|
2020-10-04 10:51:08 +13:00
|
|
|
int testUtilHaveLibreOffice();
|
|
|
|
int testUtilVerifyLibreOffice(char *filename, int debug);
|
2020-05-06 09:28:25 +12:00
|
|
|
int testUtilHaveGhostscript();
|
|
|
|
int testUtilVerifyGhostscript(char *filename, int debug);
|
2020-10-04 10:51:08 +13:00
|
|
|
int testUtilHaveVnu();
|
|
|
|
int testUtilVerifyVnu(char *filename, int debug);
|
2021-03-22 10:20:16 +13:00
|
|
|
int testUtilHaveTiffInfo();
|
|
|
|
int testUtilVerifyTiffInfo(char *filename, int debug);
|
2020-10-27 01:21:43 +13:00
|
|
|
int testUtilCanBwipp(int index, const struct zint_symbol *symbol, int option_1, int option_2, int option_3, int debug);
|
2020-10-01 00:19:12 +13:00
|
|
|
int testUtilBwipp(int index, const struct zint_symbol *symbol, int option_1, int option_2, int option_3, const char *data, int length, const char *primary, char *buffer, int buffer_size);
|
2020-07-11 06:39:32 +12:00
|
|
|
int testUtilBwippCmp(const struct zint_symbol *symbol, char *msg, const char *bwipp_buf, const char *expected);
|
|
|
|
int testUtilBwippCmpRow(const struct zint_symbol *symbol, int row, char *msg, const char *bwipp_buf, const char *expected);
|
2019-09-02 08:09:47 +12:00
|
|
|
|
2020-12-22 08:30:07 +13:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-09-02 08:09:47 +12:00
|
|
|
#endif /* TESTCOMMON_H */
|