summaryrefslogtreecommitdiff
path: root/xdelta3
diff options
context:
space:
mode:
authorJosh MacDonald <josh.macdonald@gmail.com>2015-07-16 23:46:00 -0700
committerJosh MacDonald <josh.macdonald@gmail.com>2015-07-16 23:46:00 -0700
commit94b7d2c1c9ed371fb9e86d5e3355124a69f338d3 (patch)
treee8e7653606d0fac679274a93fba1d64019f174d5 /xdelta3
parent8c44ed7581ea8190ee07e477b5c7241f7db8ca23 (diff)
Add printf tests, to be sure about mingw apparently false warnings
Diffstat (limited to 'xdelta3')
-rwxr-xr-xxdelta3/run_release.sh6
-rw-r--r--xdelta3/testing/regtest.cc40
-rw-r--r--xdelta3/xdelta3-internal.h19
-rw-r--r--xdelta3/xdelta3-main.h22
-rw-r--r--xdelta3/xdelta3-test.h11
-rw-r--r--xdelta3/xdelta3.h42
6 files changed, 83 insertions, 57 deletions
diff --git a/xdelta3/run_release.sh b/xdelta3/run_release.sh
index 8b09ab3..c6a95cc 100755
--- a/xdelta3/run_release.sh
+++ b/xdelta3/run_release.sh
@@ -72,13 +72,13 @@ function buildall {
72} 72}
73 73
74# Linux / OS X 64bit 74# Linux / OS X 64bit
75#buildall x86_64-pc-linux-gnu -m64 75buildall x86_64-pc-linux-gnu -m64
76 76
77# Linux / OS X 32bit 77# Linux / OS X 32bit
78#buildall x86_64-pc-linux-gnu -m32 78buildall x86_64-pc-linux-gnu -m32
79 79
80# Windows 32bit 80# Windows 32bit
81buildall i686-w64-mingw32 -mconsole "${MINGW_CFLAGS}" "-L${MINGW_BASE}/mingw-w64-i686/lib ${MINGW_LDFLAGS}" 81buildall i686-w64-mingw32 -mconsole "${MINGW_CFLAGS}" "-L${MINGW_BASE}/mingw-w64-i686/lib ${MINGW_LDFLAGS}"
82 82
83# Windows 64bit 83# Windows 64bit
84#buildall x86_64-w64-mingw32 -mconsole "${MINGW_CFLAGS}" "-L${MINGW_BASE}/mingw-w64-x86_64/lib ${MINGW_LDFLAGS}" 84buildall x86_64-w64-mingw32 -mconsole "${MINGW_CFLAGS}" "-L${MINGW_BASE}/mingw-w64-x86_64/lib ${MINGW_LDFLAGS}"
diff --git a/xdelta3/testing/regtest.cc b/xdelta3/testing/regtest.cc
index a36bded..a09b444 100644
--- a/xdelta3/testing/regtest.cc
+++ b/xdelta3/testing/regtest.cc
@@ -366,28 +366,35 @@ public:
366 CHECK_EQ(0, CmpDifferentBlockBytes(to, recon)); 366 CHECK_EQ(0, CmpDifferentBlockBytes(to, recon));
367 } 367 }
368 368
369 ////////////////////////////////////////////////////////////////////// 369//////////////////////////////////////////////////////////////////////
370 370
371 void TestRandomNumbers() { 371void TestPrintf() {
372 MTRandom rand; 372 char buf[64];
373 int rounds = 1<<20; 373 xoff_t x = XOFF_T_MAX;
374 uint64_t usum = 0; 374 snprintf_func (buf, sizeof(buf), "[%"Q"u]", x);
375 uint64_t esum = 0; 375 XD3_ASSERT(strcmp (buf, "[18446744073709551615]") == 0);
376}
376 377
377 for (int i = 0; i < rounds; i++) { 378void TestRandomNumbers() {
378 usum += rand.Rand32(); 379 MTRandom rand;
379 esum += rand.ExpRand32(1024); 380 int rounds = 1<<20;
380 } 381 uint64_t usum = 0;
382 uint64_t esum = 0;
383
384 for (int i = 0; i < rounds; i++) {
385 usum += rand.Rand32();
386 esum += rand.ExpRand32(1024);
387 }
381 388
382 double allowed_error = 0.01; 389 double allowed_error = 0.01;
383 390
384 uint32_t umean = usum / rounds; 391 uint32_t umean = usum / rounds;
385 uint32_t emean = esum / rounds; 392 uint32_t emean = esum / rounds;
386 393
387 uint32_t uexpect = UINT32_MAX / 2; 394 uint32_t uexpect = UINT32_MAX / 2;
388 uint32_t eexpect = 1024; 395 uint32_t eexpect = 1024;
389 396
390 if (umean < uexpect * (1.0 - allowed_error) || 397 if (umean < uexpect * (1.0 - allowed_error) ||
391 umean > uexpect * (1.0 + allowed_error)) { 398 umean > uexpect * (1.0 + allowed_error)) {
392 XPR(NT "uniform mean error: %u != %u\n", umean, uexpect); 399 XPR(NT "uniform mean error: %u != %u\n", umean, uexpect);
393 abort(); 400 abort();
@@ -1245,6 +1252,7 @@ void TestLastFrontierBlock() {
1245template <class T> 1252template <class T>
1246void UnitTest() { 1253void UnitTest() {
1247 Regtest<T> regtest; 1254 Regtest<T> regtest;
1255 TEST(TestPrintf);
1248 TEST(TestRandomNumbers); 1256 TEST(TestRandomNumbers);
1249 TEST(TestRandomFile); 1257 TEST(TestRandomFile);
1250 TEST(TestFirstByte); 1258 TEST(TestFirstByte);
diff --git a/xdelta3/xdelta3-internal.h b/xdelta3/xdelta3-internal.h
index b14408f..244192c 100644
--- a/xdelta3/xdelta3-internal.h
+++ b/xdelta3/xdelta3-internal.h
@@ -80,6 +80,25 @@ typedef enum
80 XO_WRITE = 1 80 XO_WRITE = 1
81} main_file_modes; 81} main_file_modes;
82 82
83#ifndef XD3_POSIX
84#define XD3_POSIX 0
85#endif
86#ifndef XD3_STDIO
87#define XD3_STDIO 0
88#endif
89#ifndef XD3_WIN32
90#define XD3_WIN32 0
91#endif
92#ifndef NOT_MAIN
93#define NOT_MAIN 0
94#endif
95
96/* If none are set, default to posix. */
97#if (XD3_POSIX + XD3_STDIO + XD3_WIN32) == 0
98#undef XD3_POSIX
99#define XD3_POSIX 1
100#endif
101
83struct _main_file 102struct _main_file
84{ 103{
85#if XD3_WIN32 104#if XD3_WIN32
diff --git a/xdelta3/xdelta3-main.h b/xdelta3/xdelta3-main.h
index 875dd71..e3c4e86 100644
--- a/xdelta3/xdelta3-main.h
+++ b/xdelta3/xdelta3-main.h
@@ -49,19 +49,6 @@
49 49
50/*********************************************************************/ 50/*********************************************************************/
51 51
52#ifndef XD3_POSIX
53#define XD3_POSIX 0
54#endif
55#ifndef XD3_STDIO
56#define XD3_STDIO 0
57#endif
58#ifndef XD3_WIN32
59#define XD3_WIN32 0
60#endif
61#ifndef NOT_MAIN
62#define NOT_MAIN 0
63#endif
64
65/* Combines xd3_strerror() and strerror() */ 52/* Combines xd3_strerror() and strerror() */
66const char* xd3_mainerror(int err_num); 53const char* xd3_mainerror(int err_num);
67 54
@@ -82,12 +69,6 @@ xsnprintf_func (char *str, int n, const char *fmt, ...)
82 return ret; 69 return ret;
83} 70}
84 71
85/* If none are set, default to posix. */
86#if (XD3_POSIX + XD3_STDIO + XD3_WIN32) == 0
87#undef XD3_POSIX
88#define XD3_POSIX 1
89#endif
90
91/* Handle externally-compressed inputs. */ 72/* Handle externally-compressed inputs. */
92#ifndef EXTERNAL_COMPRESSION 73#ifndef EXTERNAL_COMPRESSION
93#define EXTERNAL_COMPRESSION 1 74#define EXTERNAL_COMPRESSION 1
@@ -1248,9 +1229,10 @@ main_set_secondary_flags (xd3_config *config)
1248 VCDIFF TOOLS 1229 VCDIFF TOOLS
1249 *****************************************************************/ 1230 *****************************************************************/
1250 1231
1251#if VCDIFF_TOOLS
1252#include "xdelta3-merge.h" 1232#include "xdelta3-merge.h"
1253 1233
1234#if VCDIFF_TOOLS
1235
1254/* The following macros let VCDIFF print using main_file_write(), 1236/* The following macros let VCDIFF print using main_file_write(),
1255 * for example: 1237 * for example:
1256 * 1238 *
diff --git a/xdelta3/xdelta3-test.h b/xdelta3/xdelta3-test.h
index 659bd31..775da13 100644
--- a/xdelta3/xdelta3-test.h
+++ b/xdelta3/xdelta3-test.h
@@ -215,6 +215,16 @@ test_random_numbers (xd3_stream *stream, int ignore)
215 return XD3_INTERNAL; 215 return XD3_INTERNAL;
216} 216}
217 217
218static int
219test_printf_xoff (xd3_stream *stream, int ignore)
220{
221 char buf[64];
222 xoff_t x = XOFF_T_MAX;
223 snprintf_func (buf, sizeof(buf), "[%"Q"u]", x);
224 XD3_ASSERT(strcmp (buf, "[18446744073709551615]") == 0);
225 return 0;
226}
227
218static void 228static void
219test_unlink (char* file) 229test_unlink (char* file)
220{ 230{
@@ -2852,6 +2862,7 @@ xd3_selftest (void)
2852 2862
2853 int ret; 2863 int ret;
2854 DO_TEST (random_numbers, 0, 0); 2864 DO_TEST (random_numbers, 0, 0);
2865 DO_TEST (printf_xoff, 0, 0);
2855 2866
2856 DO_TEST (decode_integer_end_of_input, 0, 0); 2867 DO_TEST (decode_integer_end_of_input, 0, 0);
2857 DO_TEST (decode_integer_overflow, 0, 0); 2868 DO_TEST (decode_integer_overflow, 0, 0);
diff --git a/xdelta3/xdelta3.h b/xdelta3/xdelta3.h
index b317203..3d230d6 100644
--- a/xdelta3/xdelta3.h
+++ b/xdelta3/xdelta3.h
@@ -131,7 +131,7 @@
131 131
132/* _MSV_VER is defined by Microsoft tools, not by mingw32 */ 132/* _MSV_VER is defined by Microsoft tools, not by mingw32 */
133#ifdef _MSC_VER 133#ifdef _MSC_VER
134#define inline 134/*#define inline*/
135typedef signed int ssize_t; 135typedef signed int ssize_t;
136#if _MSC_VER < 1600 136#if _MSC_VER < 1600
137typedef unsigned char uint8_t; 137typedef unsigned char uint8_t;
@@ -162,8 +162,10 @@ typedef uint32_t usize_t;
162#define _FILE_OFFSET_BITS 64 162#define _FILE_OFFSET_BITS 64
163#endif 163#endif
164 164
165#ifdef _WIN32 165#if defined(_WIN32)
166typedef uint64_t xoff_t; 166typedef uint64_t xoff_t;
167/* Note: The following generates benign warnings in a mingw
168 * cross-compiler */
167#define Q "I64" 169#define Q "I64"
168#elif SIZEOF_UNSIGNED_LONG == 8 170#elif SIZEOF_UNSIGNED_LONG == 8
169typedef unsigned long xoff_t; 171typedef unsigned long xoff_t;
@@ -174,32 +176,36 @@ typedef size_t xoff_t;
174#elif SIZEOF_UNSIGNED_LONG_LONG == 8 176#elif SIZEOF_UNSIGNED_LONG_LONG == 8
175typedef unsigned long long xoff_t; 177typedef unsigned long long xoff_t;
176#define Q "ll" 178#define Q "ll"
177#endif 179#endif /* #define Q */
178
179#ifdef _WIN32
180#if SIZEOF_SIZE_T == 4
181#define Z ""
182#elif SIZEOF_SIZE_T == 8
183#define Z "I64"
184#endif
185#else
186#define Z "z"
187#endif
188 180
189#define SIZEOF_XOFF_T 8 181#define SIZEOF_XOFF_T 8
190#define SIZEOF_USIZE_T 4 182
191#else 183#else /* XD3_USE_LARGEFILE64 == 0 */
184
192#if SIZEOF_UNSIGNED_INT == 4 185#if SIZEOF_UNSIGNED_INT == 4
193typedef unsigned int xoff_t; 186typedef unsigned int xoff_t;
187#elif SIZEOF_UNSIGNED_LONG == 4
188typedef unsigned long xoff_t;
194#else 189#else
195typedef uint32_t xoff_t; 190typedef uint32_t xoff_t;
196#endif 191#endif /* xoff_t is 32 bits */
197 192
198#define SIZEOF_XOFF_T 4 193#define SIZEOF_XOFF_T 4
199#define SIZEOF_USIZE_T 4
200#define Q 194#define Q
195#endif /* 64 vs 32 bit xoff_t */
196
197/* Note: This gets modified in the 64bithash branch. */
198#define SIZEOF_USIZE_T 4
199
200#if SIZEOF_SIZE_T == 4
201#define Z 201#define Z
202#endif 202#elif SIZEOF_SIZE_T == 8
203#ifdef _WIN32
204#define Z "I64"
205#else /* !_WIN32 */
206#define Z "z"
207#endif /* Windows or not */
208#endif /* size_t printf flags */
203 209
204#define USE_UINT32 (SIZEOF_USIZE_T == 4 || \ 210#define USE_UINT32 (SIZEOF_USIZE_T == 4 || \
205 SIZEOF_XOFF_T == 4 || REGRESSION_TEST) 211 SIZEOF_XOFF_T == 4 || REGRESSION_TEST)