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

Commit7e87462

Browse files
author
Nikolay Shaplov
committed
move tests of blob shift method to t/*.t tests
1 parentc8e8e03 commit7e87462

File tree

6 files changed

+90
-32
lines changed

6 files changed

+90
-32
lines changed

‎Makefile‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@ all: blob-stamper-all test test_pg_op_wrappers test_libblobstamper
2222
blob-stamper-all:
2323
$(MAKE) -C blobstamper
2424

25-
test:$(LIB_OBJS) test.o
26-
$(CC)$(LDFLAGS)$^ -o$@$(LDLIBS)
27-
2825
test_pg_op_wrappers: blob-stamper-all$(LIB_OBJS) test_pg_op_wrappers.o pg_op_wrappers.o
2926
$(CXX)$(LDFLAGS)$@.o -o$@$(LDLIBS)$(BLOB_STAMPER_OBJ) pg_op_wrappers.o
3027

‎blobstamper/blob.cpp‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1+
2+
3+
#include<cstring>
4+
15
#include"blob.h"
26
#include"helpers.h"
37

8+
49
#include"stamp.h"
510

611
Blob::Blob (char * data_in,int size_in)
@@ -56,3 +61,11 @@ Blob::ShiftSingleStampStr(StampGeneric& stmp)
5661
return stmp.ExtractStr(*this);
5762
}
5863

64+
void
65+
Blob::DataDup(char *& data_out,size_t& size_out)
66+
{
67+
size_out = end - begin +1;
68+
data_out = (char *)malloc(size);
69+
memcpy(data_out, data + begin, size_out);
70+
}
71+

‎blobstamper/blob.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class Blob
1414
boolisEmpty ();
1515
voidDump();
1616
BlobShiftBytes(size_t n);
17+
voidDataDup(char *& data_out,size_t& size_out);
1718

1819
void *ShiftSingleStampBin(StampGeneric &stmp);
1920
std::stringShiftSingleStampStr(StampGeneric &stmp);

‎t/001-blob-generic.cpp‎

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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+
#include"blobstamper/blobstamper.h"
10+
#include"blobstamper/helpers.h"
11+
12+
13+
usingnamespaceTAP;
14+
15+
char my_data[]="1234567890ABCDEFGHIGKLMNOPQRSTUVWXYZabcdefghigklmnopqrstuvwxyzАБВГДитд.___";
16+
17+
char short_sample[]="123456";
18+
19+
int
20+
main()
21+
{
22+
char *ptr;
23+
size_t size;
24+
25+
TEST_START(7);
26+
27+
{/* 1..2*/
28+
/* Check that DataDup gives us the same data we've just added to blob*/
29+
Blobblob(my_data,strlen(my_data));
30+
blob.DataDup(ptr,size);
31+
ok(!memcmp(my_data, ptr, size),"Blob gets and returns blob data ok");
32+
ok(size ==strlen(my_data),"Blob gets and returns blob data with expected size");
33+
free(ptr);
34+
}
35+
{/* 3..6*/
36+
/* Check that Shift bytes behave as expected*/
37+
char expected1[]="456";
38+
char expected2[]="123";
39+
40+
Blobblob1(short_sample,strlen(short_sample));
41+
Blob blob2 = blob1.ShiftBytes(3);
42+
43+
blob1.DataDup(ptr,size);
44+
ok(size ==strlen(expected1),"Blob shifted data size ok");
45+
ok(!memcmp(expected1, ptr, size),"Blob shifted data ok");
46+
free(ptr);
47+
48+
blob2.DataDup(ptr,size);
49+
ok(size ==strlen(expected2),"Blob remained data size ok");
50+
ok(!memcmp(expected2, ptr, size),"Blob remained data ok");
51+
free(ptr);
52+
}
53+
{/* 7*/
54+
/* Check that shifting too many bytes return empty result*/
55+
Blobblob(my_data,strlen(my_data));
56+
Blob blob_res = blob.ShiftBytes(99999);
57+
ok(blob_res.isEmpty(),"Shifting too many bytes gives empty result");
58+
}
59+
60+
61+
62+
TEST_END;
63+
}

‎t/Makefile‎

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,25 @@ DEBUG := -ggdb3 -DDEBUG
66
CXXFLAGS :=$(DEBUG)$(WARNINGS) -fPIC
77
PREFIX := /usr/local
88
LIBRARY_VAR := LD_LIBRARY_PATH
9-
TEST_GOALS := ./00-sanity.t
9+
TEST_GOALS := ./00-sanity.t ./001-blob-generic.t
1010

1111
all:$(TEST_GOALS)
1212

13+
14+
# FIXME this list dublicates same list in ../Makefile
15+
# should remove it for deduplication
16+
BLOB_STAMPER_OBJ = ../blobstamper/blob.o\
17+
../blobstamper/helpers.o\
18+
../blobstamper/stamp.o\
19+
../blobstamper/stamp_atomic.o\
20+
../blobstamper/stamp_pg_type_geo.o\
21+
22+
1323
build-libtappp:
1424
$(MAKE) -C ../libtappp
1525

16-
$(LIB): src/tap++.cpp include/tap++/tap++.h
17-
$(CXX) -shared -o$@ -Wl,-soname,$(LIB)$(CXXFLAGS) -Iinclude/ src/*.cpp
18-
1926
%.t:%.cpp build-libtappp
20-
$(CXX)$(CXXFLAGS) -I../libtappp/include -o$@$< -L../libtappp -ltap++
27+
$(CXX)$(CXXFLAGS) -I../libtappp/include -I.. -o$@$<$(BLOB_STAMPER_OBJ) -L../libtappp -ltap++
2128

2229
test: all
2330
@echo run_tests.pl$(TEST_GOALS)
@@ -26,5 +33,5 @@ test: all
2633
clean:
2734
-rm*.t2>/dev/null
2835

29-
.PHONY: test clean all build-libtappp
36+
.PHONY: test clean all build-libtappp build-libblobstamper
3037

‎test_libblobstamper.cpp‎

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,6 @@ main(void)
1111
{
1212
Blobbl(my_data,strlen(my_data));
1313

14-
printf("Original blob:\n");
15-
16-
bl.Dump();
17-
18-
printf("\n Now shifting 3 bytes.\n");
19-
Blob bl2 = bl.ShiftBytes(3);
20-
21-
printf("Bytes shifted:\n");
22-
bl2.Dump();
23-
24-
printf("\n Remaining blob:\n");
25-
bl.Dump();
26-
27-
printf("\n Now shifting too many bytes.\n");
28-
29-
Blob bl3 = bl.ShiftBytes(99999);
30-
31-
if (bl3.isEmpty())
32-
printf("Got empty result. All is right\n");
33-
else
34-
printf("got non-empty result. SOMETHING IS REALLY WRONG!!!!\n");
35-
36-
3714
StampBinDouble stmp_double;
3815

3916
void* res = bl.ShiftSingleStampBin(stmp_double);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp