|
| 1 | +#include<string.h> |
| 2 | + |
| 3 | +#include<exception> |
| 4 | +#include<string> |
| 5 | +#include<cstdlib> |
| 6 | + |
| 7 | +#defineWANT_TEST_EXTRAS |
| 8 | +#include<tap++/tap++.h> |
| 9 | + |
| 10 | +#include"blobstamper/blobstamper.h" |
| 11 | +#include"blobstamper/helpers.h" |
| 12 | + |
| 13 | + |
| 14 | +usingnamespaceTAP; |
| 15 | + |
| 16 | + |
| 17 | +/* Tests for atomic type stamps*/ |
| 18 | + |
| 19 | +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}; |
| 24 | + |
| 25 | +int |
| 26 | +main() |
| 27 | +{ |
| 28 | +size_t sample_data_int16_size =sizeof(sample_data_int16); |
| 29 | +size_t sample_data_int32_size =sizeof(sample_data_int32); |
| 30 | +size_t sample_data_int64_size =sizeof(sample_data_int64); |
| 31 | +size_t sample_data_double_size =sizeof(double) *7; |
| 32 | + |
| 33 | +TEST_START(21); |
| 34 | + |
| 35 | +/* Check that Bin and Str Char stamps works well*/ |
| 36 | + {/* 1, 2, 3*/ |
| 37 | + Blobblob(sample_data_char,strlen(sample_data_char)); |
| 38 | + StampArithm<char> stamp; |
| 39 | + std::vector<char> v = blob.ShiftSingleStampBin(stamp); |
| 40 | +char * pc = (char *) &v[0]; |
| 41 | +is(*pc,'S' ,"Bin Char stamp works well"); |
| 42 | + |
| 43 | + std::string s = blob.ShiftSingleStampStr(stamp); |
| 44 | +is(s,"111" ,"Str UInt8 stamp works well");// 'o'==111 |
| 45 | + |
| 46 | +char c = stamp.ExtractValue(blob); |
| 47 | +is(c,'m' ,"extract char as value works well"); |
| 48 | + } |
| 49 | + |
| 50 | +/* Check that Bin and Srt Int16 stamps works well*/ |
| 51 | + {/* 4, 5, 6, 7, 8*/ |
| 52 | + Blobblob((char *)sample_data_int16, sample_data_int16_size); |
| 53 | + StampArithm<shortint> stamp; |
| 54 | + std::vector<char> v = blob.ShiftSingleStampBin(stamp); |
| 55 | +shortint * pi = (shortint *) &v[0]; |
| 56 | +is(*pi,1 ,"Bin Int16 stamp works well"); |
| 57 | + |
| 58 | + StampArithm<unsignedshortint> stamp_unsigned; |
| 59 | + std::string s = blob.ShiftSingleStampStr(stamp_unsigned); |
| 60 | +is(s,"65534" ,"Str UInt16 stamp works well");// (unsigned short int)-2 == 65534 |
| 61 | + |
| 62 | + StampArithm<signedshortint> stamp_signed; |
| 63 | + s = blob.ShiftSingleStampStr(stamp_signed); |
| 64 | +is(s,"-3" ,"Str SInt16 stamp works well"); |
| 65 | + |
| 66 | +unsignedshortint ui = stamp_unsigned.ExtractValue(blob); |
| 67 | +is(ui,4,"Extract unsigned int16 as value"); |
| 68 | + |
| 69 | +signedshortint si = stamp_signed.ExtractValue(blob); |
| 70 | +is(si,555,"Extract signed int16 as value"); |
| 71 | + } |
| 72 | + |
| 73 | +/* Check that Bin and Srt Int32 stamps works well*/ |
| 74 | + {/* 9, 10, 11, 12, 13*/ |
| 75 | + Blobblob((char *)sample_data_int32, sample_data_int32_size); |
| 76 | + StampArithm<int> stamp; |
| 77 | + |
| 78 | + std::vector<char> v = blob.ShiftSingleStampBin(stamp); |
| 79 | + |
| 80 | +int * i = (int *) &v[0]; |
| 81 | +is(*i,10 ,"Bin Int32 stamp works well"); |
| 82 | + |
| 83 | + StampArithm<unsignedint> stamp_unsigned; |
| 84 | + std::string s = blob.ShiftSingleStampStr(stamp_unsigned); |
| 85 | +is(s,"4294967276" ,"Str UInt32 stamp works well");// (unsigned short int)-20 == 4294967276 |
| 86 | + |
| 87 | + StampArithm<signedint> stamp_signed; |
| 88 | + s = blob.ShiftSingleStampStr(stamp_signed); |
| 89 | +is(s,"-30" ,"Str SInt32 stamp works well"); |
| 90 | + |
| 91 | +unsignedint ui = stamp_unsigned.ExtractValue(blob); |
| 92 | +is(ui,40,"Extract unsigned int32 as value"); |
| 93 | + |
| 94 | +signedint si = stamp_signed.ExtractValue(blob); |
| 95 | +is(si,500,"Extract signed int32 as value"); |
| 96 | + |
| 97 | + } |
| 98 | + |
| 99 | + |
| 100 | +/* Check that Bin and Srt Int64 stamps works well*/ |
| 101 | + {/* 14, 15, 16, 17, 18*/ |
| 102 | + Blobblob((char *)sample_data_int64, sample_data_int64_size); |
| 103 | + StampArithm<longlong> stamp; |
| 104 | + |
| 105 | + std::vector<char> v = blob.ShiftSingleStampBin(stamp); |
| 106 | + |
| 107 | +longlong * i = (longlong *) &v[0]; |
| 108 | +is(*i,100 ,"Bin Int64 stamp works well"); |
| 109 | + |
| 110 | + StampArithm<unsignedlonglong> stamp_unsigned; |
| 111 | + std::string s = blob.ShiftSingleStampStr(stamp_unsigned); |
| 112 | +is(s,"18446744073709551416" ,"Str UInt64 stamp works well");// (unsigned short int)-200 == 18446744073709551416 |
| 113 | + |
| 114 | + StampArithm<signedlonglong> stamp_signed; |
| 115 | + s = blob.ShiftSingleStampStr(stamp_signed); |
| 116 | +is(s,"-300" ,"Str SInt64 stamp works well"); |
| 117 | + |
| 118 | +unsignedlonglong ui = stamp_unsigned.ExtractValue(blob); |
| 119 | +is(ui,400,"Extract unsigned int32 as value"); |
| 120 | + |
| 121 | +signedlonglong si = stamp_signed.ExtractValue(blob); |
| 122 | +is(si,5,"Extract signed int32 as value"); |
| 123 | + } |
| 124 | + |
| 125 | +/* Test Double stamp*/ |
| 126 | + {/* 19, 20, 21*/ |
| 127 | + Blobblob((char *)sample_data_double, sample_data_double_size); |
| 128 | + StampArithm<double> stamp; |
| 129 | + std::vector<char> v = blob.ShiftSingleStampBin(stamp); |
| 130 | +double *pd = (double *) &v[0]; |
| 131 | +is(*pd,1.4142,"Bin Double stamp works well"); |
| 132 | + |
| 133 | + std::string res = blob.ShiftSingleStampStr(stamp); |
| 134 | +is(res,"2","Str Double stamp works well"); |
| 135 | + |
| 136 | +double d = stamp.ExtractValue(blob); |
| 137 | +is(d,3.1415,"Extract double as value"); |
| 138 | + } |
| 139 | + TEST_END; |
| 140 | +} |