diff options
author | josh.macdonald <jmacd@users.noreply.github.com> | 2008-06-27 03:41:48 +0000 |
---|---|---|
committer | josh.macdonald <jmacd@users.noreply.github.com> | 2008-06-27 03:41:48 +0000 |
commit | e127914b71638072798f7c02e93caf9377ba7385 (patch) | |
tree | f3a4584604aac0f26e7f9d9a101b05612786744b /xdelta3/testing | |
parent | c31f63a124fc6221ee82e9563bb7aeeb238c92e8 (diff) |
Adds new testing directory for a C++ test, makes xdelta3-test.h compile with C++.
Removes xdelta3-test2.h, moves contents into xdelta3-regtest.cc
Diffstat (limited to 'xdelta3/testing')
-rwxr-xr-x | xdelta3/testing/Makefile | 13 | ||||
-rw-r--r-- | xdelta3/testing/xdelta3-regtest.cc | 284 |
2 files changed, 297 insertions, 0 deletions
diff --git a/xdelta3/testing/Makefile b/xdelta3/testing/Makefile new file mode 100755 index 0000000..a6cd152 --- /dev/null +++ b/xdelta3/testing/Makefile | |||
@@ -0,0 +1,13 @@ | |||
1 | CFLAGS = -g -Wall -I.. -DXD3_DEBUG=1 -DNDEBUG=0 | ||
2 | |||
3 | DEPS = ../*.h ../*.c *.cc | ||
4 | |||
5 | TARGETS = xdelta3-regtest | ||
6 | |||
7 | all: $(TARGETS) | ||
8 | |||
9 | xdelta3-regtest: $(DEPS) | ||
10 | $(CXX) $(CFLAGS) xdelta3-regtest.cc -o xdelta3-regtest | ||
11 | |||
12 | clean: | ||
13 | rm -f *.exe *.stackdump $(TARGETS) | ||
diff --git a/xdelta3/testing/xdelta3-regtest.cc b/xdelta3/testing/xdelta3-regtest.cc new file mode 100644 index 0000000..a43ed92 --- /dev/null +++ b/xdelta3/testing/xdelta3-regtest.cc | |||
@@ -0,0 +1,284 @@ | |||
1 | /* xdelta 3 - delta compression tools and library | ||
2 | * Copyright (C) 2001, 2003, 2004, 2005, 2006, 2007, 2008. Joshua P. MacDonald | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify | ||
5 | * it under the terms of the GNU General Public License as published by | ||
6 | * the Free Software Foundation; either version 2 of the License, or | ||
7 | * (at your option) any later version. | ||
8 | * | ||
9 | * This program is distributed in the hope that it will be useful, | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | * GNU General Public License for more details. | ||
13 | * | ||
14 | * You should have received a copy of the GNU General Public License | ||
15 | * along with this program; if not, write to the Free Software | ||
16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
17 | */ | ||
18 | |||
19 | // This file started because I wanted to write a test in C++ rather than C. | ||
20 | |||
21 | extern "C" { | ||
22 | #define NOT_MAIN 1 | ||
23 | #define REGRESSION_TEST 1 | ||
24 | #include "../xdelta3.c" | ||
25 | } | ||
26 | |||
27 | namespace { | ||
28 | |||
29 | const int TEST_SEED1 = 0x1970; | ||
30 | |||
31 | class RandomFileSpec { | ||
32 | public: | ||
33 | RandomFileSpec() | ||
34 | : size_(0), | ||
35 | seed_(0), | ||
36 | filedata_(NULL), | ||
37 | filename_(NULL), | ||
38 | deltafile_(NULL) { | ||
39 | main_file_init(&file_); | ||
40 | mt_init(&mt_, TEST_SEED1); | ||
41 | } | ||
42 | int size_; | ||
43 | int seed_; | ||
44 | uint8_t *filedata_; | ||
45 | char *filename_; | ||
46 | char *deltafile_; | ||
47 | main_file file_; | ||
48 | mtrand mt_; | ||
49 | }; | ||
50 | |||
51 | } // namespace | ||
52 | |||
53 | int main(int argc, char **argv) { | ||
54 | RandomFileSpec spec1; | ||
55 | |||
56 | return 0; | ||
57 | } | ||
58 | |||
59 | |||
60 | #if 0 | ||
61 | static const int TESTS_PER_PARAMETER = 100; | ||
62 | |||
63 | struct random_file_spec_ { | ||
64 | int size; | ||
65 | int seed; | ||
66 | main_file file; | ||
67 | uint8_t *tmp_data; | ||
68 | char *tmp_copy; | ||
69 | char *tmp_delta; | ||
70 | mtrand mt; | ||
71 | }; | ||
72 | |||
73 | struct random_parameters_ { | ||
74 | int file_size; | ||
75 | int window_size; | ||
76 | int add_size; | ||
77 | int del_size; | ||
78 | }; | ||
79 | |||
80 | typedef struct random_file_spec_ random_file_spec; | ||
81 | typedef struct random_parameters_ random_parameters; | ||
82 | |||
83 | static const random_parameters test_parameters[] = { | ||
84 | { 16384, 4096, 16, 0 }, | ||
85 | { 16384, 4096, 0, 16 }, | ||
86 | { 16384, 4096, 16, 16 }, | ||
87 | { 16384, 4096, 128, 128 }, | ||
88 | }; | ||
89 | |||
90 | static random_parameters current_parameters; | ||
91 | static int test2_malloc_count; | ||
92 | |||
93 | void | ||
94 | set_test_parameters (const random_parameters *params) | ||
95 | { | ||
96 | current_parameters = *params; | ||
97 | } | ||
98 | |||
99 | void | ||
100 | set_random_parameters () | ||
101 | { | ||
102 | // TODO(jmacd) | ||
103 | current_parameters = test_parameters[0]; | ||
104 | } | ||
105 | |||
106 | void* | ||
107 | test2_malloc (int size) | ||
108 | { | ||
109 | test2_malloc_count++; | ||
110 | return malloc(size); | ||
111 | } | ||
112 | |||
113 | void | ||
114 | test2_free (void *ptr) | ||
115 | { | ||
116 | test2_malloc_count--; | ||
117 | free (ptr); | ||
118 | XD3_ASSERT (test2_malloc_count >= 0); | ||
119 | } | ||
120 | |||
121 | void | ||
122 | random_file_spec_clear (random_file_spec *spec) | ||
123 | { | ||
124 | if (spec->tmp_copy) | ||
125 | { | ||
126 | unlink (spec->tmp_copy); /* TODO(jmacd): make portable */ | ||
127 | test2_free (spec->tmp_copy); | ||
128 | spec->tmp_copy = NULL; | ||
129 | } | ||
130 | |||
131 | if (spec->tmp_delta) | ||
132 | { | ||
133 | unlink (spec->tmp_delta); | ||
134 | test2_free (spec->tmp_delta); | ||
135 | spec->tmp_delta = NULL; | ||
136 | } | ||
137 | |||
138 | if (spec->tmp_data) | ||
139 | { | ||
140 | test2_free (spec->tmp_data); | ||
141 | spec->tmp_data = NULL; | ||
142 | } | ||
143 | } | ||
144 | |||
145 | void | ||
146 | random_file_spec_swap (random_file_spec *a, | ||
147 | random_file_spec *b) | ||
148 | { | ||
149 | random_file_spec t = *a; | ||
150 | *a = *b; | ||
151 | *b = t; | ||
152 | } | ||
153 | |||
154 | int | ||
155 | random_file_spec_generate (random_file_spec *spec) | ||
156 | { | ||
157 | int i; | ||
158 | spec->seed = mt_random (&static_mtrand); | ||
159 | mt_init (&spec->mt, spec->seed); | ||
160 | main_file_init (&spec->file); | ||
161 | |||
162 | test_setup(); | ||
163 | spec->tmp_copy = test2_malloc(strlen(TEST_TARGET_FILE) + 1); | ||
164 | strcpy (spec->tmp_copy, TEST_TARGET_FILE); | ||
165 | |||
166 | spec->size = current_parameters.file_size; | ||
167 | spec->tmp_data = (uint8_t*)test2_malloc(spec->size); | ||
168 | |||
169 | for (i = 0; i < spec->size; i++) | ||
170 | { | ||
171 | spec->tmp_data[i] = mt_random(&spec->mt); | ||
172 | } | ||
173 | |||
174 | return 0; | ||
175 | } | ||
176 | |||
177 | int | ||
178 | random_file_spec_write (random_file_spec *spec) | ||
179 | { | ||
180 | int ret; | ||
181 | if ((ret = main_file_open (&spec->file, spec->tmp_copy, XO_WRITE)) || | ||
182 | (ret = main_file_write (&spec->file, spec->tmp_data, spec->size, | ||
183 | "write failed")) || | ||
184 | (ret = main_file_close (&spec->file))) | ||
185 | { | ||
186 | return ret; | ||
187 | } | ||
188 | |||
189 | return 0; | ||
190 | } | ||
191 | |||
192 | int | ||
193 | random_file_spec_mutate (random_file_spec *from, random_file_spec *to) | ||
194 | { | ||
195 | to->seed = mt_random (&static_mtrand); | ||
196 | mt_init (&to->mt, to->seed); | ||
197 | main_file_init (&spec->file); | ||
198 | |||
199 | test_setup(); | ||
200 | spec->tmp_copy = test2_malloc(strlen(TEST_TARGET_FILE) + 1); | ||
201 | strcpy (spec->tmp_copy, TEST_TARGET_FILE); | ||
202 | |||
203 | spec->size = current_parameters.file_size; | ||
204 | spec->tmp_data = (uint8_t*)test2_malloc(spec->size); | ||
205 | |||
206 | |||
207 | return 0; | ||
208 | } | ||
209 | |||
210 | int | ||
211 | random_file_spec_delta (random_file_spec *from, random_file_spec *to) | ||
212 | { | ||
213 | return 0; | ||
214 | } | ||
215 | |||
216 | int | ||
217 | test_merge_chain (random_file_spec *specs, int number) | ||
218 | { | ||
219 | /* "number" is from 1 (a single delta) between specs[0] and | ||
220 | * specs[1], to N, an (N-1) chain from specs[0] to specs[N]. */ | ||
221 | return 0; | ||
222 | } | ||
223 | |||
224 | static int | ||
225 | test_merge_command () | ||
226 | { | ||
227 | /* Repeat random-input testing for a number of iterations. | ||
228 | * Test 2, 3, and 4-file scenarios (i.e., 1, 2, and 3-delta merges). */ | ||
229 | int ret; | ||
230 | int iter = 0, param = 0; | ||
231 | random_file_spec spec[4]; | ||
232 | |||
233 | memset (spec, 0, sizeof (spec)); | ||
234 | |||
235 | /* Repeat this loop for TESTS_PER_PARAMETER * #parameters * 2. The | ||
236 | * first #parameters repeats are for the provided values, the second | ||
237 | * set of repeats use random parameters. */ | ||
238 | for (; param < (2 * SIZEOF_ARRAY(test_parameters)); iter++) | ||
239 | { | ||
240 | if (iter % TESTS_PER_PARAMETER == 0) | ||
241 | { | ||
242 | if (param < SIZEOF_ARRAY(test_parameters)) | ||
243 | { | ||
244 | set_test_parameters (&test_parameters[param]); | ||
245 | } | ||
246 | else | ||
247 | { | ||
248 | set_random_parameters (); | ||
249 | } | ||
250 | |||
251 | param++; | ||
252 | |||
253 | if ((ret = random_file_spec_generate (&spec[0]))) { return ret; } | ||
254 | if ((ret = random_file_spec_write (&spec[0]))) { return ret; } | ||
255 | |||
256 | if ((ret = random_file_spec_mutate (&spec[0], &spec[1]))) { return ret; } | ||
257 | if ((ret = random_file_spec_write (&spec[1]))) { return ret; } | ||
258 | if ((ret = random_file_spec_delta (&spec[0], &spec[1]))) { return ret; } | ||
259 | |||
260 | if ((ret = random_file_spec_mutate (&spec[1], &spec[2]))) { return ret; } | ||
261 | if ((ret = random_file_spec_write (&spec[2]))) { return ret; } | ||
262 | if ((ret = random_file_spec_delta (&spec[1], &spec[2]))) { return ret; } | ||
263 | } | ||
264 | |||
265 | /* Each iteration creates a new mutation. */ | ||
266 | if ((ret = random_file_spec_mutate (&spec[2], &spec[3]))) { return ret; } | ||
267 | if ((ret = random_file_spec_write (&spec[3]))) { return ret; } | ||
268 | if ((ret = random_file_spec_delta (&spec[2], &spec[3]))) { return ret; } | ||
269 | |||
270 | /* Test 1, 2, and 3 */ | ||
271 | if ((ret = test_merge_chain (spec, 1))) { return ret; } | ||
272 | if ((ret = test_merge_chain (spec, 2))) { return ret; } | ||
273 | if ((ret = test_merge_chain (spec, 3))) { return ret; } | ||
274 | |||
275 | /* Clear 1st input, shift inputs */ | ||
276 | random_file_spec_clear (&spec[0]); | ||
277 | random_file_spec_swap (&spec[0], &spec[1]); | ||
278 | random_file_spec_swap (&spec[1], &spec[2]); | ||
279 | random_file_spec_swap (&spec[2], &spec[3]); | ||
280 | } | ||
281 | |||
282 | return 0; | ||
283 | } | ||
284 | #endif | ||