1#!/bin/sh
2
3test_description='check infrastructure for svn importer'
4
5. ./test-lib.sh
6uint32_max=4294967295
7
8test_expect_success 'obj pool: store data' '
9 cat <<-\EOF >expected &&
10 0
11 1
12 EOF
13
14 test-obj-pool <<-\EOF >actual &&
15 alloc one 16
16 set one 13
17 test one 13
18 reset one
19 EOF
20 test_cmp expected actual
21'
22
23test_expect_success 'obj pool: NULL is offset ~0' '
24 echo "$uint32_max" >expected &&
25 echo null one | test-obj-pool >actual &&
26 test_cmp expected actual
27'
28
29test_expect_success 'obj pool: out-of-bounds access' '
30 cat <<-EOF >expected &&
31 0
32 0
33 $uint32_max
34 $uint32_max
35 16
36 20
37 $uint32_max
38 EOF
39
40 test-obj-pool <<-\EOF >actual &&
41 alloc one 16
42 alloc two 16
43 offset one 20
44 offset two 20
45 alloc one 5
46 offset one 20
47 free one 1
48 offset one 20
49 reset one
50 reset two
51 EOF
52 test_cmp expected actual
53'
54
55test_expect_success 'obj pool: high-water mark' '
56 cat <<-\EOF >expected &&
57 0
58 0
59 10
60 20
61 20
62 20
63 EOF
64
65 test-obj-pool <<-\EOF >actual &&
66 alloc one 10
67 committed one
68 alloc one 10
69 commit one
70 committed one
71 alloc one 10
72 free one 20
73 committed one
74 reset one
75 EOF
76 test_cmp expected actual
77'
78
79test_expect_success 'line buffer' '
80 echo HELLO >expected1 &&
81 printf "%s\n" "" HELLO >expected2 &&
82 echo >expected3 &&
83 printf "%s\n" "" Q | q_to_nul >expected4 &&
84 printf "%s\n" foo "" >expected5 &&
85 printf "%s\n" "" foo >expected6 &&
86
87 test-line-buffer <<-\EOF >actual1 &&
88 5
89 HELLO
90 EOF
91
92 test-line-buffer <<-\EOF >actual2 &&
93 0
94
95 5
96 HELLO
97 EOF
98
99 q_to_nul <<-\EOF |
100 1
101 Q
102 EOF
103 test-line-buffer >actual3 &&
104
105 q_to_nul <<-\EOF |
106 0
107
108 1
109 Q
110 EOF
111 test-line-buffer >actual4 &&
112
113 test-line-buffer <<-\EOF >actual5 &&
114 5
115 foo
116 EOF
117
118 test-line-buffer <<-\EOF >actual6 &&
119 0
120
121 5
122 foo
123 EOF
124
125 test_cmp expected1 actual1 &&
126 test_cmp expected2 actual2 &&
127 test_cmp expected3 actual3 &&
128 test_cmp expected4 actual4 &&
129 test_cmp expected5 actual5 &&
130 test_cmp expected6 actual6
131'
132
133test_expect_success 'string pool' '
134 echo a does not equal b >expected.differ &&
135 echo a equals a >expected.match &&
136 echo equals equals equals >expected.matchmore &&
137
138 test-string-pool "a,--b" >actual.differ &&
139 test-string-pool "a,a" >actual.match &&
140 test-string-pool "equals-equals" >actual.matchmore &&
141 test_must_fail test-string-pool a,a,a &&
142 test_must_fail test-string-pool a &&
143
144 test_cmp expected.differ actual.differ &&
145 test_cmp expected.match actual.match &&
146 test_cmp expected.matchmore actual.matchmore
147'
148
149test_expect_success 'treap sort' '
150 cat <<-\EOF >unsorted &&
151 68
152 12
153 13
154 13
155 68
156 13
157 13
158 21
159 10
160 11
161 12
162 13
163 13
164 EOF
165 sort unsorted >expected &&
166
167 test-treap <unsorted >actual &&
168 test_cmp expected actual
169'
170
171test_done