8000 Fix behaviur when GalleyVector does not have enough data. Add tests f… · postgrespro/libblobstamper@b90c618 · GitHub
[go: up one dir, main page]

Skip to content

Commit b90c618

Browse files
Fix behaviur when GalleyVector does not have enough data. Add tests for cases when there is not enought data, and when it is almost not enoght data
1 parent c43fc47 commit b90c618

File tree

2 files changed

+99
-9
lines changed

2 files changed

+99
-9
lines changed

blobstamper/galley.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ GalleySeries::ExtractBin(Blob &blob)
5757
return res;
5858
}
5959

60-
6160
std::list<Blob>
6261
GalleySeries::extract_internal(Blob &blob)
6362
{
@@ -155,6 +154,8 @@ GalleySeries::extract_internal(Blob &blob)
155154
return res;
156155
}
157156

157+
/**********************************************/
158+
158159
std::vector<Blob>
159160
GalleyVector::extract_internal(Blob &blob)
160161
{
@@ -199,6 +200,11 @@ GalleyVector::extract_internal(Blob &blob)
199200
This is a variable that will set limits to gariated stamps greed (will be rediced later */
200201
int varited_total_size_limit = max_varited_total_size;
201202

203+
if(fixed_total_size > blob.Size()) /* Not enought data case*/
204+
{
205+
return res;
206+
}
207+
202208
int avaliable_nonfixed_size = blob.Size() - fixed_total_size; /* The ammount of data available for non-fixed part of variated or unbounded stamps*/
203209
if (varited_total_size_limit > avaliable_nonfixed_size)
204210
varited_total_size_limit = avaliable_nonfixed_size; /* Can't use more than we have */
@@ -311,12 +317,12 @@ GalleyVector::ExtractStr(Blob &blob)
311317
{
312318
std::vector<std::string> res;
313319
std::vector<Blob> blobs = extract_internal(blob);
314-
for(int i=0; i<stamps.size(); i++)
320+
for(int i=0; i<blobs.size(); i++)
315321
{
316322
Blob blob = blobs[i];
317323
StampBase & stamp = stamps[i];
318-
std::string str= blob.ShiftSingleStampStr(stamp);
319-
res.push_back(str);
324+
std::string str= blob.ShiftSingleStampStr(stamp);
325+
res.push_back(str);
320326
}
321327
return res;
322328
}
@@ -378,5 +384,3 @@ GalleyVector::maxSize()
378384
}
379385
return res;
380386
}
381-
382-

t/300-galley.cpp

Lines changed: 89 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ char longer_sample[]="z1234567*89abcde&fghijklmnopqrstuvwxyzAB%CDEFGHIJKLMNOPQRS
1717

