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

Commit5323b4e

Browse files
Tests for ExreactPValue for arithmetic types
1 parent3774639 commit5323b4e

File tree

2 files changed

+64
-14
lines changed

2 files changed

+64
-14
lines changed

‎blobstamper/stamp.h

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#include<list>
77
#include<vector>
88

9+
#include"helpers.h"
10+
911

1012
classStampBase
1113
{
@@ -22,18 +24,33 @@ class StampBase
2224
};
2325

2426

25-
template<classT>classStampBaseV:publicvirtual StampBase
27+
template<classT>classStampBasePV:publicvirtual StampBase
2628
{
2729
public:
28-
virtualTExtractValue(Blob &blob) = 0;/* Shoud be defined by derived classes*/
30+
virtualsized_ptr<T>ExtractPValue(Blob &blob) = 0;/* Shoud be defined by derived classes*/
2931
};
3032

31-
template<classT>classStampBasePV:publicvirtual StampBase
33+
34+
template<classT>classStampBaseV:publicStampBasePV<T>
3235
{
3336
public:
34-
virtual T*ExtractValue(Blob &blob) = 0;/* Shoud be defined by derived classes*/
37+
virtual TExtractValue(Blob &blob) = 0;/* Shoud be defined by derived classes*/
38+
virtual sized_ptr<T>ExtractPValue(Blob &blob)override;
3539
};
3640

41+
template<classT> sized_ptr<T>
42+
StampBaseV<T>::ExtractPValue(Blob &blob)
43+
{
44+
T* p = (T*)malloc(sizeof(T));
45+
*p =ExtractValue(blob);
46+
sized_ptr<T>res(p,sizeof(T));
47+
return res;
48+
}
49+
50+
51+
52+
53+
3754

3855
classStampFixed :publicvirtual StampBase
3956
{

‎t/110-stamp-arithm.cpp

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ using namespace TAP;
1717
/* Tests for atomic type stamps*/
1818

1919
char sample_data_char[] ="Some string";
20-
shortint sample_data_int16[] = {1, -2, -3,4,555,66};
21-
int sample_data_int32[] = {10, -20, -30,40,500,6};
22-
longlong sample_data_int64[] = {100, -200, -300,400,5,6};
23-
double sample_data_double[] ={1.4142,2,3.1415,4.2e01,5,6,7};
20+
shortint sample_data_int16[] ={1, -2,-3,4,555,66,777,8};
21+
int sample_data_int32[] ={10, -20,-30,40,500,6,77,888};
22+
longlong sample_data_int64[] ={100, -200,-300,400,5,6,7000,808};
23+
double sample_data_double[] = {1.4142,2,3.1415,4.2e01,5,6,7};
2424

2525
int
2626
main()
@@ -30,10 +30,10 @@ main()
3030
size_t sample_data_int64_size =sizeof(sample_data_int64);
3131
size_t sample_data_double_size =sizeof(double) *7;
3232

33-
TEST_START(21);
33+
TEST_START(29);
3434

3535
/* Check that Bin and Str Char stamps works well*/
36-
{/* 1, 2, 3*/
36+
{/* 1..4*/
3737
Blobblob(sample_data_char,strlen(sample_data_char));
3838
StampArithm<char> stamp;
3939
std::vector<char> v = blob.ShiftSingleStampBin(stamp);
@@ -45,10 +45,14 @@ main()
4545

4646
char c = stamp.ExtractValue(blob);
4747
is(c,'m' ,"extract char as value works well");
48+
49+
sized_ptr<char> sp =stamp.ExtractPValue(blob);
50+
char * p = sp;
51+
is(*p,'e',"Extract poiner to value works well");
4852
}
4953

5054
/* Check that Bin and Srt Int16 stamps works well*/
51-
{/*4, 5, 6, 7, 8*/
55+
{/*5..11*/
5256
Blobblob((char *)sample_data_int16, sample_data_int16_size);
5357
StampArithm<shortint> stamp;
5458
std::vector<char> v = blob.ShiftSingleStampBin(stamp);
@@ -68,10 +72,18 @@ main()
6872

6973
signedshortint si = stamp_signed.ExtractValue(blob);
7074
is(si,555,"Extract signed int16 as value");
75+
76+
sized_ptr<unsignedshortint> usp =stamp_unsigned.ExtractPValue(blob);
77+
unsignedshortint * up = usp;
78+
is(*up,66,"Extract poiner to value for unsigned int16 works well");
79+
80+
sized_ptr<signedshortint> ssp =stamp_signed.ExtractPValue(blob);
81+
signedshortint * sp = ssp;
82+
is(*sp,777,"Extract poiner to value for signed int16 works well");
7183
}
7284

7385
/* Check that Bin and Srt Int32 stamps works well*/
74-
{/*9, 10, 11, 12, 13*/
86+
{/* 12..18*/
7587
Blobblob((char *)sample_data_int32, sample_data_int32_size);
7688
StampArithm<int> stamp;
7789

@@ -94,11 +106,18 @@ main()
94106
signedint si = stamp_signed.ExtractValue(blob);
95107
is(si,500,"Extract signed int32 as value");
96108

109+
sized_ptr<unsignedint> usp =stamp_unsigned.ExtractPValue(blob);
110+
unsignedint * up = usp;
111+
is(*up,6,"Extract poiner to value for unsigned int32 works well");
112+
113+
sized_ptr<signedint> ssp =stamp_signed.ExtractPValue(blob);
114+
signedint * sp = ssp;
115+
is(*sp,77,"Extract poiner to value for signed int32 works well");
97116
}
98117

99118

100119
/* Check that Bin and Srt Int64 stamps works well*/
101-
{/*14, 15, 16, 17, 18*/
120+
{/*19..25*/
102121
Blobblob((char *)sample_data_int64, sample_data_int64_size);
103122
StampArithm<longlong> stamp;
104123

@@ -120,10 +139,19 @@ main()
120139

121140
signedlonglong si = stamp_signed.ExtractValue(blob);
122141
is(si,5,"Extract signed int32 as value");
142+
143+
sized_ptr<unsignedlonglong> usp =stamp_unsigned.ExtractPValue(blob);
144+
unsignedlonglong * up = usp;
145+
is(*up,6,"Extract poiner to value for unsigned int64 works well");
146+
147+
sized_ptr<signedlonglong> ssp =stamp_signed.ExtractPValue(blob);
148+
signedlonglong * sp = ssp;
149+
is(*sp,7000,"Extract poiner to value for signed int64 works well");
150+
123151
}
124152

125153
/* Test Double stamp*/
126-
{/*19, 20, 21*/
154+
{/*26..29*/
127155
Blobblob((char *)sample_data_double, sample_data_double_size);
128156
StampArithm<double> stamp;
129157
std::vector<char> v = blob.ShiftSingleStampBin(stamp);
@@ -135,6 +163,11 @@ main()
135163

136164
double d = stamp.ExtractValue(blob);
137165
is(d,3.1415,"Extract double as value");
166+
167+
sized_ptr<double> sp =stamp.ExtractPValue(blob);
168+
double * p = sp;
169+
is(*p,42,"Extract poiner to value for double works well");
170+
138171
}
139172
TEST_END;
140173
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp