1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
|
// tstore4.cpp -- Regression test program, storage tests, part 4
// $Id$
// This is part of Metakit, see http://www.equi4.com/metakit/
#include "regress.h"
void TestStores4()
{
B(s30, Memo storage, 0) W(s30a);
{
c4_Bytes hi ("hi", 2);
c4_Bytes gday ("gday", 4);
c4_Bytes hello ("hello", 5);
c4_MemoProp p1 ("p1");
c4_Storage s1 ("s30a", 1);
s1.SetStructure("a[p1:B]");
c4_View v1 = s1.View("a");
v1.Add(p1 [hi]);
A(p1 (v1[0]) == hi);
v1.Add(p1 [hello]);
A(p1 (v1[0]) == hi);
A(p1 (v1[1]) == hello);
v1.InsertAt(1, p1 [gday]);
A(p1 (v1[0]) == hi);
A(p1 (v1[1]) == gday);
A(p1 (v1[2]) == hello);
s1.Commit();
A(p1 (v1[0]) == hi);
A(p1 (v1[1]) == gday);
A(p1 (v1[2]) == hello);
} D(s30a); R(s30a); E;
// this failed in the unbuffered 1.8.5a interim release in Mk4tcl 1.0.5
B(s31, Check sort buffer use, 0) W(s31a);
{
c4_IntProp p1 ("p1");
c4_Storage s1 ("s31a", 1);
s1.SetStructure("a[p1:I]");
c4_View v1 = s1.View("a");
v1.Add(p1 [3]);
v1.Add(p1 [1]);
v1.Add(p1 [2]);
s1.Commit();
c4_View v2 = v1.SortOn(p1);
A(v2.GetSize() == 3);
A(p1 (v2[0]) == 1);
A(p1 (v2[1]) == 2);
A(p1 (v2[2]) == 3);
} D(s31a); R(s31a); E;
// this failed in 1.8.6, fixed 19990828
B(s32, Set memo empty or same size, 0) W(s32a);
{
c4_Bytes empty;
c4_Bytes full ("full", 4);
c4_Bytes more ("more", 4);
c4_MemoProp p1 ("p1");
c4_Storage s1 ("s32a", 1);
s1.SetStructure("a[p1:B]");
c4_View v1 = s1.View("a");
v1.Add(p1 [full]);
A(p1 (v1[0]) == full);
s1.Commit();
A(p1 (v1[0]) == full);
p1 (v1[0]) = empty;
A(p1 (v1[0]) == empty);
s1.Commit();
A(p1 (v1[0]) == empty);
p1 (v1[0]) = more;
A(p1 (v1[0]) == more);
s1.Commit();
A(p1 (v1[0]) == more);
p1 (v1[0]) = full;
A(p1 (v1[0]) == full);
s1.Commit();
A(p1 (v1[0]) == full);
} D(s32a); R(s32a); E;
// this failed in 1.8.6, fixed 19990828
B(s33, Serialize memo fields, 0) W(s33a); W(s33b); W(s33c);
{
c4_Bytes hi ("hi", 2);
c4_Bytes gday ("gday", 4);
c4_Bytes hello ("hello", 5);
c4_MemoProp p1 ("p1");
c4_Storage s1 ("s33a", 1);
s1.SetStructure("a[p1:B]");
c4_View v1 = s1.View("a");
v1.Add(p1 [hi]);
v1.Add(p1 [gday]);
v1.Add(p1 [hello]);
A(p1 (v1[0]) == hi);
A(p1 (v1[1]) == gday);
A(p1 (v1[2]) == hello);
s1.Commit();
A(p1 (v1[0]) == hi);
A(p1 (v1[1]) == gday);
A(p1 (v1[2]) == hello);
{
c4_FileStream fs1 (fopen("s33b", "wb"), true);
s1.SaveTo(fs1);
}
c4_Storage s2 ("s33c", 1);
c4_FileStream fs2 (fopen("s33b", "rb"), true);
s2.LoadFrom(fs2);
c4_View v2 = s2.View("a");
A(p1 (v2[0]) == hi);
A(p1 (v2[1]) == gday);
A(p1 (v2[2]) == hello);
s2.Commit();
A(p1 (v2[0]) == hi);
A(p1 (v2[1]) == gday);
A(p1 (v2[2]) == hello);
s2.Commit();
A(p1 (v2[0]) == hi);
A(p1 (v2[1]) == gday);
A(p1 (v2[2]) == hello);
} D(s33a); D(s33b); D(s33c); R(s33a); R(s33b); R(s33c); E;
// check smarter commit and commit failure on r/o
B(s34, Smart and failed commits, 0) W(s34a);
{
c4_IntProp p1 ("p1");
{
c4_Storage s1 ("s34a", 1);
s1.SetStructure("a[p1:I]");
c4_View v1 = s1.View("a");
v1.Add(p1 [111]);
A(v1.GetSize() == 1);
A(p1 (v1[0]) == 111);
bool f1 = s1.Commit();
A(f1);
A(v1.GetSize() == 1);
A(p1 (v1[0]) == 111);
bool f2 = s1.Commit();
A(f2); // succeeds, but should not write anything
A(v1.GetSize() == 1);
A(p1 (v1[0]) == 111);
}
{
c4_Storage s1 ("s34a", 0);
c4_View v1 = s1.View("a");
v1.Add(p1 [222]);
A(v1.GetSize() == 2);
A(p1 (v1[0]) == 111);
A(p1 (v1[1]) == 222);
bool f1 = s1.Commit();
A(!f1);
A(v1.GetSize() == 2);
A(p1 (v1[0]) == 111);
A(p1 (v1[1]) == 222);
}
} D(s34a); R(s34a); E;
B(s35, Datafile with preamble, 0) W(s35a);
{
{
c4_FileStream fs1 (fopen("s35a", "wb"), true);
fs1.Write("abc", 3);
}
c4_IntProp p1 ("p1");
{
c4_Storage s1 ("s35a", 1);
s1.SetStructure("a[p1:I]");
c4_View v1 = s1.View("a");
v1.Add(p1 [111]);
A(v1.GetSize() == 1);
A(p1 (v1[0]) == 111);
bool f1 = s1.Commit();
A(f1);
A(v1.GetSize() == 1);
A(p1 (v1[0]) == 111);
bool f2 = s1.Commit();
A(f2); // succeeds, but should not write anything
A(v1.GetSize() == 1);
A(p1 (v1[0]) == 111);
}
{
c4_FileStream fs1 (fopen("s35a", "rb"), true);
char buffer [10];
int n1 = fs1.Read(buffer, 3);
A(n1 == 3);
A(c4_String (buffer, 3) == "abc");
}
{
c4_Storage s1 ("s35a", 0);
c4_View v1 = s1.View("a");
A(v1.GetSize() == 1);
A(p1 (v1[0]) == 111);
v1.Add(p1 [222]);
A(v1.GetSize() == 2);
A(p1 (v1[0]) == 111);
A(p1 (v1[1]) == 222);
bool f1 = s1.Commit();
A(!f1);
A(v1.GetSize() == 2);
A(p1 (v1[0]) == 111);
A(p1 (v1[1]) == 222);
}
} D(s35a); R(s35a); E;
B(s36, Commit after load, 0) W(s36a); W(s36b);
{
c4_IntProp p1 ("p1");
c4_Storage s1 ("s36a", 1);
s1.SetStructure("a[p1:I]");
c4_View v1 = s1.View("a");
v1.Add(p1 [111]);
A(v1.GetSize() == 1);
A(p1 (v1[0]) == 111);
{
c4_FileStream fs1 (fopen("s36b", "wb"), true);
s1.SaveTo(fs1);
}
p1 (v1[0]) = 222;
v1.Add(p1 [333]);
bool f1 = s1.Commit();
A(f1);
A(v1.GetSize() == 2);
A(p1 (v1[0]) == 222);
A(p1 (v1[1]) == 333);
c4_FileStream fs2 (fopen("s36b", "rb"), true);
s1.LoadFrom(fs2);
//A(v1.GetSize() == 0); // should be detached, but it's still 2
c4_View v2 = s1.View("a");
A(v2.GetSize() == 1);
A(p1 (v2[0]) == 111);
// this fails in 2.4.0, reported by James Lupo, August 2001
bool f2 = s1.Commit();
A(f2);
} D(s36a); D(s36b); R(s36a); R(s36b); E;
// fails in 2.4.1, reported Oct 31. 2001 by Steve Baxter
B(s37, Change short partial fields, 0) W(s37a);
{
c4_BytesProp p1 ("p1");
c4_Storage s1( "s37a", true );
c4_View v1 = s1.GetAs("v1[key:I,p1:B]");
v1.Add(p1 [c4_Bytes ("12345", 6)]);
A(v1.GetSize() == 1);
s1.Commit();
c4_Bytes buf = p1 (v1[0]);
A(buf.Size() == 6);
A(buf == c4_Bytes ("12345", 6));
buf = p1(v1[0]).Access(1,3);
A(buf == c4_Bytes ("234", 3));
p1 (v1[0]).Modify(c4_Bytes ("ab", 2), 2, 0);
s1.Commit();
buf = p1 (v1[0]);
A(buf == c4_Bytes ("12ab5", 6));
} D(s37a); R(s37a); E;
// Gross memory use (but no leaks), January 2002, Murat Berk
B(s38, Lots of empty subviews, 0) W(s38a);
{
c4_BytesProp p1 ("p1");
{
c4_Storage s1( "s38a", true );
c4_View v = s1.GetAs("v[v1[p1:S]]");
v.SetSize(100000);
s1.Commit();
}
{
c4_Storage s2( "s38a", true );
c4_View v2 = s2.View("v");
// this should not materialize all the empty subviews
v2.SetSize(v2.GetSize() + 1);
// nor should this
s2.Commit();
}
{
c4_Storage s3( "s38a", true );
c4_View v3 = s3.View("v");
v3.RemoveAt(1, v3.GetSize() - 2);
A(v3.GetSize() == 2);
s3.Commit();
}
} D(s38a); R(s38a); E;
// Fix bug introduced on 7-2-2002, as reported by M. Berk
B(s39, Do not detach empty top-level views, 0) W(s39a);
{
c4_IntProp p1 ("p1");
c4_Storage s1( "s39a", true );
c4_View v1 = s1.GetAs("v1[p1:I]");
s1.Commit();
A(v1.GetSize() == 0);
v1.Add(p1 [123]);
A(v1.GetSize() == 1);
s1.Commit();
c4_View v2 = s1.View("v1");
A(v2.GetSize() == 1); // fails with 0 due to recent bug
} D(s39a); R(s39a); E;
}
|