1818
int
1919
main()
20-
{
21-
TEST_START(53);
20+
{
21+
TEST_START(63);
2222
/* Test Galley Sereies with fixed size stampp*/
2323
{ /* 1..4 */
2424
std::string expected1 = "12";
@@ -172,7 +172,6 @@ main()
172172

173173
std::vector<std::string> res = galley.ExtractStr(blob);
174174
std::string str;
175-
176175
str = res[0];
177176
is(str, expected1, "GalleyVector, fixed size string stamps: First element of vector is ok");
178177

@@ -356,5 +355,92 @@ main()
356355
is(galley.maxSize(), -1, "GalleyVector, mixed types stamps 2: galley max size is ok");
357356
}
358357

358+
/* Test Galley Vector, when there are only minimal amound of data available */
359+
{ /* 54 .. 63*/
360+
361+
char sample[] = "oo" "oo" "oo" "oo" "oo" "z1" "23" "45" "67" "89" "ab";
362+
363+
std::string expected1 = "(z1)"; // first u_stamp
364+
std::string expected2 = "23"; // first v_stamp
365+
std::string expected3 = "45"; // second v_stamp
366+
std::string expected4 = "67"; // first f_stamp
367+
std::string expected5 = "(89)"; //second u_stamp
368+
std::string expected6 = "ab"; //second f_stamp
369+
370+
Blob blob(sample, strlen(sample));
371+
372+
StampTwoChars f_stamp;
373+
StampSeveralChars v_stamp;
374+
StampTwoCharsList u_stamp;
375+
376+
std::vector<std::reference_wrapper<StampBase>> stamps;
377+
stamps.push_back(u_stamp);
378+
stamps.push_back(v_stamp);
379+
stamps.push_back(v_stamp);
380+
stamps.push_back(f_stamp);
381+
stamps.push_back(u_stamp);
382+
stamps.push_back(f_stamp);
383+
384+
GalleyVector galley(stamps);
385+
386+
std::vector<std::string> res = galley.ExtractStr(blob);
387+
std::string str;
388+
389+
str = res[0];
390+
is(str, expected1, "GalleyVector, mixed type stamps 3: First unbounded stamp is ok");
391+
392+
str = res[1];
393+
is(str, expected2, "GalleyVector, mixed type stamps 3: Fist varieded stamp is ok");
394+
395+
str = res[2];
396+
is(str, expected3, "GalleyVector, mixed type stamps 3: Second variated stamp is ok");
397+
398+
str = res[3];
399+
is(str, expected4, "GalleyVector, mixed type stamps 3: First fixed stamp is ok");
400+
401+
str = res[4];
402+
is(str, expected5, "GalleyVector, mixed type stamps 3: Second unbounded stamp is ok");
403+
404+
str = res[5];
405+
is(str, expected6, "GalleyVector, mixed type stamps 3: Second fixed stamp is ok");
406+
407+
is(res.size(), 6, "GalleyVector, mixed type stamps 3: The vector has only six elements ");
408+
409+
is(blob.Size(), 0 , "GalleyVector 3: will use all data if we have at least one unbounded stamp");
410+
411+
is(galley.minSize(), (f_stamp.minSize()+v_stamp.minSize()+u_stamp.minSize())*2 + ORACLE_SIZE * (2+2+1), "GalleyVector, mixed types stamps 3: galley min size is ok");
412+
is(galley.maxSize(), -1, "GalleyVector, mixed types stamps 3: galley max size is ok");
413+
}
414+
415+
/* Test Galley Vector, when there are not enought data */
416+
{ /* 64 .. 67*/
417+
418+
char sample[] = "oo" "oo" "oo" "oo" "oo" "z1" "23" "45" "67" "89" "a";
419+
420+
Blob blob(sample, strlen(sample));
421+
422+
StampTwoChars f_stamp;
423+
StampSeveralChars v_stamp;
424+
StampTwoCharsList u_stamp;
425+
426+
std::vector<std::reference_wrapper<StampBase>> stamps;
427+
stamps.push_back(u_stamp);
428+
stamps.push_back(v_stamp);
429+
stamps.push_back(v_stamp);
430+
stamps.push_back(f_stamp);
431+
stamps.push_back(u_stamp);
432+
stamps.push_back(f_stamp);
433+
434+
GalleyVector galley(stamps);
435+
std::vector<std::string> res = galley.ExtractStr(blob);
436+
std::string str;
437+
438+
is(res.size(), 0, "GalleyVector, mixed type stamps 4: Fails when not enught data");
439+
440+
is(blob.Size(), strlen(sample) , "GalleyVector 4: will use keep all data when applying galley fails");
441+
442+
is(galley.minSize(), (f_stamp.minSize()+v_stamp.minSize()+u_stamp.minSize())*2 + ORACLE_SIZE * (2+2+1), "GalleyVector, mixed types stamps 4: galley min size is ok");
443+
is(galley.maxSize(), -1, "GalleyVector, mixed types stamps 4: galley max size is ok");
444+
}
359445
TEST_END;
360446
}

0 commit comments

Comments
 (0)
0