Mark many merge tests as skip-against-old-server.
[svn.git] / subversion / tests / libsvn_delta / vdelta-test.c
blob9820cb5993f7e0cb8bf5bd767354187959a13edd
1 /* vdelta-test.c -- test driver for text deltas
3 * ====================================================================
4 * Copyright (c) 2000-2004 CollabNet. All rights reserved.
6 * This software is licensed as described in the file COPYING, which
7 * you should have received as part of this distribution. The terms
8 * are also available at http://subversion.tigris.org/license-1.html.
9 * If newer versions of this license are posted there, you may use a
10 * newer version instead, at your option.
12 * This software consists of voluntary contributions made by many
13 * individuals. For exact contribution history, see the revision
14 * history and logs, available at http://subversion.tigris.org/.
15 * ====================================================================
18 #define APR_WANT_STDIO
19 #include <apr_want.h>
21 #include <apr_general.h>
22 #include <assert.h>
24 #include "svn_delta.h"
25 #include "svn_error.h"
26 #include "svn_pools.h"
28 #include "../../libsvn_delta/delta.h"
29 #include "delta-window-test.h"
31 static apr_off_t
32 print_delta_window(const svn_txdelta_window_t *window,
33 const char *tag, int quiet, FILE *stream)
35 if (quiet)
36 return delta_window_size_estimate(window);
37 else
38 return delta_window_print(window, tag, stream);
42 static void
43 do_one_diff(apr_file_t *source_file, apr_file_t *target_file,
44 int *count, apr_off_t *len,
45 int quiet, apr_pool_t *pool,
46 const char *tag, FILE* stream)
48 svn_txdelta_stream_t *delta_stream = NULL;
49 svn_txdelta_window_t *delta_window = NULL;
50 apr_pool_t *fpool = svn_pool_create(pool);
51 apr_pool_t *wpool = svn_pool_create(pool);
53 *count = 0;
54 *len = 0;
55 svn_txdelta(&delta_stream,
56 svn_stream_from_aprfile(source_file, fpool),
57 svn_stream_from_aprfile(target_file, fpool),
58 fpool);
59 do {
60 svn_error_t *err;
61 err = svn_txdelta_next_window(&delta_window, delta_stream, wpool);
62 if (err)
63 svn_handle_error2(err, stderr, TRUE, "vdelta-test: ");
64 if (delta_window != NULL)
66 *len += print_delta_window(delta_window, tag, quiet, stream);
67 svn_pool_clear(wpool);
68 ++*count;
70 } while (delta_window != NULL);
71 fprintf(stream, "%s: (LENGTH %" APR_OFF_T_FMT " +%d)\n", tag, *len, *count);
73 svn_pool_destroy(fpool);
74 svn_pool_destroy(wpool);
78 static apr_file_t *
79 open_binary_read(const char *path, apr_pool_t *pool)
81 apr_status_t apr_err;
82 apr_file_t *fp;
84 apr_err = apr_file_open(&fp, path, (APR_READ | APR_BINARY),
85 APR_OS_DEFAULT, pool);
87 if (apr_err)
89 fprintf(stderr, "unable to open \"%s\" for reading\n", path);
90 exit(1);
93 return fp;
97 int
98 main(int argc, char **argv)
100 apr_file_t *source_file_A = NULL;
101 apr_file_t *target_file_A = NULL;
102 int count_A = 0;
103 apr_off_t len_A = 0;
105 apr_file_t *source_file_B = NULL;
106 apr_file_t *target_file_B = NULL;
107 int count_B = 0;
108 apr_off_t len_B = 0;
110 apr_pool_t *pool;
111 int quiet = 0;
113 if (argc > 1 && argv[1][0] == '-' && argv[1][1] == 'q')
115 quiet = 1;
116 --argc; ++argv;
119 apr_initialize();
120 pool = svn_pool_create(NULL);
122 if (argc == 2)
124 target_file_A = open_binary_read(argv[1], pool);
126 else if (argc == 3)
128 source_file_A = open_binary_read(argv[1], pool);
129 target_file_A = open_binary_read(argv[2], pool);
131 else if (argc == 4)
133 source_file_A = open_binary_read(argv[1], pool);
134 target_file_A = open_binary_read(argv[2], pool);
135 source_file_B = open_binary_read(argv[2], pool);
136 target_file_B = open_binary_read(argv[3], pool);
138 else
140 fprintf(stderr,
141 "Usage: vdelta-test [-q] <target>\n"
142 " or: vdelta-test [-q] <source> <target>\n"
143 " or: vdelta-test [-q] <source> <intermediate> <target>\n");
144 exit(1);
147 do_one_diff(source_file_A, target_file_A,
148 &count_A, &len_A, quiet, pool, "A ", stdout);
150 if (source_file_B)
152 apr_pool_t *fpool = svn_pool_create(pool);
153 apr_pool_t *wpool = svn_pool_create(pool);
154 svn_txdelta_stream_t *stream_A = NULL;
155 svn_txdelta_stream_t *stream_B = NULL;
156 svn_txdelta_window_t *window_A = NULL;
157 svn_txdelta_window_t *window_B = NULL;
158 svn_txdelta_window_t *window_AB = NULL;
159 int count_AB = 0;
160 apr_off_t len_AB = 0;
162 putc('\n', stdout);
163 do_one_diff(source_file_B, target_file_B,
164 &count_B, &len_B, quiet, pool, "B ", stdout);
166 putc('\n', stdout);
169 apr_off_t offset = 0;
171 apr_file_seek(source_file_A, APR_SET, &offset);
172 apr_file_seek(target_file_A, APR_SET, &offset);
173 apr_file_seek(source_file_B, APR_SET, &offset);
174 apr_file_seek(target_file_B, APR_SET, &offset);
177 svn_txdelta(&stream_A,
178 svn_stream_from_aprfile(source_file_A, fpool),
179 svn_stream_from_aprfile(target_file_A, fpool),
180 fpool);
181 svn_txdelta(&stream_B,
182 svn_stream_from_aprfile(source_file_B, fpool),
183 svn_stream_from_aprfile(target_file_B, fpool),
184 fpool);
186 for (count_AB = 0; count_AB < count_B; ++count_AB)
188 svn_error_t *err;
190 err = svn_txdelta_next_window(&window_A, stream_A, wpool);
191 if (err)
192 svn_handle_error2(err, stderr, TRUE, "vdelta-test: ");
193 err = svn_txdelta_next_window(&window_B, stream_B, wpool);
194 if (err)
195 svn_handle_error2(err, stderr, TRUE, "vdelta-test: ");
197 /* Note: It's not possible that window_B is null, we already
198 counted the number of windows in the second delta. */
199 assert(window_A != NULL || window_B->src_ops == 0);
200 if (window_B->src_ops == 0)
202 window_AB = window_B;
203 window_AB->sview_len = 0;
205 else
206 window_AB = svn_txdelta_compose_windows(window_A, window_B,
207 wpool);
208 len_AB += print_delta_window(window_AB, "AB", quiet, stdout);
209 svn_pool_clear(wpool);
212 fprintf(stdout, "AB: (LENGTH %" APR_OFF_T_FMT " +%d)\n",
213 len_AB, count_AB);
216 if (source_file_A) apr_file_close(source_file_A);
217 if (target_file_A) apr_file_close(target_file_A);
218 if (source_file_B) apr_file_close(source_file_B);
219 if (target_file_B) apr_file_close(source_file_B);
221 svn_pool_destroy(pool);
222 apr_terminate();
223 exit(0);