8000 Tests for Galley Vector · postgrespro/libblobstamper@7dcc092 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7dcc092

Browse files
Tests for Galley Vector
1 parent d2648e0 commit 7dcc092

File tree

3 files changed

+213
-3
lines changed

3 files changed

+213
-3
lines changed

blobstamper/galley.cpp

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,4 +322,54 @@ GalleyVector::ExtractStr(Blob &blob)
322322
return res;
323323
}
324324

325+
int
326+
GalleyVector::minSize()
327+
{
328+
bool has_variated_stamps = false;
329+
bool has_unbounded_stamps = false;
330+
331+
int res = 0;
332+
333+
/* Loop throight stamps calculating total sizes and seeing what kind of stamps do we have*/
334+
for(StampBase & s : stamps)
335+
{
336+
res += s.minSize();
337+
if (s.isVariated())
338+
{
339+
has_variated_stamps = true;
340+
res += ORACLE_SIZE; //Each variated stamp needs an oracle to predict it's size
341+
}
342+
if (s.isUnbounded())
343+
{
344+
has_unbounded_stamps = true;
345+
res += ORACLE_SIZE; //Each unbounded stamp needs an oracle to predict it's size
346+
}
347+
}
348+
if (has_variated_stamps && has_unbounded_stamps)
349+
res += ORACLE_SIZE; // Need another oracle to predict how space is devided between variated and unbounded stamps
350+
351+
return res;
352+
}
353+
354+
int
355+
GalleyVector::maxSize()
356+
{
357+
int res = 0;
358+
359+
/* Loop throight stamps calculating total sizes and seeing what kind of stamps do we have*/
360+
for(StampBase & s : stamps)
361+
{
362+
res += s.maxSize();
363+
if (s.isVariated())
364+
{
365+
res += ORACLE_SIZE; // Each variated stamp needs an oracle to predict it's size. It also affects max size
366+
}
367+
if (s.isUnbounded())
368+
{
369+
return -1; // Junst one unbounded stamp makes all thing unbounded
370+
}
371+
}
372+
return res;
373+
}
374+
325375

blobstamper/galley.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ class GalleyVector : public GalleyBase
4747
std::vector<std::string> ExtractStr(Blob &blob);
4848
// std::list<void *> ExtractBin(Blob &blob);
4949

50-
int minSize() override {return -2;}; // FIXME
51-
int maxSize() override {return -3;}; //FIXME /* Sereies always takes as much data as it can take */
50+
int minSize() override;
51+
int maxSize() override;
5252
};
5353

5454

t/300-galley.cpp

