zint/backend/tests/testcommon.h

192 lines
8.7 KiB
C
Raw Normal View History

2019-09-02 08:09:47 +12:00
/*
libzint - the open source barcode library
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.
*/
/* 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
#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
#define ZINT_DEBUG_TEST_MINIMIZE 512
#define ZINT_DEBUG_TEST_ZXINGCPP 1024
#ifdef _MSC_VER
#define testutil_popen(command, mode) _popen(command, mode)
#define testutil_pclose(stream) _pclose(stream)
#else
#include <unistd.h>
#define testutil_popen(command, mode) popen(command, mode)
#define testutil_pclose(stream) pclose(stream)
#endif
2019-09-02 08:09:47 +12:00
#include <stdio.h>
#include <errno.h>
2019-09-02 08:09:47 +12:00
#include "../common.h"
#if defined(__clang__)
# pragma clang diagnostic ignored "-Wpedantic"
# pragma clang diagnostic ignored "-Woverlength-strings"
#elif defined(__GNUC__)
# pragma GCC diagnostic ignored "-Wpedantic"
# pragma GCC diagnostic ignored "-Woverlength-strings"
#elif defined(_MSC_VER)
# pragma warning(disable: 4305) /* truncation from 'double' to 'float' */
#endif
#ifdef __cplusplus
extern "C" {
#endif
2019-09-02 08:09:47 +12:00
extern int assertionFailed;
extern int assertionNum;
extern const char *assertionFilename;
2019-09-02 08:09:47 +12:00
#if _MSC_VER < 1900 /* MSVC 2015 */
#define testStart(__arg__) (testStartReal("", __arg__))
#else
2019-09-02 08:09:47 +12:00
#define testStart(__arg__) (testStartReal(__func__, __arg__))
#endif
2019-09-02 08:09:47 +12:00
void testStartReal(const char *func, const char *name);
void testFinish(void);
void testSkip(const char *msg);
void testReport(void);
2019-09-02 08:09:47 +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);
#if _MSC_VER == 1200 /* VC6 */
#include "../ms_stdint.h"
void assert_zero(int exp, const char *fmt, ...);
void assert_nonzero(int exp, const char *fmt, ...);
Performance improvements for linear encoding and raster output - use fixed-length string tables (mostly) instead of (char *) pointer ones (saves ~40K) - re-use C128Table for CODABLOCKF and CODE16K (required removal of Stop character and extra CODE16K-only entry) - use pointer to destination and copy (memcpy/strcpy(), bin_append_posn()) instead of concatenating (strcat()) (mostly) - replace last remaining bin_append()s with bin_append_posn(); bin_append() removed - add length arg to toupper() and expand() (avoids strlen()) - change is_sane() to use table-based flags (avoids an iteration) - rename lookup() to is_sane_lookup() and change to check and return posns and use in pointer to destination loops (avoids strcat()s) - remove special case PHARMA in expand() (dealt with in pharma()) - make #define SILVER/CALCIUM/TECHNETIUM/KRSET etc static strings - replace strchr() -> posn() - CODE128: populate destination once in checksum loop; re-use and export some more routines (c128_set_a/b/c(), c128_put_in_set()) for sharing; prefix defines (SHIFTA -> C128_SHIFTA etc) and existing exported routines - use factor XOR toggle trick in checksum calcs (avoids branch) - raster.c: fill out single 1-pixel row and copy using new draw_bar_line(), copy_bar_line() routines; similarly in buffer_plot compare previous line & copy if same (same technique as used to improve non-half-integer scaling, significant performance increase, (c) codemonkey82); also done for PNG (BMP/GIF/PCX/TIFF not done) - raster/vector/output.c: shorten "output_" prefix -> "out_"; sync vector to other raster changes to try to keep source files similar - 2of5.c: prefix "c25_" JAPANPOST: return error if input data truncated (backward incompatible) DAFT: max chars 50 -> 100 common.c: istwodigit() -> is_twodigit() common.c/emf.c/output.c: use some further stripf()s (MSVC6 float variations) library.c: new check_output_args() helper zint.h: add BARCODE_LAST marker and use in library.c QRCODE: remove a NOLINT (requires clang-tidy-13), one remaining CMake: separate no-optimize from ZINT_DEBUG into new ZINT_NOOPT option
2021-10-21 11:05:30 +13:00
void assert_null(const void *exp, const char *fmt, ...);
void assert_nonnull(const void *exp, const char *fmt, ...);
void assert_equal(int e1, int e2, const char *fmt, ...);
void assert_equalu64(uint64_t e1, uint64_t e2, const char *fmt, ...);
void assert_notequal(int e1, int e2, ...);
#else
2019-09-02 08:09:47 +12:00
#define assert_exp(__exp__, ...) \
{ assertionNum++; if (!(__exp__)) { assertionFailed++; printf("%s:%d ", assertionFilename, __LINE__); \
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_equalu64 assert_equal
2019-09-02 08:09:47 +12:00
#define assert_notequal(__e1__, __e2__, ...) assert_exp((__e1__) != (__e2__), __VA_ARGS__)
#endif
2019-09-02 08:09:47 +12:00
INTERNAL void vector_free(struct zint_symbol *symbol); /* Free vector structures */
2019-09-02 08:09:47 +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);
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);
Performance improvements for linear encoding and raster output - use fixed-length string tables (mostly) instead of (char *) pointer ones (saves ~40K) - re-use C128Table for CODABLOCKF and CODE16K (required removal of Stop character and extra CODE16K-only entry) - use pointer to destination and copy (memcpy/strcpy(), bin_append_posn()) instead of concatenating (strcat()) (mostly) - replace last remaining bin_append()s with bin_append_posn(); bin_append() removed - add length arg to toupper() and expand() (avoids strlen()) - change is_sane() to use table-based flags (avoids an iteration) - rename lookup() to is_sane_lookup() and change to check and return posns and use in pointer to destination loops (avoids strcat()s) - remove special case PHARMA in expand() (dealt with in pharma()) - make #define SILVER/CALCIUM/TECHNETIUM/KRSET etc static strings - replace strchr() -> posn() - CODE128: populate destination once in checksum loop; re-use and export some more routines (c128_set_a/b/c(), c128_put_in_set()) for sharing; prefix defines (SHIFTA -> C128_SHIFTA etc) and existing exported routines - use factor XOR toggle trick in checksum calcs (avoids branch) - raster.c: fill out single 1-pixel row and copy using new draw_bar_line(), copy_bar_line() routines; similarly in buffer_plot compare previous line & copy if same (same technique as used to improve non-half-integer scaling, significant performance increase, (c) codemonkey82); also done for PNG (BMP/GIF/PCX/TIFF not done) - raster/vector/output.c: shorten "output_" prefix -> "out_"; sync vector to other raster changes to try to keep source files similar - 2of5.c: prefix "c25_" JAPANPOST: return error if input data truncated (backward incompatible) DAFT: max chars 50 -> 100 common.c: istwodigit() -> is_twodigit() common.c/emf.c/output.c: use some further stripf()s (MSVC6 float variations) library.c: new check_output_args() helper zint.h: add BARCODE_LAST marker and use in library.c QRCODE: remove a NOLINT (requires clang-tidy-13), one remaining CMake: separate no-optimize from ZINT_DEBUG into new ZINT_NOOPT option
2021-10-21 11:05:30 +13:00
int testUtilDAFTConvert(const struct zint_symbol *symbol, char *buffer, const int buffer_size);
int testUtilIsValidUTF8(const unsigned char str[], const int length);
Performance improvements for linear encoding and raster output - use fixed-length string tables (mostly) instead of (char *) pointer ones (saves ~40K) - re-use C128Table for CODABLOCKF and CODE16K (required removal of Stop character and extra CODE16K-only entry) - use pointer to destination and copy (memcpy/strcpy(), bin_append_posn()) instead of concatenating (strcat()) (mostly) - replace last remaining bin_append()s with bin_append_posn(); bin_append() removed - add length arg to toupper() and expand() (avoids strlen()) - change is_sane() to use table-based flags (avoids an iteration) - rename lookup() to is_sane_lookup() and change to check and return posns and use in pointer to destination loops (avoids strcat()s) - remove special case PHARMA in expand() (dealt with in pharma()) - make #define SILVER/CALCIUM/TECHNETIUM/KRSET etc static strings - replace strchr() -> posn() - CODE128: populate destination once in checksum loop; re-use and export some more routines (c128_set_a/b/c(), c128_put_in_set()) for sharing; prefix defines (SHIFTA -> C128_SHIFTA etc) and existing exported routines - use factor XOR toggle trick in checksum calcs (avoids branch) - raster.c: fill out single 1-pixel row and copy using new draw_bar_line(), copy_bar_line() routines; similarly in buffer_plot compare previous line & copy if same (same technique as used to improve non-half-integer scaling, significant performance increase, (c) codemonkey82); also done for PNG (BMP/GIF/PCX/TIFF not done) - raster/vector/output.c: shorten "output_" prefix -> "out_"; sync vector to other raster changes to try to keep source files similar - 2of5.c: prefix "c25_" JAPANPOST: return error if input data truncated (backward incompatible) DAFT: max chars 50 -> 100 common.c: istwodigit() -> is_twodigit() common.c/emf.c/output.c: use some further stripf()s (MSVC6 float variations) library.c: new check_output_args() helper zint.h: add BARCODE_LAST marker and use in library.c QRCODE: remove a NOLINT (requires clang-tidy-13), one remaining CMake: separate no-optimize from ZINT_DEBUG into new ZINT_NOOPT option
2021-10-21 11:05:30 +13:00
char *testUtilEscape(const char *buffer, const int length, char *escaped, const int escaped_size);
const char *testUtilReadCSVField(const char *buffer, char *field, const int field_size);
void testUtilStrCpyRepeat(char *buffer, const char *repeat, const int size);
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);
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);
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);
char *testUtilUIntArrayDump(unsigned int *array, int size, char *dump, int dump_size);
char *testUtilUCharArrayDump(unsigned char *array, int size, char *dump, int dump_size);
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);
int testUtilDataPath(char *buffer, int buffer_size, const char *subdir, const char *filename);
int testUtilExists(const char *filename);
int testUtilDirExists(const char *dirname);
int testUtilMkDir(const char *dirname);
int testUtilRmDir(const char *dirname);
int testUtilRename(const char *oldpath, const char *newpath);
int testUtilCmpPngs(const char *file1, const char *file2);
int testUtilCmpTxts(const char *txt1, const char *txt2);
int testUtilCmpBins(const char *bin1, const char *bin2);
int testUtilCmpSvgs(const char *svg1, const char *svg2);
int testUtilCmpEpss(const char *eps1, const char *eps2);
int testUtilHaveIdentify(void);
int testUtilVerifyIdentify(const char *filename, int debug);
int testUtilHaveLibreOffice(void);
int testUtilVerifyLibreOffice(const char *filename, int debug);
int testUtilHaveGhostscript(void);
int testUtilVerifyGhostscript(const char *filename, int debug);
int testUtilHaveVnu(void);
int testUtilVerifyVnu(const char *filename, int debug);
int testUtilHaveTiffInfo(void);
int testUtilVerifyTiffInfo(const char *filename, int debug);
int testUtilCanBwipp(int index, const struct zint_symbol *symbol, int option_1, int option_2, int option_3,
int debug);
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);
int testUtilBwippCmp(const struct zint_symbol *symbol, char *msg, char *cmp_buf, const char *expected);
int testUtilBwippCmpRow(const struct zint_symbol *symbol, int row, char *msg, const char *cmp_buf,
const char *expected);
2019-09-02 08:09:47 +12:00
int testUtilHaveZXingCPPDecoder(void);
int testUtilCanZXingCPP(int index, const struct zint_symbol *symbol, const char *data, const int debug);
int testUtilZXingCPP(int index, struct zint_symbol *symbol, const char *source, char *bits, char *buffer,
const int buffer_size, int *p_cmp_len);
int testUtilZXingCPPCmp(struct zint_symbol *symbol, char *msg, char *cmp_buf, int cmp_len,
const char *expected, int expected_len, const char *primary, char *ret_buf, int *p_ret_len);
#ifdef __cplusplus
}
#endif
2019-09-02 08:09:47 +12:00
#endif /* TESTCOMMON_H */