Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitfc77793

Browse files
Add tests for galley
1 parentdef0e05 commitfc77793

File tree

4 files changed

+95
-74
lines changed

4 files changed

+95
-74
lines changed

‎t/100-stamp-base.cpp‎

Lines changed: 1 addition & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -11,51 +11,13 @@
1111
#include"blobstamper/blobstamper.h"
1212
#include"blobstamper/helpers.h"
1313

14+
#include"two-chars-stamp.h"
1415

1516
usingnamespaceTAP;
1617

1718

1819
/* Tests for very basic stamp operations*/
1920

20-
21-
/* This stamps chops first two bytes and treat them as string*/
22-
/* Never do this in real live, as blob is binary and may have \0 in the middle of it*/
23-
classStampTwoChars:publicStampGeneric
24-
{
25-
public:
26-
StampTwoChars();
27-
std::stringExtractStr(Blob &blob)override;
28-
};
29-
30-
StampTwoChars::StampTwoChars() : StampGeneric()
31-
{
32-
min_size =2;/* This stamp shifts two characters only*/
33-
max_size =2;
34-
is_fixed_size =true;
35-
}
36-
37-
std::string
38-
StampTwoChars::ExtractStr(Blob &blob)
39-
{
40-
char * buf;
41-
size_t buf_size;
42-
43-
Blob blob2 = blob.ShiftBytes(min_size);
44-
if (blob2.isEmpty())
45-
return"";
46-
47-
/* Save shited data as string*/
48-
/* NEVER do this in prod, as in real live blob is binary and may have 0 in the middle of it*/
49-
blob2.DataDup(buf, buf_size);
50-
buf = (char *)realloc((void *)buf, buf_size +1);
51-
buf[buf_size] ='\0';
52-
std::string res = buf;
53-
free(buf);
54-
55-
return res;
56-
}
57-
58-
5921
char my_data[]="1234567890ABCDEFGHIGKLMNOPQRSTUVWXYZabcdefghigklmnopqrstuvwxyzАБВГДитд.___";
6022

6123
char short_sample[]="1234567";
@@ -85,37 +47,6 @@ main()
8547
free(ptr);
8648
}
8749

88-
/* This should be moved to Galley test later*/
89-
#if0
90-
/* Test that StamList really splits the whole blob to the specified stamps */
91-
{ /* 4..7 */
92-
std::string expected1 = "12";
93-
std::string expected2 = "34";
94-
std::string expected3 = "56";
95-
96-
StampTwoChars stamp;
97-
StampList stamp_list(stamp);
98-
Blob blob(short_sample, strlen(short_sample));
99-
std::list<std::string> res = stamp_list.ExtractStrList(blob);
100-
101-
std::string str;
102-
103-
str = res.front();
104-
ok(str == expected1, "ExtractStrList: First element of shifted list is ok");
105-
res.pop_front();
106-
107-
str = res.front();
108-
ok(str == expected2, "ExtractStrList: Second element of shifted list is ok");
109-
res.pop_front();
110-
111-
str = res.front();
112-
ok(str == expected3, "ExtractStrList: Third element of shifted list is ok");
113-
res.pop_front();
114-
115-
ok(res.empty(), "ExtractStrList: The rest of the list is empty");
116-
}
117-
#endif
118-
11950
/* Chekc that data is shifted till blob data is empty*/
12051
{/* 8*/
12152
char sample_two_bytes[]="12";
@@ -124,7 +55,6 @@ main()
12455
StampTwoChars stamp;
12556
std::string str = blob.ShiftSingleStampStr(stamp);
12657
ok(str == expected1,"ShiftSingleStampStr: shifts last two bytes ok");
127-
12858
}
12959

13060
TEST_END;