Lines changed: 161 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ char longer_sample[]="z1234567*89abcde&fghijklmnopqrstuvwxyzAB%CDEFGHIJKLMNOPQRS
1818
int
1919
main()
2020
{
21-
TEST_START(18);
21+
TEST_START(46);
2222
/* Test Galley Sereies with fixed size stampp*/
2323
{ /* 1..4 */
2424
std::string expected1 = "12";
@@ -149,10 +149,170 @@ main()
149149
res.pop_front();
150150

151151
ok(res.empty(), "GalleySeries, unlimited size string stamp: The rest of the list is empty");
152+
153+
}
154+
155+
/* Test Galley Vector with fixed size stamps*/
156+
{ /* 19 .. 22*/
157+
158+
char sample[]="z1234567*89abcde&fghijklm";
159+
160+
std::string expected1 = "z1";
161+
std::string expected2 = "23";
162+
163+
164+
Blob blob(sample, strlen(sample));
165+
166+
StampTwoChars stamp;
167+
std::vector<std::reference_wrapper<StampBase>> stamps;
168+
stamps.push_back(stamp);
169+
stamps.push_back(stamp);
170+
171+
GalleyVector galley(stamps);
172+
173+
std::vector<std::string> res = galley.ExtractStr(blob);
174+
std::string str;
175+
176+
str = res[0];
177+
is(str, expected1, "GalleyVector, fixed size string stamps: First element of vector is ok");
178+
179+
str = res[1];
180+
is(str, expected2, "GalleyVector, fixed size string stamps: Second element of vector is ok");
181+
182+
is(res.size(), 2, "GalleyVector, fixed size string stamps: The vector has only two elements ");
183+
184+
is(blob.Size(), strlen(sample) - res[0].length() - res[1].length(), "GalleyVector: shifts no extra bytes for fixed stamps");
185+
186+
is(galley.minSize(), stamp.minSize()*2, "GalleyVector, fixed size string stamps: galley min size is ok");
187+
is(galley.maxSize(), stamp.maxSize()*2, "GalleyVector, fixed size string stamps: galley max size is ok");
188+
}
189+
190+
/* Test Galley Vector with variated size stamps*/
191+
{ /* 25 .. 30*/
192+
193+
char sample[]="z1234567*89abcde&fghijklm";
194+
195+
std::string expected1 = "456";
196+
std::string expected2 = "7*8";
197+
198+
Blob blob(sample, strlen(sample));
199+
200+
StampSeveralChars stamp;
201+
std::vector<std::reference_wrapper<StampBase>> stamps;
202+
stamps.push_back(stamp);
203+
stamps.push_back(stamp);
204+
205+
GalleyVector galley(stamps);
206+
207+
std::vector<std::string> res = galley.ExtractStr(blob);
208+
std::string str;
209+
210+
str = res[0];
211+
is(str, expected1, "GalleyVector, variated size string stamp: First element of vector is ok");
212+
213+
str = res[1];
214+
is(str, expected2, "GalleyVector, variated size string stamp: Second element of vector is ok");
215+
216+
is(res.size(), 2, "GalleyVector, variated size string stamp: The vector has only two elements ");
217+
218+
is(blob.Size(), strlen(sample) - res[0].length() - res[1].length() - ORACLE_SIZE*2, "GalleyVector: shifts one oracle for each variated stamps");
219+
220+
is(galley.minSize(), stamp.minSize()*2 + ORACLE_SIZE * 2, "GalleyVector, variated size string stamps: galley min size is ok");
221+
is(galley.maxSize(), stamp.maxSize()*2 + ORACLE_SIZE * 2, "GalleyVector, variated size string stamps: galley max size is ok");
222+
}
223+
224+
/* Test Galley Vector with unbounded size stamps*/
225+
{ /* 31 .. 36*/
226+
227+
char sample[]="z1234567*89abcde&fghijklm";
228+
229+
std::string expected1 = "(45, 67, *8, 9a, bc)";
230+
std::string expected2 = "(de, &f, gh, ij, kl)";
231+
232+
Blob blob(sample, strlen(sample));
233+
234+
StampTwoCharsList stamp;
235+
std::vector<std::reference_wrapper<StampBase>> stamps;
236+
stamps.push_back(stamp);
237+
stamps.push_back(stamp);
238+
239+
GalleyVector galley(stamps);
240+
241+
std::vector<std::string> res = galley.ExtractStr(blob);
242+
std::string str;
243+
244+
str = res[0];
245+
is(str, expected1, "GalleyVector, unbounded size string stamp: First element of vector is ok");
246+
247+
str = res[1];
248+
is(str, expected2, "GalleyVector, unbounded size string stamp: Second element of vector is ok");
249+
250+
is(res.size(), 2, "GalleyVector, unbounded size string stamp: The vector has only two elements ");
251+
252+
is(blob.Size(), 0 , "GalleyVector: will use all data for unbounded stamp");
253+
254+
is(galley.minSize(), stamp.minSize()*2 + ORACLE_SIZE * 2, "GalleyVector, unbounded size string stamps: galley min size is ok");
255+
is(galley.maxSize(), -1, "GalleyVector, unbounded size string stamps: galley max size is ok");
256+
152257
}
153258

259+
/* Test Galley Vector with mixed stam types */
260+
{ /* 37 .. 46*/
154261

262+
char sample[]="z1234567*89abcde&fghijklmnopqrstuvwxyzAB%CDEFGHIJKLMNOPQRSTUVWXYZ!";
155263

264+
std::string expected1 = "(9a, bc, de, &f, gh, ij, kl, mn, op, qr, st)"; // first u_stamp
265+
std::string expected2 = "uvw"; // first v_stamp
266+
std::string expected3 = "xyzA"; // second v_stamp
267+
std::string expected4 = "B%"; // first f_stamp
268+
std::string expected5 = "(CD, EF, GH, IJ, KL, MN, OP, QR, ST, UV, WX)"; //second u_stamp
269+
std::string expected6 = "Z!"; //second f_stamp
270+
271+
Blob blob(sample, strlen(sample));
272+
273+
274+
StampTwoChars f_stamp;
275+
StampSeveralChars v_stamp;
276+
StampTwoCharsList u_stamp;
277+
278+
std::vector<std::reference_wrapper<StampBase>> stamps;
279+
stamps.push_back(u_stamp);
280+
stamps.push_back(v_stamp);
281+
stamps.push_back(v_stamp);
282+
stamps.push_back(f_stamp);
283+
stamps.push_back(u_stamp);
284+
stamps.push_back(f_stamp);
285+
286+
GalleyVector galley(stamps);
287+
288+
std::vector<std::string> res = galley.ExtractStr(blob);
289+
std::string str;
290+
291+
str = res[0];
292+
is(str, expected1, "GalleyVector, mixed type stamps: First unbounded stamp is ok");
293+
294+
str = res[1];
295+
is(str, expected2, "GalleyVector, mixed type stamps: Fist varieded stamp is ok");
296+
297+
str = res[2];
298+
is(str, expected3, "GalleyVector, mixed type stamps: Second variated stamp is ok");
299+
300+
str = res[3];
301+
is(str, expected4, "GalleyVector, mixed type stamps: First fixed stamp is ok");
302+
303+
str = res[4];
304+
is(str, expected5, "GalleyVector, mixed type stamps: Second unbounded stamp is ok");
305+
306+
str = res[5];
307+
is(str, expected6, "GalleyVector, mixed type stamps: Second fixed stamp is ok");
308+
309+
is(res.size(), 6, "GalleyVector, mixed type stamps: The vector has only six elements ");
310+
311+
is(blob.Size(), 0 , "GalleyVector: will use all data if we have at least one unbounded stamp");
312+
313+
is(galley.minSize(), (f_stamp.minSize()+v_stamp.minSize()+u_stamp.minSize())*2 + ORACLE_SIZE * (2+2+1), "GalleyVector, mixed types stamps: galley min size is ok");
314+
is(galley.maxSize(), -1, "GalleyVector, mixed types stamps: galley max size is ok");
315+
}
156316

157317
TEST_END;
158318
}

0 commit comments

Comments
 (0)
0