1 /*
2 * window-test.c: Test delta window generation
3 *
4 * ====================================================================
5 * Licensed to the Apache Software Foundation (ASF) under one
6 * or more contributor license agreements. See the NOTICE file
7 * distributed with this work for additional information
8 * regarding copyright ownership. The ASF licenses this file
9 * to you under the Apache License, Version 2.0 (the
10 * "License"); you may not use this file except in compliance
11 * with the License. You may obtain a copy of the License at
12 *
13 * http://www.apache.org/licenses/LICENSE-2.0
14 *
15 * Unless required by applicable law or agreed to in writing,
16 * software distributed under the License is distributed on an
17 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18 * KIND, either express or implied. See the License for the
19 * specific language governing permissions and limitations
20 * under the License.
21 * ====================================================================
22 */
23
24 #include <apr_pools.h>
25
26 #include "../svn_test.h"
27
28 #include "svn_types.h"
29 #include "svn_error.h"
30 #include "svn_delta.h"
31
32 #include "private/svn_subr_private.h"
33
34 static svn_error_t *
stream_window_test(apr_pool_t * pool)35 stream_window_test(apr_pool_t *pool)
36 {
37 /* Note: put these in data segment, not the stack */
38 static char source[109001];
39 static char target[109001];
40 int i;
41 char *p = &source[9];
42 svn_checksum_t *expected;
43 svn_checksum_t *actual;
44 svn_string_t source_str;
45 svn_string_t target_str;
46 svn_stream_t *source_stream;
47 svn_stream_t *target_stream;
48 svn_txdelta_stream_t *txstream;
49
50 memcpy(source, "a\nb\nc\nd\ne", 9);
51 for (i = 100; i--; )
52 *p++ = '\n';
53 for (i = 999; i--; p += 109)
54 memcpy(p, source, 109);
55 source[109000] = '\0';
56
57 memcpy(target, source, 109001);
58 for (i = 1000; i--; )
59 target[i*109 + 4] = 'X';
60
61 SVN_ERR(svn_checksum(&expected, svn_checksum_md5, target, 109000, pool));
62 /* f6fd44565e14c6e44b35292719deb77e */
63 printf("expected: %s\n", svn_checksum_to_cstring(expected, pool));
64
65 source_str.data = source;
66 source_str.len = 109000;
67 source_stream = svn_stream_from_string(&source_str, pool);
68
69 target_str.data = target;
70 target_str.len = 109000;
71 target_stream = svn_stream_from_string(&target_str, pool);
72
73 svn_txdelta2(&txstream, source_stream, target_stream, TRUE, pool);
74
75 while (1)
76 {
77 svn_txdelta_window_t *window;
78
79 SVN_ERR(svn_txdelta_next_window(&window, txstream, pool));
80 if (window == NULL)
81 break;
82
83 /* ### examine the window */
84 }
85
86 actual = svn_checksum__from_digest_md5(svn_txdelta_md5_digest(txstream),
87 pool);
88 printf(" actual: %s\n", svn_checksum_to_cstring(actual, pool));
89
90 if (!svn_checksum_match(expected, actual))
91 {
92 return svn_error_create(SVN_ERR_TEST_FAILED, NULL,
93 "Checksums did not match.");
94 }
95
96 return SVN_NO_ERROR;
97 }
98
99
100
101 /* The test table. */
102
103 static int max_threads = 1;
104
105 static struct svn_test_descriptor_t test_funcs[] =
106 {
107 SVN_TEST_NULL,
108 SVN_TEST_PASS2(stream_window_test,
109 "txdelta stream and windows test"),
110 SVN_TEST_NULL
111 };
112
113 SVN_TEST_MAIN
114