Hi All, This is an updated unit test. The test cases include overflow and detection, and bad params. It was tested with and without PDF_FORCE_BIGNUMS. I did not create the full patch/diff since it can be rejected.
* drop pdf_i64_abs.c torture/unit/base/types/ over top of the existing file Jeff
/* -*- mode: C -*- * * File: pdf-i64-abs.c * Date: Mon May 05 16:30:00 2008 * * GNU PDF Library - Types Module - pdf_i64_abs test case * */ /* Copyright (C) 2008, 2010 Free Software Foundation, Inc. */ /* This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include <config.h> #include <stdio.h> #include <string.h> #include <pdf.h> #include <check.h> #define INTERACTIVE_DEBUG 0 #ifndef pdf_i64_eq # define pdf_i64_eq(x,y) (0 == pdf_i64_cmp((x), (y))) #endif /* pdf_i64_eq */ #ifndef pdf_i64_neq # define pdf_i64_neq(x,y) (0 != pdf_i64_cmp((x), (y))) #endif /* pdf_i64_neq */ typedef struct _KnownAnswer { int32_t nh; /* number high */ uint32_t nl; /* number low */ int32_t mh; /* expected abs high */ uint32_t ml; /* expected abs low */ uint32_t st; /* expected status */ } KnownAnswer; static const KnownAnswer tests_abs[] = { /* 1 */ {0x80000000,0x00000000,0x00000000,0x00000000,PDF_EOVERFLOW}, /* 2 */ {0x80000000,0x00000001,0x7fffffff,0xffffffff,PDF_OK}, /* 3 */ {0xffffffff,0xfffffffe,0x00000000,0x00000002,PDF_OK}, /* 4 */ {0xffffffff,0xffffffff,0x00000000,0x00000001,PDF_OK}, /* 5 */ {0x00000000,0x00000000,0x00000000,0x00000000,PDF_OK}, /* 6 */ {0x00000000,0x00000001,0x00000000,0x00000001,PDF_OK}, /* 7 */ {0x00000000,0x00000002,0x00000000,0x00000002,PDF_OK}, /* 8 */ {0x7fffffff,0xfffffffe,0x7fffffff,0xfffffffe,PDF_OK}, /* 9 */ {0x7fffffff,0xffffffff,0x7fffffff,0xffffffff,PDF_OK}, /* 10 */ {0x00000000,0x00000000,0x00000000,0x00000000,PDF_OK}, /* 11 */ {0x80000000,0x00000000,0x00000000,0x00000000,PDF_EOVERFLOW}, /* 12 */ {0x00000000,0x00000001,0x00000000,0x00000001,PDF_OK}, /* 13 */ {0x80000000,0x00000001,0x7fffffff,0xffffffff,PDF_OK}, /* 14 */ {0x00000000,0x00000002,0x00000000,0x00000002,PDF_OK}, /* 15 */ {0x80000000,0x00000002,0x7fffffff,0xfffffffe,PDF_OK}, /* 16 */ {0x00000000,0x00000004,0x00000000,0x00000004,PDF_OK}, /* 17 */ {0x80000000,0x00000004,0x7fffffff,0xfffffffc,PDF_OK}, /* 18 */ {0x00000000,0x00000008,0x00000000,0x00000008,PDF_OK}, /* 19 */ {0x80000000,0x00000008,0x7fffffff,0xfffffff8,PDF_OK}, /* 20 */ {0x00000000,0x00000010,0x00000000,0x00000010,PDF_OK}, /* 21 */ {0x80000000,0x00000010,0x7fffffff,0xfffffff0,PDF_OK}, /* 22 */ {0x00000000,0x00000020,0x00000000,0x00000020,PDF_OK}, /* 23 */ {0x80000000,0x00000020,0x7fffffff,0xffffffe0,PDF_OK}, /* 24 */ {0x00000000,0x00000040,0x00000000,0x00000040,PDF_OK}, /* 25 */ {0x80000000,0x00000040,0x7fffffff,0xffffffc0,PDF_OK}, /* 26 */ {0x00000000,0x00000080,0x00000000,0x00000080,PDF_OK}, /* 27 */ {0x80000000,0x00000080,0x7fffffff,0xffffff80,PDF_OK}, /* 28 */ {0x00000000,0x00000100,0x00000000,0x00000100,PDF_OK}, /* 29 */ {0x80000000,0x00000100,0x7fffffff,0xffffff00,PDF_OK}, /* 30 */ {0x00000000,0x00000200,0x00000000,0x00000200,PDF_OK}, /* 31 */ {0x80000000,0x00000200,0x7fffffff,0xfffffe00,PDF_OK}, /* 32 */ {0x00000000,0x00000400,0x00000000,0x00000400,PDF_OK}, /* 33 */ {0x80000000,0x00000400,0x7fffffff,0xfffffc00,PDF_OK}, /* 34 */ {0x00000000,0x00000800,0x00000000,0x00000800,PDF_OK}, /* 35 */ {0x80000000,0x00000800,0x7fffffff,0xfffff800,PDF_OK}, /* 36 */ {0x00000000,0x00001000,0x00000000,0x00001000,PDF_OK}, /* 37 */ {0x80000000,0x00001000,0x7fffffff,0xfffff000,PDF_OK}, /* 38 */ {0x00000000,0x00002000,0x00000000,0x00002000,PDF_OK}, /* 39 */ {0x80000000,0x00002000,0x7fffffff,0xffffe000,PDF_OK}, /* 40 */ {0x00000000,0x00004000,0x00000000,0x00004000,PDF_OK}, /* 41 */ {0x80000000,0x00004000,0x7fffffff,0xffffc000,PDF_OK}, /* 42 */ {0x00000000,0x00008000,0x00000000,0x00008000,PDF_OK}, /* 43 */ {0x80000000,0x00008000,0x7fffffff,0xffff8000,PDF_OK}, /* 44 */ {0x00000000,0x00010000,0x00000000,0x00010000,PDF_OK}, /* 45 */ {0x80000000,0x00010000,0x7fffffff,0xffff0000,PDF_OK}, /* 46 */ {0x00000000,0x00020000,0x00000000,0x00020000,PDF_OK}, /* 47 */ {0x80000000,0x00020000,0x7fffffff,0xfffe0000,PDF_OK}, /* 48 */ {0x00000000,0x00040000,0x00000000,0x00040000,PDF_OK}, /* 49 */ {0x80000000,0x00040000,0x7fffffff,0xfffc0000,PDF_OK}, /* 50 */ {0x00000000,0x00080000,0x00000000,0x00080000,PDF_OK}, /* 51 */ {0x80000000,0x00080000,0x7fffffff,0xfff80000,PDF_OK}, /* 52 */ {0x00000000,0x00100000,0x00000000,0x00100000,PDF_OK}, /* 53 */ {0x80000000,0x00100000,0x7fffffff,0xfff00000,PDF_OK}, /* 54 */ {0x00000000,0x00200000,0x00000000,0x00200000,PDF_OK}, /* 55 */ {0x80000000,0x00200000,0x7fffffff,0xffe00000,PDF_OK}, /* 56 */ {0x00000000,0x00400000,0x00000000,0x00400000,PDF_OK}, /* 57 */ {0x80000000,0x00400000,0x7fffffff,0xffc00000,PDF_OK}, /* 58 */ {0x00000000,0x00800000,0x00000000,0x00800000,PDF_OK}, /* 59 */ {0x80000000,0x00800000,0x7fffffff,0xff800000,PDF_OK}, /* 60 */ {0x00000000,0x01000000,0x00000000,0x01000000,PDF_OK}, /* 61 */ {0x80000000,0x01000000,0x7fffffff,0xff000000,PDF_OK}, /* 62 */ {0x00000000,0x02000000,0x00000000,0x02000000,PDF_OK}, /* 63 */ {0x80000000,0x02000000,0x7fffffff,0xfe000000,PDF_OK}, /* 64 */ {0x00000000,0x04000000,0x00000000,0x04000000,PDF_OK}, /* 65 */ {0x80000000,0x04000000,0x7fffffff,0xfc000000,PDF_OK}, /* 66 */ {0x00000000,0x08000000,0x00000000,0x08000000,PDF_OK}, /* 67 */ {0x80000000,0x08000000,0x7fffffff,0xf8000000,PDF_OK}, /* 68 */ {0x00000000,0x10000000,0x00000000,0x10000000,PDF_OK}, /* 69 */ {0x80000000,0x10000000,0x7fffffff,0xf0000000,PDF_OK}, /* 70 */ {0x00000000,0x20000000,0x00000000,0x20000000,PDF_OK}, /* 71 */ {0x80000000,0x20000000,0x7fffffff,0xe0000000,PDF_OK}, /* 72 */ {0x00000000,0x40000000,0x00000000,0x40000000,PDF_OK}, /* 73 */ {0x80000000,0x40000000,0x7fffffff,0xc0000000,PDF_OK}, /* 74 */ {0x00000000,0x80000000,0x00000000,0x80000000,PDF_OK}, /* 75 */ {0x80000000,0x80000000,0x7fffffff,0x80000000,PDF_OK}, /* 76 */ {0x00000001,0x00000000,0x00000001,0x00000000,PDF_OK}, /* 77 */ {0x80000001,0x00000000,0x7fffffff,0x00000000,PDF_OK}, /* 78 */ {0x00000002,0x00000000,0x00000002,0x00000000,PDF_OK}, /* 79 */ {0x80000002,0x00000000,0x7ffffffe,0x00000000,PDF_OK}, /* 80 */ {0x00000004,0x00000000,0x00000004,0x00000000,PDF_OK}, /* 81 */ {0x80000004,0x00000000,0x7ffffffc,0x00000000,PDF_OK}, /* 82 */ {0x00000008,0x00000000,0x00000008,0x00000000,PDF_OK}, /* 83 */ {0x80000008,0x00000000,0x7ffffff8,0x00000000,PDF_OK}, /* 84 */ {0x00000010,0x00000000,0x00000010,0x00000000,PDF_OK}, /* 85 */ {0x80000010,0x00000000,0x7ffffff0,0x00000000,PDF_OK}, /* 86 */ {0x00000020,0x00000000,0x00000020,0x00000000,PDF_OK}, /* 87 */ {0x80000020,0x00000000,0x7fffffe0,0x00000000,PDF_OK}, /* 88 */ {0x00000040,0x00000000,0x00000040,0x00000000,PDF_OK}, /* 89 */ {0x80000040,0x00000000,0x7fffffc0,0x00000000,PDF_OK}, /* 90 */ {0x00000080,0x00000000,0x00000080,0x00000000,PDF_OK}, /* 91 */ {0x80000080,0x00000000,0x7fffff80,0x00000000,PDF_OK}, /* 92 */ {0x00000100,0x00000000,0x00000100,0x00000000,PDF_OK}, /* 93 */ {0x80000100,0x00000000,0x7fffff00,0x00000000,PDF_OK}, /* 94 */ {0x00000200,0x00000000,0x00000200,0x00000000,PDF_OK}, /* 95 */ {0x80000200,0x00000000,0x7ffffe00,0x00000000,PDF_OK}, /* 96 */ {0x00000400,0x00000000,0x00000400,0x00000000,PDF_OK}, /* 97 */ {0x80000400,0x00000000,0x7ffffc00,0x00000000,PDF_OK}, /* 98 */ {0x00000800,0x00000000,0x00000800,0x00000000,PDF_OK}, /* 99 */ {0x80000800,0x00000000,0x7ffff800,0x00000000,PDF_OK}, /* 100 */ {0x00001000,0x00000000,0x00001000,0x00000000,PDF_OK}, /* 101 */ {0x80001000,0x00000000,0x7ffff000,0x00000000,PDF_OK}, /* 102 */ {0x00002000,0x00000000,0x00002000,0x00000000,PDF_OK}, /* 103 */ {0x80002000,0x00000000,0x7fffe000,0x00000000,PDF_OK}, /* 104 */ {0x00004000,0x00000000,0x00004000,0x00000000,PDF_OK}, /* 105 */ {0x80004000,0x00000000,0x7fffc000,0x00000000,PDF_OK}, /* 106 */ {0x00008000,0x00000000,0x00008000,0x00000000,PDF_OK}, /* 107 */ {0x80008000,0x00000000,0x7fff8000,0x00000000,PDF_OK}, /* 108 */ {0x00010000,0x00000000,0x00010000,0x00000000,PDF_OK}, /* 109 */ {0x80010000,0x00000000,0x7fff0000,0x00000000,PDF_OK}, /* 110 */ {0x00020000,0x00000000,0x00020000,0x00000000,PDF_OK}, /* 111 */ {0x80020000,0x00000000,0x7ffe0000,0x00000000,PDF_OK}, /* 112 */ {0x00040000,0x00000000,0x00040000,0x00000000,PDF_OK}, /* 113 */ {0x80040000,0x00000000,0x7ffc0000,0x00000000,PDF_OK}, /* 114 */ {0x00080000,0x00000000,0x00080000,0x00000000,PDF_OK}, /* 115 */ {0x80080000,0x00000000,0x7ff80000,0x00000000,PDF_OK}, /* 116 */ {0x00100000,0x00000000,0x00100000,0x00000000,PDF_OK}, /* 117 */ {0x80100000,0x00000000,0x7ff00000,0x00000000,PDF_OK}, /* 118 */ {0x00200000,0x00000000,0x00200000,0x00000000,PDF_OK}, /* 119 */ {0x80200000,0x00000000,0x7fe00000,0x00000000,PDF_OK}, /* 120 */ {0x00400000,0x00000000,0x00400000,0x00000000,PDF_OK}, /* 121 */ {0x80400000,0x00000000,0x7fc00000,0x00000000,PDF_OK}, /* 122 */ {0x00800000,0x00000000,0x00800000,0x00000000,PDF_OK}, /* 123 */ {0x80800000,0x00000000,0x7f800000,0x00000000,PDF_OK}, /* 124 */ {0x01000000,0x00000000,0x01000000,0x00000000,PDF_OK}, /* 125 */ {0x81000000,0x00000000,0x7f000000,0x00000000,PDF_OK}, /* 126 */ {0x02000000,0x00000000,0x02000000,0x00000000,PDF_OK}, /* 127 */ {0x82000000,0x00000000,0x7e000000,0x00000000,PDF_OK}, /* 128 */ {0x04000000,0x00000000,0x04000000,0x00000000,PDF_OK}, /* 129 */ {0x84000000,0x00000000,0x7c000000,0x00000000,PDF_OK}, /* 130 */ {0x08000000,0x00000000,0x08000000,0x00000000,PDF_OK}, /* 131 */ {0x88000000,0x00000000,0x78000000,0x00000000,PDF_OK}, /* 132 */ {0x10000000,0x00000000,0x10000000,0x00000000,PDF_OK}, /* 133 */ {0x90000000,0x00000000,0x70000000,0x00000000,PDF_OK}, /* 134 */ {0x20000000,0x00000000,0x20000000,0x00000000,PDF_OK}, /* 135 */ {0xa0000000,0x00000000,0x60000000,0x00000000,PDF_OK}, /* 136 */ {0x40000000,0x00000000,0x40000000,0x00000000,PDF_OK}, /* 137 */ {0xc0000000,0x00000000,0x40000000,0x00000000,PDF_OK}, /* 138 */ {0x80000000,0x00000000,0x00000000,0x00000000,PDF_EOVERFLOW}, }; /* * Test: pdf_i64_abs_001 * Description: * Checks if the result is the absolute value of the input variable * Success conditions: * The call should produce a positive number from a negative argument */ START_TEST (pdf_i64_abs_001) { pdf_init(); int i; for(i=0; i<sizeof(tests_abs)/sizeof(tests_abs[0]); i++) { pdf_status_t exp_st, calc_st; pdf_i64_t n, exp_m, calc_m; const KnownAnswer ka = tests_abs[i]; n = pdf_i64_new( ka.nh, ka.nl ); exp_m = pdf_i64_new( ka.mh, ka.ml ); exp_st = (pdf_status_t)ka.st; pdf_i64_abs(&calc_m, n, &calc_st); /* Courtesy output */ int failed = (exp_st != calc_st) || (exp_st == PDF_OK && pdf_i64_neq(exp_m, calc_m)); if(failed) { PDF_DEBUG_BASE (" Absolute test %d failed\n", i + 1); } /* Real test occurs here */ fail_if( exp_st != calc_st ); if( exp_st == PDF_OK ) { fail_if(pdf_i64_neq(exp_m, calc_m)); } } } END_TEST /* * Test: pdf_i64_abs_002 * Description: * Checks the status of a NULL destination * Success conditions: * The call should produce an error */ START_TEST (pdf_i64_abs_002) { pdf_init(); pdf_i64_t n; pdf_status_t status; pdf_i64_abs((pdf_i64_t*)NULL, n, &status); fail_unless(status == PDF_EBADDATA); } END_TEST /* * Test case creation function */ TCase * test_pdf_i64_abs (void) { TCase *tc = tcase_create ("pdf_i64_abs"); tcase_add_test (tc, pdf_i64_abs_001); tcase_add_test (tc, pdf_i64_abs_002); return tc; } /* End of pdf-i64-abs.c */
