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
21 #include <apr_general.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"
32 print_delta_window(const svn_txdelta_window_t
*window
,
33 const char *tag
, int quiet
, FILE *stream
)
36 return delta_window_size_estimate(window
);
38 return delta_window_print(window
, tag
, stream
);
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
);
55 svn_txdelta(&delta_stream
,
56 svn_stream_from_aprfile(source_file
, fpool
),
57 svn_stream_from_aprfile(target_file
, fpool
),
61 err
= svn_txdelta_next_window(&delta_window
, delta_stream
, wpool
);
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
);
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
);
79 open_binary_read(const char *path
, apr_pool_t
*pool
)
84 apr_err
= apr_file_open(&fp
, path
, (APR_READ
| APR_BINARY
),
85 APR_OS_DEFAULT
, pool
);
89 fprintf(stderr
, "unable to open \"%s\" for reading\n", path
);
98 main(int argc
, char **argv
)
100 apr_file_t
*source_file_A
= NULL
;
101 apr_file_t
*target_file_A
= NULL
;
105 apr_file_t
*source_file_B
= NULL
;
106 apr_file_t
*target_file_B
= NULL
;
113 if (argc
> 1 && argv
[1][0] == '-' && argv
[1][1] == 'q')
120 pool
= svn_pool_create(NULL
);
124 target_file_A
= open_binary_read(argv
[1], pool
);
128 source_file_A
= open_binary_read(argv
[1], pool
);
129 target_file_A
= open_binary_read(argv
[2], pool
);
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
);
141 "Usage: vdelta-test [-q] <target>\n"
142 " or: vdelta-test [-q] <source> <target>\n"
143 " or: vdelta-test [-q] <source> <intermediate> <target>\n");
147 do_one_diff(source_file_A
, target_file_A
,
148 &count_A
, &len_A
, quiet
, pool
, "A ", stdout
);
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
;
160 apr_off_t len_AB
= 0;
163 do_one_diff(source_file_B
, target_file_B
,
164 &count_B
, &len_B
, quiet
, pool
, "B ", 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
),
181 svn_txdelta(&stream_B
,
182 svn_stream_from_aprfile(source_file_B
, fpool
),
183 svn_stream_from_aprfile(target_file_B
, fpool
),
186 for (count_AB
= 0; count_AB
< count_B
; ++count_AB
)
190 err
= svn_txdelta_next_window(&window_A
, stream_A
, wpool
);
192 svn_handle_error2(err
, stderr
, TRUE
, "vdelta-test: ");
193 err
= svn_txdelta_next_window(&window_B
, stream_B
, wpool
);
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;
206 window_AB
= svn_txdelta_compose_windows(window_A
, window_B
,
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",
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
);