‎t/300-galley.cpp‎

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#include<string.h>
2+
3+
#include<exception>
4+
#include<string>
5+
#include<cstdlib>
6+
#defineWANT_TEST_EXTRAS
7+
#include<tap++/tap++.h>
8+
9+
10+
#include"blobstamper/blobstamper.h"
11+
12+
#include"two-chars-stamp.h"
13+
14+
usingnamespaceTAP;
15+
16+
/* Test that dict works as expected*/
17+
18+
char short_sample[]="1234567";
19+
20+
int
21+
main()
22+
{
23+
TEST_START(4);
24+
{/* 1..4*/
25+
std::string expected1 ="12";
26+
std::string expected2 ="34";
27+
std::string expected3 ="56";
28+
29+
StampTwoChars stamp;
30+
GalleySeriesgalley(stamp);
31+
Blobblob(short_sample,strlen(short_sample));
32+
std::list<std::string> res = galley.Extract(blob);
33+
34+
std::string str;
35+
36+
str = res.front();
37+
ok(str == expected1,"GalleySeries: First element of shifted list is ok");
38+
res.pop_front();
39+
40+
str = res.front();
41+
ok(str == expected2,"GalleySeries: Second element of shifted list is ok");
42+
res.pop_front();
43+
44+
str = res.front();
45+
ok(str == expected3,"GalleySeries: Third element of shifted list is ok");
46+
res.pop_front();
47+
48+
ok(res.empty(),"GalleySeries: The rest of the list is empty");
49+
}
50+
51+
TEST_END;
52+
}

‎t/Makefile‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ DEBUG := -ggdb3 -DDEBUG
66
CXXFLAGS :=$(DEBUG)$(WARNINGS) -fPIC
77
PREFIX := /usr/local
88
LIBRARY_VAR := LD_LIBRARY_PATH
9-
TEST_GOALS := ./00-sanity.t ./001-blob-generic.t ./100-stamp-base.t ./110-stamp-atomic.t ./200-dict.t ./500-stamp-pg-type-geo.t ./700-wrapper-pg-type-geo.t
9+
TEST_GOALS := ./00-sanity.t ./001-blob-generic.t ./100-stamp-base.t ./110-stamp-atomic.t ./200-dict.t ./300-galley.t ./500-stamp-pg-type-geo.t ./700-wrapper-pg-type-geo.t
1010

11-
all:$(TEST_GOALS)
11+
all:build-libtappp$(TEST_GOALS)
1212

1313

1414
# FIXME this list dublicates same list in ../Makefile
@@ -25,7 +25,7 @@ BLOB_STAMPER_OBJ = ../blobstamper/blob.o \
2525
build-libtappp:
2626
$(MAKE) -C ../libtappp
2727

28-
%.t:%.cpp build-libtappp
28+
%.t:%.cpp
2929
$(CXX)$(CXXFLAGS) -I../libtappp/include -I.. -o$@$<$(BLOB_STAMPER_OBJ) -L../libtappp -ltap++
3030

3131
test: all

‎t/two-chars-stamp.h‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
2+
/* This stamps chops first two bytes and treat them as string*/
3+
/* Never do this in real live, as blob is binary and may have \0 in the middle of it*/
4+
5+
classStampTwoChars:publicStampGeneric
6+
{
7+
public:
8+
StampTwoChars();
9+
std::stringExtractStr(Blob &blob)override;
10+
};
11+
12+
StampTwoChars::StampTwoChars() : StampGeneric()
13+
{
14+
min_size =2;/* This stamp shifts two characters only*/
15+
max_size =2;
16+
is_fixed_size =true;
17+
}
18+
19+
std::string
20+
StampTwoChars::ExtractStr(Blob &blob)
21+
{
22+
char * buf;
23+
size_t buf_size;
24+
25+
Blob blob2 = blob.ShiftBytes(min_size);
26+
if (blob2.isEmpty())
27+
return"";
28+
29+
/* Save shited data as string*/
30+
/* NEVER do this in prod, as in real live blob is binary and may have 0 in the middle of it*/
31+
blob2.DataDup(buf, buf_size);
32+
buf = (char *)realloc((void *)buf, buf_size +1);
33+
buf[buf_size] ='\0';
34+
std::string res = buf;
35+
free(buf);
36+
37+
return res;
38+
}
39+

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp